The context relating to the specific request, bound to the current task. Do not use directly, prefer the :func:`~quart.Quart.request_context` or :func:`~quart.Quart.test_request_context` instead. Attributes: _after_request_functions: List of functions to execute after the c
| 124 | |
| 125 | |
| 126 | class RequestContext(_BaseRequestWebsocketContext): |
| 127 | """The context relating to the specific request, bound to the current task. |
| 128 | |
| 129 | Do not use directly, prefer the |
| 130 | :func:`~quart.Quart.request_context` or |
| 131 | :func:`~quart.Quart.test_request_context` instead. |
| 132 | |
| 133 | Attributes: |
| 134 | _after_request_functions: List of functions to execute after the current |
| 135 | request, see :func:`after_this_request`. |
| 136 | """ |
| 137 | |
| 138 | def __init__( |
| 139 | self, |
| 140 | app: Quart, |
| 141 | request: Request, |
| 142 | session: SessionMixin | None = None, |
| 143 | ) -> None: |
| 144 | super().__init__(app, request, session) |
| 145 | self.flashes = None |
| 146 | self._after_request_functions: list[AfterRequestCallable] = [] |
| 147 | |
| 148 | @property |
| 149 | def request(self) -> Request: |
| 150 | return cast(Request, self.request_websocket) |
| 151 | |
| 152 | async def push(self) -> None: |
| 153 | await super()._push_appctx(_cv_request.set(self)) |
| 154 | await super()._push() |
| 155 | |
| 156 | async def pop(self, exc: BaseException | None = _sentinel) -> None: # type: ignore |
| 157 | try: |
| 158 | if len(self._cv_tokens) == 1: |
| 159 | if exc is _sentinel: |
| 160 | exc = sys.exc_info()[1] |
| 161 | await self.app.do_teardown_request(exc, self) |
| 162 | |
| 163 | request_close = getattr(self.request_websocket, "close", None) |
| 164 | if request_close is not None: |
| 165 | await request_close() |
| 166 | finally: |
| 167 | ctx = _cv_request.get() |
| 168 | token, app_ctx = self._cv_tokens.pop() |
| 169 | _cv_request.reset(token) |
| 170 | |
| 171 | if app_ctx is not None: |
| 172 | await app_ctx.pop(exc) |
| 173 | |
| 174 | if ctx is not self: |
| 175 | raise AssertionError( |
| 176 | f"Popped wrong request context. ({ctx!r} instead of {self!r})" |
| 177 | ) |
| 178 | |
| 179 | async def __aenter__(self) -> RequestContext: |
| 180 | await self.push() |
| 181 | return self |
| 182 | |
| 183 |
no outgoing calls
searching dependent graphs…