|
| 1 | +from collections.abc import Awaitable |
| 2 | +from typing import Any, ClassVar, Protocol |
| 3 | + |
| 4 | +from asgiref.typing import ASGIReceiveCallable, ASGISendCallable, Scope, WebSocketScope |
| 5 | +from channels.auth import UserLazyObject |
| 6 | +from channels.db import database_sync_to_async |
| 7 | +from django.contrib.sessions.backends.base import SessionBase |
| 8 | +from django.utils.functional import LazyObject |
| 9 | + |
| 10 | +class _LazySession(SessionBase, LazyObject): # type: ignore[misc] |
| 11 | + _wrapped: SessionBase |
| 12 | + |
| 13 | +# Base ASGI Scope definition |
| 14 | +class _ChannelScope(WebSocketScope, total=False): |
| 15 | + # Channel specific |
| 16 | + channel: str |
| 17 | + url_route: dict[str, Any] |
| 18 | + path_remaining: str |
| 19 | + |
| 20 | + # Auth specific |
| 21 | + cookies: dict[str, str] |
| 22 | + session: _LazySession |
| 23 | + user: UserLazyObject | None |
| 24 | + |
| 25 | +def get_handler_name(message: dict[str, Any]) -> str: ... |
| 26 | + |
| 27 | +class _ASGIApplicationProtocol(Protocol): |
| 28 | + consumer_class: Any |
| 29 | + consumer_initkwargs: dict[str, Any] |
| 30 | + |
| 31 | + def __call__(self, scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable) -> Awaitable[None]: ... |
| 32 | + |
| 33 | +class AsyncConsumer: |
| 34 | + _sync: ClassVar[bool] = ... |
| 35 | + channel_layer_alias: ClassVar[str] = ... |
| 36 | + |
| 37 | + scope: _ChannelScope |
| 38 | + channel_layer: Any |
| 39 | + channel_name: str |
| 40 | + channel_receive: ASGIReceiveCallable |
| 41 | + base_send: ASGISendCallable |
| 42 | + |
| 43 | + async def __call__(self, scope: _ChannelScope, receive: ASGIReceiveCallable, send: ASGISendCallable) -> None: ... |
| 44 | + async def dispatch(self, message: dict[str, Any]) -> None: ... |
| 45 | + async def send(self, message: dict[str, Any]) -> None: ... |
| 46 | + @classmethod |
| 47 | + def as_asgi(cls, **initkwargs: Any) -> _ASGIApplicationProtocol: ... |
| 48 | + |
| 49 | +class SyncConsumer(AsyncConsumer): |
| 50 | + _sync: ClassVar[bool] = ... |
| 51 | + |
| 52 | + @database_sync_to_async |
| 53 | + def dispatch(self, message: dict[str, Any]) -> None: ... # type: ignore[override] |
| 54 | + def send(self, message: dict[str, Any]) -> None: ... # type: ignore[override] |
0 commit comments