Skip to content
Myr

Change _cv_req -> _cv_request

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This is a clearer name for the variable.

authored by pgjones · committed by pgjones · parent 979e0ad · 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

7 files+25 added−25 removed

modified:src/flask/app.py+3 added-3 removed
37 unmodified lines
38from .ctx import _AppCtxGlobals39from .ctx import AppContext40from .ctx import RequestContext41from .globals import _cv_app42from .globals import _cv_req42from .globals import _cv_request43from .globals import g44from .globals import request45from .globals import request_ctx46from .globals import session
1695 unmodified lines
17421743 .. 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)17471748 if req_ctx is not None:1749 url_adapter = req_ctx.url_adapter1750 blueprint_name = req_ctx.request.blueprint
557 unmodified lines
2308 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())23132314 if error is not None and self.should_ignore_error(error):2315 error = None2316
8 unmodified lines
modified:src/flask/ctx.py+7 added-7 removed
6 unmodified lines
7from werkzeug.exceptions import HTTPException89from . import typing as ft10from .globals import _cv_app11from .globals import _cv_req11from .globals import _cv_request12from .signals import appcontext_popped13from .signals import appcontext_pushed1415if t.TYPE_CHECKING: # pragma: no cover
114 unmodified lines
130 some headers without converting the return value into a response object.131132 .. versionadded:: 0.9133 """134 ctx = _cv_req.get(None)134 ctx = _cv_request.get(None)135136 if ctx is None:137 raise RuntimeError(138 "'after_this_request' can only be used when a request"
27 unmodified lines
166 return 'Regular response'167168 .. versionadded:: 0.10169 """170 ctx = _cv_req.get(None)170 ctx = _cv_request.get(None)171172 if ctx is None:173 raise RuntimeError(174 "'copy_current_request_context' can only be used when a"
47 unmodified lines
222 :data:`current_app` object instead.223224 .. versionadded:: 0.9225 """226 return _cv_req.get(None) is not None226 return _cv_request.get(None) is not None227228229class AppContext:230 """The app context contains application-specific information. An app
131 unmodified lines
362 app_ctx.push()363 else:364 app_ctx = None365366 self._cv_tokens.append((_cv_req.set(self), app_ctx))366 self._cv_tokens.append((_cv_request.set(self), app_ctx))367368 # 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 was
29 unmodified lines
400 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)407408 # 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 lines
modified:src/flask/globals.py+5 added-5 removed
68 unmodified lines
69This typically means that you attempted to use functionality that needed70an active HTTP request. Consult the documentation on testing for71information 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)75request_ctx: "RequestContext" = LocalProxy( # type: ignore[assignment]76 _cv_req, unbound_message=_no_req_msg76 _cv_request, unbound_message=_no_req_msg77)78request: "Request" = LocalProxy( # type: ignore[assignment]79 _cv_req, "request", unbound_message=_no_req_msg79 _cv_request, "request", unbound_message=_no_req_msg80)81session: "SessionMixin" = LocalProxy( # type: ignore[assignment]82 _cv_req, "session", unbound_message=_no_req_msg82 _cv_request, "session", unbound_message=_no_req_msg83)848586def __getattr__(name: str) -> t.Any:
21 unmodified lines
modified:src/flask/helpers.py+2 added-2 removed
10 unmodified lines
11import werkzeug.utils12from werkzeug.exceptions import abort as _wz_abort13from werkzeug.utils import redirect as _wz_redirect1415from .globals import _cv_req15from .globals import _cv_request16from .globals import current_app17from .globals import request18from .globals import request_ctx19from .globals import session
90 unmodified lines
110111 return update_wrapper(decorator, generator_or_function) # type: ignore112113 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 lines
modified:src/flask/templating.py+2 added-2 removed
4 unmodified lines
5from jinja2 import Template6from jinja2 import TemplateNotFound78from .globals import _cv_app9from .globals import _cv_req9from .globals import _cv_request10from .globals import current_app11from .globals import request12from .helpers import stream_with_context13from .signals import before_render_template
8 unmodified lines
22 """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 lines
modified:src/flask/testing.py+4 added-4 removed
9 unmodified lines
10from werkzeug.urls import url_parse11from werkzeug.wrappers import Request as BaseRequest1213from .cli import ScriptInfo14from .globals import _cv_req14from .globals import _cv_request15from .json import dumps as json_dumps16from .sessions import SessionMixin1718if t.TYPE_CHECKING: # pragma: no cover
126 unmodified lines
145 )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 lines
161 # (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)170171 resp = app.response_class()172 if not session_interface.is_null_session(sess):173 session_interface.save_session(app, sess, resp)
114 unmodified lines
modified:tests/test_testing.py+2 added-2 removed
3 unmodified lines
45import flask6from flask import appcontext_popped7from flask.cli import ScriptInfo8from flask.globals import _cv_req8from flask.globals import _cv_request9from flask.json import jsonify10from flask.testing import EnvironBuilder11from flask.testing import FlaskCliRunner12
386 unmodified lines
399400 # 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