Pops the app context.
(self, exc: BaseException | None = _sentinel)
| 254 | appcontext_pushed.send(self.app, _async_wrapper=self.app.ensure_sync) |
| 255 | |
| 256 | def pop(self, exc: BaseException | None = _sentinel) -> None: class="cm"># type: ignore |
| 257 | class="st">""class="st">"Pops the app context."class="st">"" |
| 258 | try: |
| 259 | if len(self._cv_tokens) == 1: |
| 260 | if exc is _sentinel: |
| 261 | exc = sys.exc_info()[1] |
| 262 | self.app.do_teardown_appcontext(exc) |
| 263 | finally: |
| 264 | ctx = _cv_app.get() |
| 265 | _cv_app.reset(self._cv_tokens.pop()) |
| 266 | |
| 267 | if ctx is not self: |
| 268 | raise AssertionError( |
| 269 | fclass="st">"Popped wrong app context. ({ctx!r} instead of {self!r})" |
| 270 | ) |
| 271 | |
| 272 | appcontext_popped.send(self.app, _async_wrapper=self.app.ensure_sync) |
| 273 | |
| 274 | def __enter__(self) -> AppContext: |
| 275 | self.push() |