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

Method push

src/flask/ctx.py:377–404  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

375 return self._session
376
377 def push(self) -> None:
378 # Before we push the request context we have to ensure that there
379 # is an application context.
380 app_ctx = _cv_app.get(None)
381
382 if app_ctx is None or app_ctx.app is not self.app:
383 app_ctx = self.app.app_context()
384 app_ctx.push()
385 else:
386 app_ctx = None
387
388 self._cv_tokens.append((_cv_request.set(self), app_ctx))
389
390 # Open the session at the moment that the request context is available.
391 # This allows a custom open_session method to use the request context.
392 # Only open a new session if this is the first time the request was
393 # pushed, otherwise stream_with_context loses the session.
394 if self._session is None:
395 session_interface = self.app.session_interface
396 self._session = session_interface.open_session(self.app, self.request)
397
398 if self._session is None:
399 self._session = session_interface.make_null_session(self.app)
400
401 # Match the request URL after loading the session, so that the
402 # session is available in custom URL converters.
403 if self.url_adapter is not None:
404 self.match_request()
405
406 def pop(self, exc: BaseException | None = _sentinel) -> None: # type: ignore
407 """Pops the request context and unbinds it by doing that. This will

Callers 1

__enter__Method · 0.95

Calls 6

match_requestMethod · 0.95
app_contextMethod · 0.80
make_null_sessionMethod · 0.80
getMethod · 0.45
pushMethod · 0.45
open_sessionMethod · 0.45

Tested by

no test coverage detected