Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /mardiros_fastlife /src /fastlife /config /websockets.py
| """ | |
| Configure views using a decorator. | |
| A simple usage: | |
| ```python | |
| from typing import Annotated | |
| from fastapi import Response | |
| from fastlife import Template, template, view_config | |
| @view_config("hello_world", "/", methods=["GET"]) | |
| async def hello_world( | |
| template: Annotated[Template, template("HelloWorld.jinja")], | |
| ) -> Response: | |
| return template() | |
| ``` | |
| """ | |
| from collections.abc import Callable | |
| from typing import Any | |
| from fastlife.adapters.tamahagane import RegistryHub, th_attach | |
| def websocket_view( | |
| name: str, | |
| path: str, | |
| ) -> Callable[..., Any]: | |
| """ | |
| A decorator function to register a websocket view in the | |
| {class}`Configurator <fastlife.config.configurator.GenericConfigurator>` | |
| while scaning a module using {func}`include | |
| <fastlife.config.configurator.GenericConfigurator.include>`. | |
| Note that the current implementation does not support permission check using | |
| the security policy. | |
| :param name: name of the route, used to build route from the helper | |
| {meth}`fastlife.request.request.Request.url_for` in order to create links. | |
| :param path: path of the route, use `{curly_brace}` to inject FastAPI Path | |
| parameters. | |
| :return: the configuration callback. | |
| """ | |
| view_name = name | |
| def configure( | |
| wrapped: Callable[..., Any], | |
| ) -> Callable[..., Any]: | |
| def callback(registry: RegistryHub) -> None: | |
| registry.fastlife.add_websocket_route( | |
| name=view_name, | |
| path=path, | |
| endpoint=wrapped, | |
| ) | |
| th_attach(wrapped, callback) | |
| return wrapped | |
| return configure | |
Xet Storage Details
- Size:
- 1.64 kB
- Xet hash:
- ab7dd4dd6586427e91366fbc4e75b1d59b1eb6ade5f1e8972c038ec368f9c21a
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.