MCPcopy Create free account
hub / github.com/pallets/quart / copy_current_request_context

Function copy_current_request_context

src/quart/ctx.py:378–405  ·  view source on GitHub ↗

Share the current request context with the function decorated. The request context is local per task and hence will not be available in any other task. This decorator can be used to make the context available, .. code-block:: python @copy_current_request_context as

(func: Callable)

Source from the content-addressed store, hash-verified

376
377
378def copy_current_request_context(func: Callable) -> Callable:
379 """Share the current request context with the function decorated.
380
381 The request context is local per task and hence will not be
382 available in any other task. This decorator can be used to make
383 the context available,
384
385 .. code-block:: python
386
387 @copy_current_request_context
388 async def within_context() -> None:
389 method = request.method
390 ...
391
392 """
393 if not has_request_context():
394 raise RuntimeError(
395 "Attempt to copy request context outside of a request context"
396 )
397
398 request_context = _cv_request.get().copy()
399
400 @wraps(func)
401 async def wrapper(*args: Any, **kwargs: Any) -> Any:
402 async with request_context:
403 return await request_context.app.ensure_async(func)(*args, **kwargs)
404
405 return wrapper
406
407
408def copy_current_websocket_context(func: Callable) -> Callable:

Calls 3

has_request_contextFunction · 0.85
copyMethod · 0.45
getMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…