Merge pull request #4685 from pgjones/name
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Change _cv_req -> _cv_request
authored by David Lord · committed by GitHub · parents 979e0ad, 91044c4 · Browse files · 7 files·+25 added−25 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+25 added−25 removed
- tests:+2 added−2 removed
- other:+23 added−23 removed
Provenance
- Commit
5775d1e- Tree
04d97b1- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
979e0ad- Parent 2
91044c4
7 files changed+25 added−25 removed
modified:src/flask/app.py+3 added-3 removed
37 unmodified lines38 from .ctx import _AppCtxGlobals39 from .ctx import AppContext40 from .ctx import RequestContext41 from .globals import _cv_app42-from .globals import _cv_req42+from .globals import _cv_request43 from .globals import g44 from .globals import request45 from .globals import request_ctx46 from .globals import session1695 unmodified lines1742 1743 .. versionadded:: 2.21744 Moved from ``flask.url_for``, which calls this method.1745 """1746- req_ctx = _cv_req.get(None)1746+ req_ctx = _cv_request.get(None)1747 1748 if req_ctx is not None:1749 url_adapter = req_ctx.url_adapter1750 blueprint_name = req_ctx.request.blueprint557 unmodified lines2308 return response(environ, start_response)2309 finally:2310 if "werkzeug.debug.preserve_context" in environ:2311 environ["werkzeug.debug.preserve_context"](_cv_app.get())2312- environ["werkzeug.debug.preserve_context"](_cv_req.get())2312+ environ["werkzeug.debug.preserve_context"](_cv_request.get())2313 2314 if error is not None and self.should_ignore_error(error):2315 error = None2316 8 unmodified linesmodified:src/flask/ctx.py+7 added-7 removed
6 unmodified lines7 from werkzeug.exceptions import HTTPException8 9 from . import typing as ft10 from .globals import _cv_app11-from .globals import _cv_req11+from .globals import _cv_request12 from .signals import appcontext_popped13 from .signals import appcontext_pushed14 15 if t.TYPE_CHECKING: # pragma: no cover114 unmodified lines130 some headers without converting the return value into a response object.131 132 .. versionadded:: 0.9133 """134- ctx = _cv_req.get(None)134+ ctx = _cv_request.get(None)135 136 if ctx is None:137 raise RuntimeError(138 "'after_this_request' can only be used when a request"27 unmodified lines166 return 'Regular response'167 168 .. versionadded:: 0.10169 """170- ctx = _cv_req.get(None)170+ ctx = _cv_request.get(None)171 172 if ctx is None:173 raise RuntimeError(174 "'copy_current_request_context' can only be used when a"47 unmodified lines222 :data:`current_app` object instead.223 224 .. versionadded:: 0.9225 """226- return _cv_req.get(None) is not None226+ return _cv_request.get(None) is not None227 228 229 class AppContext:230 """The app context contains application-specific information. An app131 unmodified lines362 app_ctx.push()363 else:364 app_ctx = None365 366- self._cv_tokens.append((_cv_req.set(self), app_ctx))366+ self._cv_tokens.append((_cv_request.set(self), app_ctx))367 368 # Open the session at the moment that the request context is available.369 # This allows a custom open_session method to use the request context.370 # Only open a new session if this is the first time the request was29 unmodified lines400 request_close = getattr(self.request, "close", None)401 if request_close is not None:402 request_close()403 finally:404- ctx = _cv_req.get()404+ ctx = _cv_request.get()405 token, app_ctx = self._cv_tokens.pop()406- _cv_req.reset(token)406+ _cv_request.reset(token)407 408 # get rid of circular dependencies at the end of the request409 # so that we don't require the GC to be active.410 if clear_request:27 unmodified linesmodified:src/flask/globals.py+5 added-5 removed
68 unmodified lines69 This typically means that you attempted to use functionality that needed70 an active HTTP request. Consult the documentation on testing for71 information about how to avoid this problem.\72 """73-_cv_req: ContextVar["RequestContext"] = ContextVar("flask.request_ctx")74-__request_ctx_stack = _FakeStack("request", _cv_req)73+_cv_request: ContextVar["RequestContext"] = ContextVar("flask.request_ctx")74+__request_ctx_stack = _FakeStack("request", _cv_request)75 request_ctx: "RequestContext" = LocalProxy( # type: ignore[assignment]76- _cv_req, unbound_message=_no_req_msg76+ _cv_request, unbound_message=_no_req_msg77 )78 request: "Request" = LocalProxy( # type: ignore[assignment]79- _cv_req, "request", unbound_message=_no_req_msg79+ _cv_request, "request", unbound_message=_no_req_msg80 )81 session: "SessionMixin" = LocalProxy( # type: ignore[assignment]82- _cv_req, "session", unbound_message=_no_req_msg82+ _cv_request, "session", unbound_message=_no_req_msg83 )84 85 86 def __getattr__(name: str) -> t.Any:21 unmodified linesmodified:src/flask/helpers.py+2 added-2 removed
10 unmodified lines11 import werkzeug.utils12 from werkzeug.exceptions import abort as _wz_abort13 from werkzeug.utils import redirect as _wz_redirect14 15-from .globals import _cv_req15+from .globals import _cv_request16 from .globals import current_app17 from .globals import request18 from .globals import request_ctx19 from .globals import session90 unmodified lines110 111 return update_wrapper(decorator, generator_or_function) # type: ignore112 113 def generator() -> t.Generator:114- ctx = _cv_req.get(None)114+ ctx = _cv_request.get(None)115 if ctx is None:116 raise RuntimeError(117 "'stream_with_context' can only be used when a request"118 " context is active, such as in a view function."568 unmodified linesmodified:src/flask/templating.py+2 added-2 removed
4 unmodified lines5 from jinja2 import Template6 from jinja2 import TemplateNotFound7 8 from .globals import _cv_app9-from .globals import _cv_req9+from .globals import _cv_request10 from .globals import current_app11 from .globals import request12 from .helpers import stream_with_context13 from .signals import before_render_template8 unmodified lines22 """Default template context processor. Injects `request`,23 `session` and `g`.24 """25 appctx = _cv_app.get(None)26- reqctx = _cv_req.get(None)26+ reqctx = _cv_request.get(None)27 rv: t.Dict[str, t.Any] = {}28 if appctx is not None:29 rv["g"] = appctx.g30 if reqctx is not None:182 unmodified linesmodified:src/flask/testing.py+4 added-4 removed
9 unmodified lines10 from werkzeug.urls import url_parse11 from werkzeug.wrappers import Request as BaseRequest12 13 from .cli import ScriptInfo14-from .globals import _cv_req14+from .globals import _cv_request15 from .json import dumps as json_dumps16 from .sessions import SessionMixin17 18 if t.TYPE_CHECKING: # pragma: no cover126 unmodified lines145 )146 app = self.application147 environ_overrides = kwargs.setdefault("environ_overrides", {})148 self.cookie_jar.inject_wsgi(environ_overrides)149- outer_reqctx = _cv_req.get(None)149+ outer_reqctx = _cv_request.get(None)150 with app.test_request_context(*args, **kwargs) as c:151 session_interface = app.session_interface152 sess = session_interface.open_session(app, c.request)153 if sess is None:7 unmodified lines161 # (or None) on top of this and popping it we get exactly that162 # behavior. It's important to not use the push and pop163 # methods of the actual request context object since that would164 # mean that cleanup handlers are called165- token = _cv_req.set(outer_reqctx) # type: ignore[arg-type]165+ token = _cv_request.set(outer_reqctx) # type: ignore[arg-type]166 try:167 yield sess168 finally:169- _cv_req.reset(token)169+ _cv_request.reset(token)170 171 resp = app.response_class()172 if not session_interface.is_null_session(sess):173 session_interface.save_session(app, sess, resp)114 unmodified linesmodified:tests/test_testing.py+2 added-2 removed
3 unmodified lines4 5 import flask6 from flask import appcontext_popped7 from flask.cli import ScriptInfo8-from flask.globals import _cv_req8+from flask.globals import _cv_request9 from flask.json import jsonify10 from flask.testing import EnvironBuilder11 from flask.testing import FlaskCliRunner12 386 unmodified lines399 400 # close the response, releasing the context held by stream_with_context401 rv.close()402 # only req_ctx fixture should still be pushed403- assert _cv_req.get(None) is req_ctx403+ assert _cv_request.get(None) is req_ctx