MCPcopy
hub / github.com/encode/starlette / websocket_session

Function websocket_session

starlette/routing.py:69–85  ·  view source on GitHub ↗

Takes a coroutine `func(session)`, and returns an ASGI application.

(
    func: Callable[[WebSocket], Awaitable[None]],
)

Source from the content-addressed store, hash-verified

67
68
69def websocket_session(
70 func: Callable[[WebSocket], Awaitable[None]],
71) -> ASGIApp:
72 """
73 Takes a coroutine `func(session)`, and returns an ASGI application.
74 """
75 # assert asyncio.iscoroutinefunction(func), "WebSocket endpoints must be async"
76
77 async def app(scope: Scope, receive: Receive, send: Send) -> None:
78 session = WebSocket(scope, receive=receive, send=send)
79
80 async def app(scope: Scope, receive: Receive, send: Send) -> None:
81 await func(session)
82
83 await wrap_app_handling_exceptions(app, session)(scope, receive, send)
84
85 return app
86
87
88def get_name(endpoint: Callable[..., Any]) -> str:

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected