|
| 1 | +import typing as t |
| 2 | + |
| 3 | +from engineio import AsyncServer |
| 4 | + |
| 5 | +from ellar.common_types import TReceive, TScope, TSend |
| 6 | +from ellar.core import App, IExecutionContext |
| 7 | +from ellar.core.context import IHTTPHostContext, IWebSocketHostContext |
| 8 | +from ellar.di import EllarInjector |
| 9 | + |
| 10 | +if t.TYPE_CHECKING: # pragma: no cover |
| 11 | + from .model import GatewayBase |
| 12 | + |
| 13 | + |
| 14 | +class GatewayContext(IExecutionContext): |
| 15 | + def __init__( |
| 16 | + self, |
| 17 | + server: AsyncServer, |
| 18 | + sid: str, |
| 19 | + message: t.Any, |
| 20 | + context: "IExecutionContext", |
| 21 | + environment: t.Dict, |
| 22 | + ) -> None: |
| 23 | + self.server = server |
| 24 | + self.sid = sid |
| 25 | + self.message = message |
| 26 | + self._context = context |
| 27 | + self.environment = environment |
| 28 | + |
| 29 | + def get_handler(self) -> t.Callable: |
| 30 | + return self._context.get_handler() |
| 31 | + |
| 32 | + def get_class(self) -> t.Optional[t.Type["GatewayBase"]]: # type: ignore[override] |
| 33 | + return t.cast(t.Type["GatewayBase"], self._context.get_class()) |
| 34 | + |
| 35 | + def get_service_provider(self) -> EllarInjector: # pragma: no cover |
| 36 | + return self._context.get_service_provider() |
| 37 | + |
| 38 | + def switch_to_http_connection(self) -> IHTTPHostContext: # pragma: no cover |
| 39 | + return self._context.switch_to_http_connection() |
| 40 | + |
| 41 | + def switch_to_websocket(self) -> IWebSocketHostContext: # pragma: no cover |
| 42 | + return self._context.switch_to_websocket() |
| 43 | + |
| 44 | + def get_app(self) -> App: # pragma: no cover |
| 45 | + return self._context.get_app() |
| 46 | + |
| 47 | + def get_type(self) -> str: # pragma: no cover |
| 48 | + return self._context.get_type() |
| 49 | + |
| 50 | + def get_args(self) -> t.Tuple[TScope, TReceive, TSend]: # pragma: no cover |
| 51 | + return self._context.get_args() |
0 commit comments