MCPcopy
hub / github.com/pallets/flask / pop

Method pop

src/flask/ctx.py:406–441  ·  src/flask/ctx.py::RequestContext.pop

Pops the request context and unbinds it by doing that. This will also trigger the execution of functions registered by the :meth:`~flask.Flask.teardown_request` decorator. .. versionchanged:: 0.9 Added the `exc` argument.

(self, exc: BaseException | None = _sentinel)

Source from the content-addressed store, hash-verified

404 self.match_request()
405
406 def pop(self, exc: BaseException | None = _sentinel) -> None: class="cm"># type: ignore
407 class="st">"""Pops the request context and unbinds it by doing that. This will
408 also trigger the execution of functions registered by the
409 :meth:`~flask.Flask.teardown_request` decorator.
410
411 .. versionchanged:: 0.9
412 Added the `exc` argument.
413 class="st">"""
414 clear_request = len(self._cv_tokens) == 1
415
416 try:
417 if clear_request:
418 if exc is _sentinel:
419 exc = sys.exc_info()[1]
420 self.app.do_teardown_request(exc)
421
422 request_close = getattr(self.request, class="st">"close", None)
423 if request_close is not None:
424 request_close()
425 finally:
426 ctx = _cv_request.get()
427 token, app_ctx = self._cv_tokens.pop()
428 _cv_request.reset(token)
429
430 class="cm"># get rid of circular dependencies at the end of the request
431 class="cm"># so that we don't require the GC to be active.
432 if clear_request:
433 ctx.request.environ[class="st">"werkzeug.request"] = None
434
435 if app_ctx is not None:
436 app_ctx.pop(exc)
437
438 if ctx is not self:
439 raise AssertionError(
440 fclass="st">"Popped wrong request context. ({ctx!r} instead of {self!r})"
441 )
442
443 def __enter__(self) -> RequestContext:
444 self.push()

Callers 1

__exit__Method · 0.95

Calls 3

do_teardown_requestMethod · 0.80
getMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected