Format: text/x-python
⬇ Download File (1.7 KB)
   1  from __future__ import annotations
   2  
   3  import typing as t
   4  from contextvars import ContextVar
   5  
   6  from werkzeug.local import LocalProxy
   7  
   8  if t.TYPE_CHECKING:  # pragma: no cover
   9      from .app import Flask
  10      from .ctx import _AppCtxGlobals
  11      from .ctx import AppContext
  12      from .ctx import RequestContext
  13      from .sessions import SessionMixin
  14      from .wrappers import Request
  15  
  16  
  17  _no_app_msg = """\
  18  Working outside of application context.
  19  
  20  This typically means that you attempted to use functionality that needed
  21  the current application. To solve this, set up an application context
  22  with app.app_context(). See the documentation for more information.\
  23  """
  24  _cv_app: ContextVar[AppContext] = ContextVar("flask.app_ctx")
  25  app_ctx: AppContext = LocalProxy(  # type: ignore[assignment]
  26      _cv_app, unbound_message=_no_app_msg
  27  )
  28  current_app: Flask = LocalProxy(  # type: ignore[assignment]
  29      _cv_app, "app", unbound_message=_no_app_msg
  30  )
  31  g: _AppCtxGlobals = LocalProxy(  # type: ignore[assignment]
  32      _cv_app, "g", unbound_message=_no_app_msg
  33  )
  34  
  35  _no_req_msg = """\
  36  Working outside of request context.
  37  
  38  This typically means that you attempted to use functionality that needed
  39  an active HTTP request. Consult the documentation on testing for
  40  information about how to avoid this problem.\
  41  """
  42  _cv_request: ContextVar[RequestContext] = ContextVar("flask.request_ctx")
  43  request_ctx: RequestContext = LocalProxy(  # type: ignore[assignment]
  44      _cv_request, unbound_message=_no_req_msg
  45  )
  46  request: Request = LocalProxy(  # type: ignore[assignment]
  47      _cv_request, "request", unbound_message=_no_req_msg
  48  )
  49  session: SessionMixin = LocalProxy(  # type: ignore[assignment]
  50      _cv_request, "session", unbound_message=_no_req_msg
  51  )
  52