MCPcopy Create free account
hub / github.com/encode/starlette / __call__

Method __call__

starlette/routing.py:179–196  ·  view source on GitHub ↗

A route may be used in isolation as a stand-alone ASGI app. This is a somewhat contrived case, as they'll almost always be used within a Router, but could be useful for some tooling and minimal apps.

(self, scope: Scope, receive: Receive, send: Send)

Source from the content-addressed store, hash-verified

177 raise NotImplementedError() # pragma: no cover
178
179 async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
180 """
181 A route may be used in isolation as a stand-alone ASGI app.
182 This is a somewhat contrived case, as they'll almost always be used
183 within a Router, but could be useful for some tooling and minimal apps.
184 """
185 match, child_scope = self.matches(scope)
186 if match == Match.NONE:
187 if scope["type"] == "http":
188 response = PlainTextResponse("Not Found", status_code=404)
189 await response(scope, receive, send)
190 elif scope["type"] == "websocket": # pragma: no branch
191 websocket_close = WebSocketClose()
192 await websocket_close(scope, receive, send)
193 return
194
195 scope.update(child_scope)
196 await self.handle(scope, receive, send)
197
198
199class Route(BaseRoute):

Callers

nothing calls this directly

Calls 5

matchesMethod · 0.95
handleMethod · 0.95
PlainTextResponseClass · 0.90
WebSocketCloseClass · 0.90
updateMethod · 0.45

Tested by

no test coverage detected