diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-05-03 00:01:03 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-05-03 00:06:37 +0300 |
commit | 38934cfb0b963a0157cf16c13499977ac87f35b9 (patch) | |
tree | 124d141726b8a860761a75fe2b597eecce078ee7 /contrib/python/Flask/py3/flask/ctx.py | |
parent | 616419d508d3ee4a3b07a82e5cae5ab4544bd1e2 (diff) | |
download | ydb-38934cfb0b963a0157cf16c13499977ac87f35b9.tar.gz |
Intermediate changes
Diffstat (limited to 'contrib/python/Flask/py3/flask/ctx.py')
-rw-r--r-- | contrib/python/Flask/py3/flask/ctx.py | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/contrib/python/Flask/py3/flask/ctx.py b/contrib/python/Flask/py3/flask/ctx.py index 47465fd4e1..e6822b2d97 100644 --- a/contrib/python/Flask/py3/flask/ctx.py +++ b/contrib/python/Flask/py3/flask/ctx.py @@ -5,11 +5,11 @@ from types import TracebackType from werkzeug.exceptions import HTTPException +from . import typing as ft from .globals import _app_ctx_stack from .globals import _request_ctx_stack from .signals import appcontext_popped from .signals import appcontext_pushed -from .typing import AfterRequestCallable if t.TYPE_CHECKING: from .app import Flask @@ -109,7 +109,7 @@ class _AppCtxGlobals: return object.__repr__(self) -def after_this_request(f: AfterRequestCallable) -> AfterRequestCallable: +def after_this_request(f: ft.AfterRequestCallable) -> ft.AfterRequestCallable: """Executes a function after this request. This is useful to modify response objects. The function is passed the response object and has to return the same or a new one. @@ -178,7 +178,7 @@ def copy_current_request_context(f: t.Callable) -> t.Callable: def wrapper(*args, **kwargs): with reqctx: - return f(*args, **kwargs) + return reqctx.app.ensure_sync(f)(*args, **kwargs) return update_wrapper(wrapper, f) @@ -267,7 +267,10 @@ class AppContext: return self def __exit__( - self, exc_type: type, exc_value: BaseException, tb: TracebackType + self, + exc_type: t.Optional[type], + exc_value: t.Optional[BaseException], + tb: t.Optional[TracebackType], ) -> None: self.pop(exc_value) @@ -338,14 +341,32 @@ class RequestContext: # Functions that should be executed after the request on the response # object. These will be called before the regular "after_request" # functions. - self._after_request_functions: t.List[AfterRequestCallable] = [] + self._after_request_functions: t.List[ft.AfterRequestCallable] = [] @property - def g(self) -> AppContext: + def g(self) -> _AppCtxGlobals: + import warnings + + warnings.warn( + "Accessing 'g' on the request context is deprecated and" + " will be removed in Flask 2.2. Access `g` directly or from" + "the application context instead.", + DeprecationWarning, + stacklevel=2, + ) return _app_ctx_stack.top.g @g.setter - def g(self, value: AppContext) -> None: + def g(self, value: _AppCtxGlobals) -> None: + import warnings + + warnings.warn( + "Setting 'g' on the request context is deprecated and" + " will be removed in Flask 2.2. Set it on the application" + " context instead.", + DeprecationWarning, + stacklevel=2, + ) _app_ctx_stack.top.g = value def copy(self) -> "RequestContext": @@ -473,7 +494,10 @@ class RequestContext: return self def __exit__( - self, exc_type: type, exc_value: BaseException, tb: TracebackType + self, + exc_type: t.Optional[type], + exc_value: t.Optional[BaseException], + tb: t.Optional[TracebackType], ) -> None: # do not pop the request stack if we are in debug mode and an # exception happened. This will allow the debugger to still |