summaryrefslogtreecommitdiff
path: root/venv/lib/python3.11/site-packages/litestar/routes/asgi.py
diff options
context:
space:
mode:
authorcyfraeviolae <cyfraeviolae>2024-04-03 03:10:44 -0400
committercyfraeviolae <cyfraeviolae>2024-04-03 03:10:44 -0400
commit6d7ba58f880be618ade07f8ea080fe8c4bf8a896 (patch)
treeb1c931051ffcebd2bd9d61d98d6233ffa289bbce /venv/lib/python3.11/site-packages/litestar/routes/asgi.py
parent4f884c9abc32990b4061a1bb6997b4b37e58ea0b (diff)
venv
Diffstat (limited to 'venv/lib/python3.11/site-packages/litestar/routes/asgi.py')
-rw-r--r--venv/lib/python3.11/site-packages/litestar/routes/asgi.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/venv/lib/python3.11/site-packages/litestar/routes/asgi.py b/venv/lib/python3.11/site-packages/litestar/routes/asgi.py
new file mode 100644
index 0000000..a8564d0
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/litestar/routes/asgi.py
@@ -0,0 +1,54 @@
+from __future__ import annotations
+
+from typing import TYPE_CHECKING, Any
+
+from litestar.connection import ASGIConnection
+from litestar.enums import ScopeType
+from litestar.routes.base import BaseRoute
+
+if TYPE_CHECKING:
+ from litestar.handlers.asgi_handlers import ASGIRouteHandler
+ from litestar.types import Receive, Scope, Send
+
+
+class ASGIRoute(BaseRoute):
+ """An ASGI route, handling a single ``ASGIRouteHandler``"""
+
+ __slots__ = ("route_handler",)
+
+ def __init__(
+ self,
+ *,
+ path: str,
+ route_handler: ASGIRouteHandler,
+ ) -> None:
+ """Initialize the route.
+
+ Args:
+ path: The path for the route.
+ route_handler: An instance of :class:`~.handlers.ASGIRouteHandler`.
+ """
+ self.route_handler = route_handler
+ super().__init__(
+ path=path,
+ scope_type=ScopeType.ASGI,
+ handler_names=[route_handler.handler_name],
+ )
+
+ async def handle(self, scope: Scope, receive: Receive, send: Send) -> None:
+ """ASGI app that authorizes the connection and then awaits the handler function.
+
+ Args:
+ scope: The ASGI connection scope.
+ receive: The ASGI receive function.
+ send: The ASGI send function.
+
+ Returns:
+ None
+ """
+
+ if self.route_handler.resolve_guards():
+ connection = ASGIConnection["ASGIRouteHandler", Any, Any, Any](scope=scope, receive=receive)
+ await self.route_handler.authorize_connection(connection=connection)
+
+ await self.route_handler.fn(scope=scope, receive=receive, send=send)