Change _cv_req -> _cv_request

This is a clearer name for the variable.
This commit is contained in:
pgjones 2022-07-09 13:41:35 +01:00
parent 979e0adbac
commit 91044c4d76
7 changed files with 25 additions and 25 deletions

View file

@ -39,7 +39,7 @@ from .ctx import _AppCtxGlobals
from .ctx import AppContext from .ctx import AppContext
from .ctx import RequestContext from .ctx import RequestContext
from .globals import _cv_app from .globals import _cv_app
from .globals import _cv_req from .globals import _cv_request
from .globals import g from .globals import g
from .globals import request from .globals import request
from .globals import request_ctx from .globals import request_ctx
@ -1743,7 +1743,7 @@ class Flask(Scaffold):
.. versionadded:: 2.2 .. versionadded:: 2.2
Moved from ``flask.url_for``, which calls this method. Moved from ``flask.url_for``, which calls this method.
""" """
req_ctx = _cv_req.get(None) req_ctx = _cv_request.get(None)
if req_ctx is not None: if req_ctx is not None:
url_adapter = req_ctx.url_adapter url_adapter = req_ctx.url_adapter
@ -2309,7 +2309,7 @@ class Flask(Scaffold):
finally: finally:
if "werkzeug.debug.preserve_context" in environ: if "werkzeug.debug.preserve_context" in environ:
environ["werkzeug.debug.preserve_context"](_cv_app.get()) environ["werkzeug.debug.preserve_context"](_cv_app.get())
environ["werkzeug.debug.preserve_context"](_cv_req.get()) environ["werkzeug.debug.preserve_context"](_cv_request.get())
if error is not None and self.should_ignore_error(error): if error is not None and self.should_ignore_error(error):
error = None error = None

View file

@ -8,7 +8,7 @@ from werkzeug.exceptions import HTTPException
from . import typing as ft from . import typing as ft
from .globals import _cv_app from .globals import _cv_app
from .globals import _cv_req from .globals import _cv_request
from .signals import appcontext_popped from .signals import appcontext_popped
from .signals import appcontext_pushed from .signals import appcontext_pushed
@ -131,7 +131,7 @@ def after_this_request(f: ft.AfterRequestCallable) -> ft.AfterRequestCallable:
.. versionadded:: 0.9 .. versionadded:: 0.9
""" """
ctx = _cv_req.get(None) ctx = _cv_request.get(None)
if ctx is None: if ctx is None:
raise RuntimeError( raise RuntimeError(
@ -167,7 +167,7 @@ def copy_current_request_context(f: t.Callable) -> t.Callable:
.. versionadded:: 0.10 .. versionadded:: 0.10
""" """
ctx = _cv_req.get(None) ctx = _cv_request.get(None)
if ctx is None: if ctx is None:
raise RuntimeError( raise RuntimeError(
@ -223,7 +223,7 @@ def has_app_context() -> bool:
.. versionadded:: 0.9 .. versionadded:: 0.9
""" """
return _cv_req.get(None) is not None return _cv_request.get(None) is not None
class AppContext: class AppContext:
@ -363,7 +363,7 @@ class RequestContext:
else: else:
app_ctx = None app_ctx = None
self._cv_tokens.append((_cv_req.set(self), app_ctx)) self._cv_tokens.append((_cv_request.set(self), app_ctx))
# Open the session at the moment that the request context is available. # Open the session at the moment that the request context is available.
# This allows a custom open_session method to use the request context. # This allows a custom open_session method to use the request context.
@ -401,9 +401,9 @@ class RequestContext:
if request_close is not None: if request_close is not None:
request_close() request_close()
finally: finally:
ctx = _cv_req.get() ctx = _cv_request.get()
token, app_ctx = self._cv_tokens.pop() token, app_ctx = self._cv_tokens.pop()
_cv_req.reset(token) _cv_request.reset(token)
# get rid of circular dependencies at the end of the request # get rid of circular dependencies at the end of the request
# so that we don't require the GC to be active. # so that we don't require the GC to be active.

View file

@ -70,16 +70,16 @@ This typically means that you attempted to use functionality that needed
an active HTTP request. Consult the documentation on testing for an active HTTP request. Consult the documentation on testing for
information about how to avoid this problem.\ information about how to avoid this problem.\
""" """
_cv_req: ContextVar["RequestContext"] = ContextVar("flask.request_ctx") _cv_request: ContextVar["RequestContext"] = ContextVar("flask.request_ctx")
__request_ctx_stack = _FakeStack("request", _cv_req) __request_ctx_stack = _FakeStack("request", _cv_request)
request_ctx: "RequestContext" = LocalProxy( # type: ignore[assignment] request_ctx: "RequestContext" = LocalProxy( # type: ignore[assignment]
_cv_req, unbound_message=_no_req_msg _cv_request, unbound_message=_no_req_msg
) )
request: "Request" = LocalProxy( # type: ignore[assignment] request: "Request" = LocalProxy( # type: ignore[assignment]
_cv_req, "request", unbound_message=_no_req_msg _cv_request, "request", unbound_message=_no_req_msg
) )
session: "SessionMixin" = LocalProxy( # type: ignore[assignment] session: "SessionMixin" = LocalProxy( # type: ignore[assignment]
_cv_req, "session", unbound_message=_no_req_msg _cv_request, "session", unbound_message=_no_req_msg
) )

View file

@ -12,7 +12,7 @@ import werkzeug.utils
from werkzeug.exceptions import abort as _wz_abort from werkzeug.exceptions import abort as _wz_abort
from werkzeug.utils import redirect as _wz_redirect from werkzeug.utils import redirect as _wz_redirect
from .globals import _cv_req from .globals import _cv_request
from .globals import current_app from .globals import current_app
from .globals import request from .globals import request
from .globals import request_ctx from .globals import request_ctx
@ -111,7 +111,7 @@ def stream_with_context(
return update_wrapper(decorator, generator_or_function) # type: ignore return update_wrapper(decorator, generator_or_function) # type: ignore
def generator() -> t.Generator: def generator() -> t.Generator:
ctx = _cv_req.get(None) ctx = _cv_request.get(None)
if ctx is None: if ctx is None:
raise RuntimeError( raise RuntimeError(
"'stream_with_context' can only be used when a request" "'stream_with_context' can only be used when a request"

View file

@ -6,7 +6,7 @@ from jinja2 import Template
from jinja2 import TemplateNotFound from jinja2 import TemplateNotFound
from .globals import _cv_app from .globals import _cv_app
from .globals import _cv_req from .globals import _cv_request
from .globals import current_app from .globals import current_app
from .globals import request from .globals import request
from .helpers import stream_with_context from .helpers import stream_with_context
@ -23,7 +23,7 @@ def _default_template_ctx_processor() -> t.Dict[str, t.Any]:
`session` and `g`. `session` and `g`.
""" """
appctx = _cv_app.get(None) appctx = _cv_app.get(None)
reqctx = _cv_req.get(None) reqctx = _cv_request.get(None)
rv: t.Dict[str, t.Any] = {} rv: t.Dict[str, t.Any] = {}
if appctx is not None: if appctx is not None:
rv["g"] = appctx.g rv["g"] = appctx.g

View file

@ -11,7 +11,7 @@ from werkzeug.urls import url_parse
from werkzeug.wrappers import Request as BaseRequest from werkzeug.wrappers import Request as BaseRequest
from .cli import ScriptInfo from .cli import ScriptInfo
from .globals import _cv_req from .globals import _cv_request
from .json import dumps as json_dumps from .json import dumps as json_dumps
from .sessions import SessionMixin from .sessions import SessionMixin
@ -146,7 +146,7 @@ class FlaskClient(Client):
app = self.application app = self.application
environ_overrides = kwargs.setdefault("environ_overrides", {}) environ_overrides = kwargs.setdefault("environ_overrides", {})
self.cookie_jar.inject_wsgi(environ_overrides) self.cookie_jar.inject_wsgi(environ_overrides)
outer_reqctx = _cv_req.get(None) outer_reqctx = _cv_request.get(None)
with app.test_request_context(*args, **kwargs) as c: with app.test_request_context(*args, **kwargs) as c:
session_interface = app.session_interface session_interface = app.session_interface
sess = session_interface.open_session(app, c.request) sess = session_interface.open_session(app, c.request)
@ -162,11 +162,11 @@ class FlaskClient(Client):
# behavior. It's important to not use the push and pop # behavior. It's important to not use the push and pop
# methods of the actual request context object since that would # methods of the actual request context object since that would
# mean that cleanup handlers are called # mean that cleanup handlers are called
token = _cv_req.set(outer_reqctx) # type: ignore[arg-type] token = _cv_request.set(outer_reqctx) # type: ignore[arg-type]
try: try:
yield sess yield sess
finally: finally:
_cv_req.reset(token) _cv_request.reset(token)
resp = app.response_class() resp = app.response_class()
if not session_interface.is_null_session(sess): if not session_interface.is_null_session(sess):

View file

@ -5,7 +5,7 @@ import werkzeug
import flask import flask
from flask import appcontext_popped from flask import appcontext_popped
from flask.cli import ScriptInfo from flask.cli import ScriptInfo
from flask.globals import _cv_req from flask.globals import _cv_request
from flask.json import jsonify from flask.json import jsonify
from flask.testing import EnvironBuilder from flask.testing import EnvironBuilder
from flask.testing import FlaskCliRunner from flask.testing import FlaskCliRunner
@ -400,4 +400,4 @@ def test_client_pop_all_preserved(app, req_ctx, client):
# close the response, releasing the context held by stream_with_context # close the response, releasing the context held by stream_with_context
rv.close() rv.close()
# only req_ctx fixture should still be pushed # only req_ctx fixture should still be pushed
assert _cv_req.get(None) is req_ctx assert _cv_request.get(None) is req_ctx