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

Method __call__

starlette/responses.py:257–283  ·  view source on GitHub ↗
(self, scope: Scope, receive: Receive, send: Send)

Source from the content-addressed store, hash-verified

255 await send({"type": "http.response.body", "body": b"", "more_body": False})
256
257 async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
258 if scope["type"] == "websocket":
259 send = self._wrap_websocket_denial_send(send)
260 await self.stream_response(send)
261 if self.background is not None:
262 await self.background()
263 return
264
265 spec_version = tuple(map(int, scope.get("asgi", {}).get("spec_version", "2.0").split(".")))
266
267 if spec_version >= (2, 4):
268 try:
269 await self.stream_response(send)
270 except OSError:
271 raise ClientDisconnect()
272 else:
273 async with create_collapsing_task_group() as task_group:
274
275 async def wrap(func: Callable[[], Awaitable[None]]) -> None:
276 await func()
277 task_group.cancel_scope.cancel()
278
279 task_group.start_soon(wrap, partial(self.stream_response, send))
280 await wrap(partial(self.listen_for_disconnect, receive))
281
282 if self.background is not None:
283 await self.background()
284
285
286class MalformedRangeHeader(Exception):

Callers

nothing calls this directly

Calls 6

stream_responseMethod · 0.95
ClientDisconnectClass · 0.90
backgroundMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected