remove previously deprecated code
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent 604de4b · Browse files · 16 files·+81 added−946 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
16 files+81 added−946 removed
- tests:+10 added−71 removed
- other:+71 added−875 removed
Provenance
- Commit
6650764- Tree
4fbff50- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
604de4b
16 files changed+81 added−946 removed
modified:docs/api.rst-6 removed
268 unmodified lines269 .. autoclass:: flask.json.provider.DefaultJSONProvider270 :members:271 :member-order: bysource272 273-.. autoclass:: JSONEncoder274- :members:275-276-.. autoclass:: JSONDecoder277- :members:278-273 .. automodule:: flask.json.tag274 275 276 Template Rendering468 unmodified linesmodified:docs/config.rst+5 added-64 removed
63 unmodified lines64 ----------------------------65 66 The following configuration values are used internally by Flask:67 68-.. py:data:: ENV69-70- What environment the app is running in. The :attr:`~flask.Flask.env` attribute maps71- to this config key.72-73- Default: ``'production'``74-75- .. deprecated:: 2.276- Will be removed in Flask 2.3. Use ``--debug`` instead.77-78- .. versionadded:: 1.079-68 .. py:data:: DEBUG69 70 Whether debug mode is enabled. When using ``flask run`` to start the development71 server, an interactive debugger will be shown for unhandled exceptions, and the186 unmodified lines258 read for security.259 260 Default: ``None``261 274-.. py:data:: JSON_AS_ASCII275-276- Serialize objects to ASCII-encoded JSON. If this is disabled, the277- JSON returned from ``jsonify`` will contain Unicode characters. This278- has security implications when rendering the JSON into JavaScript in279- templates, and should typically remain enabled.280-281- Default: ``True``282-283- .. deprecated:: 2.2284- Will be removed in Flask 2.3. Set ``app.json.ensure_ascii``285- instead.286-287-.. py:data:: JSON_SORT_KEYS288-289- Sort the keys of JSON objects alphabetically. This is useful for caching290- because it ensures the data is serialized the same way no matter what291- Python's hash seed is. While not recommended, you can disable this for a292- possible performance improvement at the cost of caching.293-294- Default: ``True``295-296- .. deprecated:: 2.2297- Will be removed in Flask 2.3. Set ``app.json.sort_keys``298- instead.299-300-.. py:data:: JSONIFY_PRETTYPRINT_REGULAR301-302- :func:`~flask.jsonify` responses will be output with newlines,303- spaces, and indentation for easier reading by humans. Always enabled304- in debug mode.305-306- Default: ``False``307-308- .. deprecated:: 2.2309- Will be removed in Flask 2.3. Set ``app.json.compact`` instead.310-311-.. py:data:: JSONIFY_MIMETYPE312-313- The mimetype of ``jsonify`` responses.314-315- Default: ``'application/json'``316-317- .. deprecated:: 2.2318- Will be removed in Flask 2.3. Set ``app.json.mimetype`` instead.319-262 .. py:data:: TEMPLATES_AUTO_RELOAD263 264 Reload templates when they are changed. If not set, it will be enabled in265 debug mode.56 unmodified lines322 323 .. versionchanged:: 2.2324 Removed ``PRESERVE_CONTEXT_ON_EXCEPTION``.325 384-.. versionchanged:: 2.2385- ``JSON_AS_ASCII``, ``JSON_SORT_KEYS``,386- ``JSONIFY_MIMETYPE``, and ``JSONIFY_PRETTYPRINT_REGULAR`` will be387- removed in Flask 2.3. The default ``app.json`` provider has326+.. versionchanged:: 2.3327+ ``JSON_AS_ASCII``, ``JSON_SORT_KEYS``, ``JSONIFY_MIMETYPE``, and328+ ``JSONIFY_PRETTYPRINT_REGULAR`` were removed. The default ``app.json`` provider has329 equivalent attributes instead.330 390-.. versionchanged:: 2.2391- ``ENV`` will be removed in Flask 2.3. Use ``--debug`` instead.331+.. versionchanged:: 2.3332+ ``ENV`` was removed.333 334 335 Configuring from Python Files336 -----------------------------385 unmodified linesmodified:src/flask/json/__init__.py+24 added-196 removed
1 unmodified line2 3 import json as _json4 import typing as t5 6-from jinja2.utils import htmlsafe_json_dumps as _jinja_htmlsafe_dumps7-6 from ..globals import current_app7 from .provider import _default8 9 if t.TYPE_CHECKING: # pragma: no cover12- from ..app import Flask10 from ..wrappers import Response11 12 16-class JSONEncoder(_json.JSONEncoder):17- """The default JSON encoder. Handles extra types compared to the18- built-in :class:`json.JSONEncoder`.19-20- - :class:`datetime.datetime` and :class:`datetime.date` are21- serialized to :rfc:`822` strings. This is the same as the HTTP22- date format.23- - :class:`decimal.Decimal` is serialized to a string.24- - :class:`uuid.UUID` is serialized to a string.25- - :class:`dataclasses.dataclass` is passed to26- :func:`dataclasses.asdict`.27- - :class:`~markupsafe.Markup` (or any object with a ``__html__``28- method) will call the ``__html__`` method to get a string.29-30- Assign a subclass of this to :attr:`flask.Flask.json_encoder` or31- :attr:`flask.Blueprint.json_encoder` to override the default.32-33- .. deprecated:: 2.234- Will be removed in Flask 2.3. Use ``app.json`` instead.35- """36-37- def __init__(self, **kwargs) -> None:38- import warnings39-40- warnings.warn(41- "'JSONEncoder' is deprecated and will be removed in"42- " Flask 2.3. Use 'Flask.json' to provide an alternate"43- " JSON implementation instead.",44- DeprecationWarning,45- stacklevel=3,46- )47- super().__init__(**kwargs)48-49- def default(self, o: t.Any) -> t.Any:50- """Convert ``o`` to a JSON serializable type. See51- :meth:`json.JSONEncoder.default`. Python does not support52- overriding how basic types like ``str`` or ``list`` are53- serialized, they are handled before this method.54- """55- return _default(o)56-57-58-class JSONDecoder(_json.JSONDecoder):59- """The default JSON decoder.60-61- This does not change any behavior from the built-in62- :class:`json.JSONDecoder`.63-64- Assign a subclass of this to :attr:`flask.Flask.json_decoder` or65- :attr:`flask.Blueprint.json_decoder` to override the default.66-67- .. deprecated:: 2.268- Will be removed in Flask 2.3. Use ``app.json`` instead.69- """70-71- def __init__(self, **kwargs) -> None:72- import warnings73-74- warnings.warn(75- "'JSONDecoder' is deprecated and will be removed in"76- " Flask 2.3. Use 'Flask.json' to provide an alternate"77- " JSON implementation instead.",78- DeprecationWarning,79- stacklevel=3,80- )81- super().__init__(**kwargs)82-83-84-def dumps(obj: t.Any, *, app: Flask | None = None, **kwargs: t.Any) -> str:13+def dumps(obj: t.Any, **kwargs: t.Any) -> str:14 """Serialize data as JSON.15 16 If :data:`~flask.current_app` is available, it will use its17 :meth:`app.json.dumps() <flask.json.provider.JSONProvider.dumps>`1 unmodified line19 20 :param obj: The data to serialize.21 :param kwargs: Arguments passed to the ``dumps`` implementation.22 23+ .. versionchanged:: 2.324+ The ``app`` parameter was removed.25+26 .. versionchanged:: 2.227 Calls ``current_app.json.dumps``, allowing an app to override28 the behavior.29 98- .. versionchanged:: 2.299- The ``app`` parameter will be removed in Flask 2.3.100-30 .. versionchanged:: 2.0.231 :class:`decimal.Decimal` is supported by converting to a string.32 33 .. versionchanged:: 2.02 unmodified lines36 .. versionchanged:: 1.0.337 ``app`` can be passed directly, rather than requiring an app38 context for configuration.39 """111- if app is not None:112- import warnings40+ if current_app:41+ return current_app.json.dumps(obj, **kwargs)42 114- warnings.warn(115- "The 'app' parameter is deprecated and will be removed in"116- " Flask 2.3. Call 'app.json.dumps' directly instead.",117- DeprecationWarning,118- stacklevel=2,119- )120- else:121- app = current_app122-123- if app:124- return app.json.dumps(obj, **kwargs)125-43 kwargs.setdefault("default", _default)44 return _json.dumps(obj, **kwargs)45 46 130-def dump(131- obj: t.Any, fp: t.IO[str], *, app: Flask | None = None, **kwargs: t.Any132-) -> None:47+def dump(obj: t.Any, fp: t.IO[str], **kwargs: t.Any) -> None:48 """Serialize data as JSON and write to a file.49 50 If :data:`~flask.current_app` is available, it will use its51 :meth:`app.json.dump() <flask.json.provider.JSONProvider.dump>`3 unmodified lines55 :param fp: A file opened for writing text. Should use the UTF-856 encoding to be valid JSON.57 :param kwargs: Arguments passed to the ``dump`` implementation.58 59+ .. versionchanged:: 2.360+ The ``app`` parameter was removed.61+62 .. versionchanged:: 2.263 Calls ``current_app.json.dump``, allowing an app to override64 the behavior.65 148- .. versionchanged:: 2.2149- The ``app`` parameter will be removed in Flask 2.3.150-66 .. versionchanged:: 2.067 Writing to a binary file, and the ``encoding`` argument, will be68 removed in Flask 2.1.69 """155- if app is not None:156- import warnings157-158- warnings.warn(159- "The 'app' parameter is deprecated and will be removed in"160- " Flask 2.3. Call 'app.json.dump' directly instead.",161- DeprecationWarning,162- stacklevel=2,163- )70+ if current_app:71+ current_app.json.dump(obj, fp, **kwargs)72 else:165- app = current_app166-167- if app:168- app.json.dump(obj, fp, **kwargs)169- else:73 kwargs.setdefault("default", _default)74 _json.dump(obj, fp, **kwargs)75 76 174-def loads(s: str | bytes, *, app: Flask | None = None, **kwargs: t.Any) -> t.Any:77+def loads(s: str | bytes, **kwargs: t.Any) -> t.Any:78 """Deserialize data as JSON.79 80 If :data:`~flask.current_app` is available, it will use its81 :meth:`app.json.loads() <flask.json.provider.JSONProvider.loads>`1 unmodified line83 84 :param s: Text or UTF-8 bytes.85 :param kwargs: Arguments passed to the ``loads`` implementation.86 87+ .. versionchanged:: 2.388+ The ``app`` parameter was removed.89+90 .. versionchanged:: 2.291 Calls ``current_app.json.loads``, allowing an app to override92 the behavior.93 188- .. versionchanged:: 2.2189- The ``app`` parameter will be removed in Flask 2.3.190-94 .. versionchanged:: 2.095 ``encoding`` will be removed in Flask 2.1. The data must be a96 string or UTF-8 bytes.97 98 .. versionchanged:: 1.0.399 ``app`` can be passed directly, rather than requiring an app100 context for configuration.101 """199- if app is not None:200- import warnings102+ if current_app:103+ return current_app.json.loads(s, **kwargs)104 202- warnings.warn(203- "The 'app' parameter is deprecated and will be removed in"204- " Flask 2.3. Call 'app.json.loads' directly instead.",205- DeprecationWarning,206- stacklevel=2,207- )208- else:209- app = current_app210-211- if app:212- return app.json.loads(s, **kwargs)213-105 return _json.loads(s, **kwargs)106 107 217-def load(fp: t.IO[t.AnyStr], *, app: Flask | None = None, **kwargs: t.Any) -> t.Any:108+def load(fp: t.IO[t.AnyStr], **kwargs: t.Any) -> t.Any:109 """Deserialize data as JSON read from a file.110 111 If :data:`~flask.current_app` is available, it will use its112 :meth:`app.json.load() <flask.json.provider.JSONProvider.load>`1 unmodified line114 115 :param fp: A file opened for reading text or UTF-8 bytes.116 :param kwargs: Arguments passed to the ``load`` implementation.117 118+ .. versionchanged:: 2.3119+ The ``app`` parameter was removed.120+121 .. versionchanged:: 2.2122 Calls ``current_app.json.load``, allowing an app to override123 the behavior.124 3 unmodified lines128 .. versionchanged:: 2.0129 ``encoding`` will be removed in Flask 2.1. The file must be text130 mode, or binary mode with UTF-8 bytes.131 """238- if app is not None:239- import warnings132+ if current_app:133+ return current_app.json.load(fp, **kwargs)134 241- warnings.warn(242- "The 'app' parameter is deprecated and will be removed in"243- " Flask 2.3. Call 'app.json.load' directly instead.",244- DeprecationWarning,245- stacklevel=2,246- )247- else:248- app = current_app249-250- if app:251- return app.json.load(fp, **kwargs)252-135 return _json.load(fp, **kwargs)136 137 256-def htmlsafe_dumps(obj: t.Any, **kwargs: t.Any) -> str:257- """Serialize an object to a string of JSON with :func:`dumps`, then258- replace HTML-unsafe characters with Unicode escapes and mark the259- result safe with :class:`~markupsafe.Markup`.260-261- This is available in templates as the ``|tojson`` filter.262-263- The returned string is safe to render in HTML documents and264- ``<script>`` tags. The exception is in HTML attributes that are265- double quoted; either use single quotes or the ``|forceescape``266- filter.267-268- .. deprecated:: 2.2269- Will be removed in Flask 2.3. This is built-in to Jinja now.270-271- .. versionchanged:: 2.0272- Uses :func:`jinja2.utils.htmlsafe_json_dumps`. The returned273- value is marked safe by wrapping in :class:`~markupsafe.Markup`.274-275- .. versionchanged:: 0.10276- Single quotes are escaped, making this safe to use in HTML,277- ``<script>`` tags, and single-quoted attributes without further278- escaping.279- """280- import warnings281-282- warnings.warn(283- "'htmlsafe_dumps' is deprecated and will be removed in Flask"284- " 2.3. Use 'jinja2.utils.htmlsafe_json_dumps' instead.",285- DeprecationWarning,286- stacklevel=2,287- )288- return _jinja_htmlsafe_dumps(obj, dumps=dumps, **kwargs)289-290-291-def htmlsafe_dump(obj: t.Any, fp: t.IO[str], **kwargs: t.Any) -> None:292- """Serialize an object to JSON written to a file object, replacing293- HTML-unsafe characters with Unicode escapes. See294- :func:`htmlsafe_dumps` and :func:`dumps`.295-296- .. deprecated:: 2.2297- Will be removed in Flask 2.3.298- """299- import warnings300-301- warnings.warn(302- "'htmlsafe_dump' is deprecated and will be removed in Flask"303- " 2.3. Use 'jinja2.utils.htmlsafe_json_dumps' instead.",304- DeprecationWarning,305- stacklevel=2,306- )307- fp.write(htmlsafe_dumps(obj, **kwargs))308-309-138 def jsonify(*args: t.Any, **kwargs: t.Any) -> Response:139 """Serialize the given arguments as JSON, and return a140 :class:`~flask.Response` object with the ``application/json``141 mimetype. A dict or list returned from a view will be converted to a29 unmodified linesmodified:src/flask/json/provider.py+5 added-99 removed
8 unmodified lines9 from datetime import date10 11 from werkzeug.http import http_date12 13-from ..globals import request14-13 if t.TYPE_CHECKING: # pragma: no cover14 from ..app import Flask15 from ..wrappers import Response16 156 unmodified lines173 174 :param obj: The data to serialize.175 :param kwargs: Passed to :func:`json.dumps`.176 """179- cls = self._app._json_encoder180- bp = self._app.blueprints.get(request.blueprint) if request else None181-182- if bp is not None and bp._json_encoder is not None:183- cls = bp._json_encoder184-185- if cls is not None:186- import warnings187-188- warnings.warn(189- "Setting 'json_encoder' on the app or a blueprint is"190- " deprecated and will be removed in Flask 2.3."191- " Customize 'app.json' instead.",192- DeprecationWarning,193- )194- kwargs.setdefault("cls", cls)195-196- if "default" not in cls.__dict__:197- kwargs.setdefault("default", self.default)198- else:199- kwargs.setdefault("default", self.default)200-201- ensure_ascii = self._app.config["JSON_AS_ASCII"]202- sort_keys = self._app.config["JSON_SORT_KEYS"]203-204- if ensure_ascii is not None:205- import warnings206-207- warnings.warn(208- "The 'JSON_AS_ASCII' config key is deprecated and will"209- " be removed in Flask 2.3. Set 'app.json.ensure_ascii'"210- " instead.",211- DeprecationWarning,212- )213- else:214- ensure_ascii = self.ensure_ascii215-216- if sort_keys is not None:217- import warnings218-219- warnings.warn(220- "The 'JSON_SORT_KEYS' config key is deprecated and will"221- " be removed in Flask 2.3. Set 'app.json.sort_keys'"222- " instead.",223- DeprecationWarning,224- )225- else:226- sort_keys = self.sort_keys227-228- kwargs.setdefault("ensure_ascii", ensure_ascii)229- kwargs.setdefault("sort_keys", sort_keys)177+ kwargs.setdefault("default", self.default)178+ kwargs.setdefault("ensure_ascii", self.ensure_ascii)179+ kwargs.setdefault("sort_keys", self.sort_keys)180 return json.dumps(obj, **kwargs)181 182 def loads(self, s: str | bytes, **kwargs: t.Any) -> t.Any:183 """Deserialize data as JSON from a string or bytes.184 185 :param s: Text or UTF-8 bytes.186 :param kwargs: Passed to :func:`json.loads`.187 """238- cls = self._app._json_decoder239- bp = self._app.blueprints.get(request.blueprint) if request else None240-241- if bp is not None and bp._json_decoder is not None:242- cls = bp._json_decoder243-244- if cls is not None:245- import warnings246-247- warnings.warn(248- "Setting 'json_decoder' on the app or a blueprint is"249- " deprecated and will be removed in Flask 2.3."250- " Customize 'app.json' instead.",251- DeprecationWarning,252- )253- kwargs.setdefault("cls", cls)254-188 return json.loads(s, **kwargs)189 190 def response(self, *args: t.Any, **kwargs: t.Any) -> Response:191 """Serialize the given arguments as JSON, and return a12 unmodified lines204 :param kwargs: Treat as a dict to serialize.205 """206 obj = self._prepare_response_obj(args, kwargs)207 dump_args: t.Dict[str, t.Any] = {}275- pretty = self._app.config["JSONIFY_PRETTYPRINT_REGULAR"]276- mimetype = self._app.config["JSONIFY_MIMETYPE"]208 278- if pretty is not None:279- import warnings280-281- warnings.warn(282- "The 'JSONIFY_PRETTYPRINT_REGULAR' config key is"283- " deprecated and will be removed in Flask 2.3. Set"284- " 'app.json.compact' instead.",285- DeprecationWarning,286- )287- compact: bool | None = not pretty288- else:289- compact = self.compact290-291- if (compact is None and self._app.debug) or compact is False:209+ if (self.compact is None and self._app.debug) or self.compact is False:210 dump_args.setdefault("indent", 2)211 else:212 dump_args.setdefault("separators", (",", ":"))213 296- if mimetype is not None:297- import warnings298-299- warnings.warn(300- "The 'JSONIFY_MIMETYPE' config key is deprecated and"301- " will be removed in Flask 2.3. Set 'app.json.mimetype'"302- " instead.",303- DeprecationWarning,304- )305- else:306- mimetype = self.mimetype307-214 return self._app.response_class(309- f"{self.dumps(obj, **dump_args)}\n", mimetype=mimetype215+ f"{self.dumps(obj, **dump_args)}\n", mimetype=self.mimetype216 )modified:src/flask/__init__.py+2 added-2 removed
49 unmodified lines50 import warnings51 from .globals import __app_ctx_stack52 53 warnings.warn(54- "'_app_ctx_stack' is deprecated and will be removed in Flask 2.3.",54+ "'_app_ctx_stack' is deprecated and will be removed in Flask 2.4.",55 DeprecationWarning,56 stacklevel=2,57 )58 return __app_ctx_stack2 unmodified lines61 import warnings62 from .globals import __request_ctx_stack63 64 warnings.warn(65- "'_request_ctx_stack' is deprecated and will be removed in Flask 2.3.",65+ "'_request_ctx_stack' is deprecated and will be removed in Flask 2.4.",66 DeprecationWarning,67 stacklevel=2,68 )69 return __request_ctx_stack2 unmodified linesmodified:src/flask/app.py+4 added-336 removed
1 import functools2 import inspect3-import json3 import logging4 import os5 import sys6 import typing as t66 unmodified lines73 from .blueprints import Blueprint74 from .testing import FlaskClient75 from .testing import FlaskCliRunner76 78-T_before_first_request = t.TypeVar(79- "T_before_first_request", bound=ft.BeforeFirstRequestCallable80-)77 T_shell_context_processor = t.TypeVar(78 "T_shell_context_processor", bound=ft.ShellContextProcessorCallable79 )80 T_teardown = t.TypeVar("T_teardown", bound=ft.TeardownCallable)188 unmodified lines269 #: This attribute can also be configured from the config with the270 #: :data:`SECRET_KEY` configuration key. Defaults to ``None``.271 secret_key = ConfigAttribute("SECRET_KEY")272 277- @property278- def session_cookie_name(self) -> str:279- """The name of the cookie set by the session interface.280-281- .. deprecated:: 2.2282- Will be removed in Flask 2.3. Use ``app.config["SESSION_COOKIE_NAME"]``283- instead.284- """285- import warnings286-287- warnings.warn(288- "'session_cookie_name' is deprecated and will be removed in Flask 2.3. Use"289- " 'SESSION_COOKIE_NAME' in 'app.config' instead.",290- DeprecationWarning,291- stacklevel=2,292- )293- return self.config["SESSION_COOKIE_NAME"]294-295- @session_cookie_name.setter296- def session_cookie_name(self, value: str) -> None:297- import warnings298-299- warnings.warn(300- "'session_cookie_name' is deprecated and will be removed in Flask 2.3. Use"301- " 'SESSION_COOKIE_NAME' in 'app.config' instead.",302- DeprecationWarning,303- stacklevel=2,304- )305- self.config["SESSION_COOKIE_NAME"] = value306-273 #: A :class:`~datetime.timedelta` which is used to set the expiration274 #: date of a permanent session. The default is 31 days which makes a275 #: permanent session survive for roughly one month.276 #:3 unmodified lines280 permanent_session_lifetime = ConfigAttribute(281 "PERMANENT_SESSION_LIFETIME", get_converter=_make_timedelta282 )283 318- @property319- def send_file_max_age_default(self) -> t.Optional[timedelta]:320- """The default value for ``max_age`` for :func:`~flask.send_file`. The default321- is ``None``, which tells the browser to use conditional requests instead of a322- timed cache.323-324- .. deprecated:: 2.2325- Will be removed in Flask 2.3. Use326- ``app.config["SEND_FILE_MAX_AGE_DEFAULT"]`` instead.327-328- .. versionchanged:: 2.0329- Defaults to ``None`` instead of 12 hours.330- """331- import warnings332-333- warnings.warn(334- "'send_file_max_age_default' is deprecated and will be removed in Flask"335- " 2.3. Use 'SEND_FILE_MAX_AGE_DEFAULT' in 'app.config' instead.",336- DeprecationWarning,337- stacklevel=2,338- )339- return _make_timedelta(self.config["SEND_FILE_MAX_AGE_DEFAULT"])340-341- @send_file_max_age_default.setter342- def send_file_max_age_default(self, value: t.Union[int, timedelta, None]) -> None:343- import warnings344-345- warnings.warn(346- "'send_file_max_age_default' is deprecated and will be removed in Flask"347- " 2.3. Use 'SEND_FILE_MAX_AGE_DEFAULT' in 'app.config' instead.",348- DeprecationWarning,349- stacklevel=2,350- )351- self.config["SEND_FILE_MAX_AGE_DEFAULT"] = _make_timedelta(value)352-353- @property354- def use_x_sendfile(self) -> bool:355- """Enable this to use the ``X-Sendfile`` feature, assuming the server supports356- it, from :func:`~flask.send_file`.357-358- .. deprecated:: 2.2359- Will be removed in Flask 2.3. Use ``app.config["USE_X_SENDFILE"]`` instead.360- """361- import warnings362-363- warnings.warn(364- "'use_x_sendfile' is deprecated and will be removed in Flask 2.3. Use"365- " 'USE_X_SENDFILE' in 'app.config' instead.",366- DeprecationWarning,367- stacklevel=2,368- )369- return self.config["USE_X_SENDFILE"]370-371- @use_x_sendfile.setter372- def use_x_sendfile(self, value: bool) -> None:373- import warnings374-375- warnings.warn(376- "'use_x_sendfile' is deprecated and will be removed in Flask 2.3. Use"377- " 'USE_X_SENDFILE' in 'app.config' instead.",378- DeprecationWarning,379- stacklevel=2,380- )381- self.config["USE_X_SENDFILE"] = value382-383- _json_encoder: t.Union[t.Type[json.JSONEncoder], None] = None384- _json_decoder: t.Union[t.Type[json.JSONDecoder], None] = None385-386- @property # type: ignore[override]387- def json_encoder(self) -> t.Type[json.JSONEncoder]:388- """The JSON encoder class to use. Defaults to389- :class:`~flask.json.JSONEncoder`.390-391- .. deprecated:: 2.2392- Will be removed in Flask 2.3. Customize393- :attr:`json_provider_class` instead.394-395- .. versionadded:: 0.10396- """397- import warnings398-399- warnings.warn(400- "'app.json_encoder' is deprecated and will be removed in Flask 2.3."401- " Customize 'app.json_provider_class' or 'app.json' instead.",402- DeprecationWarning,403- stacklevel=2,404- )405-406- if self._json_encoder is None:407- from . import json408-409- return json.JSONEncoder410-411- return self._json_encoder412-413- @json_encoder.setter414- def json_encoder(self, value: t.Type[json.JSONEncoder]) -> None:415- import warnings416-417- warnings.warn(418- "'app.json_encoder' is deprecated and will be removed in Flask 2.3."419- " Customize 'app.json_provider_class' or 'app.json' instead.",420- DeprecationWarning,421- stacklevel=2,422- )423- self._json_encoder = value424-425- @property # type: ignore[override]426- def json_decoder(self) -> t.Type[json.JSONDecoder]:427- """The JSON decoder class to use. Defaults to428- :class:`~flask.json.JSONDecoder`.429-430- .. deprecated:: 2.2431- Will be removed in Flask 2.3. Customize432- :attr:`json_provider_class` instead.433-434- .. versionadded:: 0.10435- """436- import warnings437-438- warnings.warn(439- "'app.json_decoder' is deprecated and will be removed in Flask 2.3."440- " Customize 'app.json_provider_class' or 'app.json' instead.",441- DeprecationWarning,442- stacklevel=2,443- )444-445- if self._json_decoder is None:446- from . import json447-448- return json.JSONDecoder449-450- return self._json_decoder451-452- @json_decoder.setter453- def json_decoder(self, value: t.Type[json.JSONDecoder]) -> None:454- import warnings455-456- warnings.warn(457- "'app.json_decoder' is deprecated and will be removed in Flask 2.3."458- " Customize 'app.json_provider_class' or 'app.json' instead.",459- DeprecationWarning,460- stacklevel=2,461- )462- self._json_decoder = value463-284 json_provider_class: t.Type[JSONProvider] = DefaultJSONProvider285 """A subclass of :class:`~flask.json.provider.JSONProvider`. An286 instance is created and assigned to :attr:`app.json` when creating287 the app.18 unmodified lines306 307 #: Default configuration parameters.308 default_config = ImmutableDict(309 {490- "ENV": None,310 "DEBUG": None,311 "TESTING": False,312 "PROPAGATE_EXCEPTIONS": None,313 "SECRET_KEY": None,13 unmodified lines327 "TRAP_BAD_REQUEST_ERRORS": None,328 "TRAP_HTTP_EXCEPTIONS": False,329 "EXPLAIN_TEMPLATE_LOADING": False,330 "PREFERRED_URL_SCHEME": "http",512- "JSON_AS_ASCII": None,513- "JSON_SORT_KEYS": None,514- "JSONIFY_PRETTYPRINT_REGULAR": None,515- "JSONIFY_MIMETYPE": None,331 "TEMPLATES_AUTO_RELOAD": None,332 "MAX_COOKIE_SIZE": 4093,333 }334 )104 unmodified lines439 self.url_build_error_handlers: t.List[440 t.Callable[[Exception, str, t.Dict[str, t.Any]], str]441 ] = []442 628- #: A list of functions that will be called at the beginning of the629- #: first request to this instance. To register a function, use the630- #: :meth:`before_first_request` decorator.631- #:632- #: .. deprecated:: 2.2633- #: Will be removed in Flask 2.3. Run setup code when634- #: creating the application instead.635- #:636- #: .. versionadded:: 0.8637- self.before_first_request_funcs: t.List[ft.BeforeFirstRequestCallable] = []638-443 #: A list of functions that are called when the application context444 #: is destroyed. Since the application context is also torn down445 #: if the request ends this is the place to store code that disconnects446 #: from databases.102 unmodified lines549 return "__main__"550 return os.path.splitext(os.path.basename(fn))[0]551 return self.import_name552 749- @property750- def propagate_exceptions(self) -> bool:751- """Returns the value of the ``PROPAGATE_EXCEPTIONS`` configuration752- value in case it's set, otherwise a sensible default is returned.753-754- .. deprecated:: 2.2755- Will be removed in Flask 2.3.756-757- .. versionadded:: 0.7758- """759- import warnings760-761- warnings.warn(762- "'propagate_exceptions' is deprecated and will be removed in Flask 2.3.",763- DeprecationWarning,764- stacklevel=2,765- )766- rv = self.config["PROPAGATE_EXCEPTIONS"]767- if rv is not None:768- return rv769- return self.testing or self.debug770-553 @locked_cached_property554 def logger(self) -> logging.Logger:555 """A standard Python :class:`~logging.Logger` for the app, with556 the same name as :attr:`name`.51 unmodified lines608 root_path = self.root_path609 if instance_relative:610 root_path = self.instance_path611 defaults = dict(self.default_config)830- defaults["ENV"] = os.environ.get("FLASK_ENV") or "production"612 defaults["DEBUG"] = get_debug_flag()613 return self.config_class(root_path, defaults)614 615 def make_aborter(self) -> Aborter:32 unmodified lines648 :param mode: resource file opening mode, default is 'rb'.649 """650 return open(os.path.join(self.instance_path, resource), mode)651 871- @property872- def templates_auto_reload(self) -> bool:873- """Reload templates when they are changed. Used by874- :meth:`create_jinja_environment`. It is enabled by default in debug mode.875-876- .. deprecated:: 2.2877- Will be removed in Flask 2.3. Use ``app.config["TEMPLATES_AUTO_RELOAD"]``878- instead.879-880- .. versionadded:: 1.0881- This property was added but the underlying config and behavior882- already existed.883- """884- import warnings885-886- warnings.warn(887- "'templates_auto_reload' is deprecated and will be removed in Flask 2.3."888- " Use 'TEMPLATES_AUTO_RELOAD' in 'app.config' instead.",889- DeprecationWarning,890- stacklevel=2,891- )892- rv = self.config["TEMPLATES_AUTO_RELOAD"]893- return rv if rv is not None else self.debug894-895- @templates_auto_reload.setter896- def templates_auto_reload(self, value: bool) -> None:897- import warnings898-899- warnings.warn(900- "'templates_auto_reload' is deprecated and will be removed in Flask 2.3."901- " Use 'TEMPLATES_AUTO_RELOAD' in 'app.config' instead.",902- DeprecationWarning,903- stacklevel=2,904- )905- self.config["TEMPLATES_AUTO_RELOAD"] = value906-652 def create_jinja_environment(self) -> Environment:653 """Create the Jinja environment based on :attr:`jinja_options`654 and the various Jinja-related methods of the app. Changing655 :attr:`jinja_options` after this will have no effect. Also adds99 unmodified lines755 rv.update(processor())756 return rv757 758 @property1014- def env(self) -> str:1015- """What environment the app is running in. This maps to the :data:`ENV` config1016- key.1017-1018- **Do not enable development when deploying in production.**1019-1020- Default: ``'production'``1021-1022- .. deprecated:: 2.21023- Will be removed in Flask 2.3.1024- """1025- import warnings1026-1027- warnings.warn(1028- "'app.env' is deprecated and will be removed in Flask 2.3."1029- " Use 'app.debug' instead.",1030- DeprecationWarning,1031- stacklevel=2,1032- )1033- return self.config["ENV"]1034-1035- @env.setter1036- def env(self, value: str) -> None:1037- import warnings1038-1039- warnings.warn(1040- "'app.env' is deprecated and will be removed in Flask 2.3."1041- " Use 'app.debug' instead.",1042- DeprecationWarning,1043- stacklevel=2,1044- )1045- self.config["ENV"] = value1046-1047- @property759 def debug(self) -> bool:760 """Whether debug mode is enabled. When using ``flask run`` to start the761 development server, an interactive debugger will be shown for unhandled762 exceptions, and the server will be reloaded when code changes. This maps to the91 unmodified lines854 855 if get_load_dotenv(load_dotenv):856 cli.load_dotenv()857 1147- # if set, let env vars override previous values1148- if "FLASK_ENV" in os.environ:1149- print(1150- "'FLASK_ENV' is deprecated and will not be used in"1151- " Flask 2.3. Use 'FLASK_DEBUG' instead.",1152- file=sys.stderr,1153- )1154- self.config["ENV"] = os.environ.get("FLASK_ENV") or "production"858+ # if set, env var overrides existing value859+ if "FLASK_DEBUG" in os.environ:860 self.debug = get_debug_flag()1156- elif "FLASK_DEBUG" in os.environ:1157- self.debug = get_debug_flag()861 862 # debug passed to method overrides all other sources863 if debug is not None:864 self.debug = bool(debug)317 unmodified lines1182 """1183 self.jinja_env.globals[name or f.__name__] = f1184 1185 @setupmethod1483- def before_first_request(self, f: T_before_first_request) -> T_before_first_request:1484- """Registers a function to be run before the first request to this1485- instance of the application.1486-1487- The function will be called without any arguments and its return1488- value is ignored.1489-1490- .. deprecated:: 2.21491- Will be removed in Flask 2.3. Run setup code when creating1492- the application instead.1493-1494- .. versionadded:: 0.81495- """1496- import warnings1497-1498- warnings.warn(1499- "'before_first_request' is deprecated and will be removed"1500- " in Flask 2.3. Run setup code while creating the"1501- " application instead.",1502- DeprecationWarning,1503- stacklevel=2,1504- )1505- self.before_first_request_funcs.append(f)1506- return f1507-1508- @setupmethod1186 def teardown_appcontext(self, f: T_teardown) -> T_teardown:1187 """Registers a function to be called when the application1188 context is popped. The application context is typically popped1189 after the request context for each request, at the end of CLI168 unmodified lines1358 This always causes a 500 ``InternalServerError``.1359 1360 Always sends the :data:`got_request_exception` signal.1361 1685- If :attr:`propagate_exceptions` is ``True``, such as in debug1362+ If :data:`PROPAGATE_EXCEPTIONS` is ``True``, such as in debug1363 mode, the error will be re-raised so that the debugger can1364 display it. Otherwise, the original exception is logged, and1365 an :exc:`~werkzeug.exceptions.InternalServerError` is returned.1366 114 unmodified lines1481 error handling.1482 1483 .. versionadded:: 0.71484 """1808- # Run before_first_request functions if this is the thread's first request.1809- # Inlined to avoid a method call on subsequent requests.1810- # This is deprecated, will be removed in Flask 2.3.1811- if not self._got_first_request:1812- with self._before_request_lock:1813- if not self._got_first_request:1814- for func in self.before_first_request_funcs:1815- self.ensure_sync(func)()1485+ self._got_first_request = True1486 1817- self._got_first_request = True1818-1487 try:1488 request_started.send(self)1489 rv = self.preprocess_request()1490 if rv is None:729 unmodified linesmodified:src/flask/blueprints.py+4 added-102 removed
1-import json1 import os2 import typing as t3 from collections import defaultdict4 from functools import update_wrapper8 unmodified lines13 from .app import Flask14 15 DeferredSetupFunction = t.Callable[["BlueprintSetupState"], t.Callable]16 T_after_request = t.TypeVar("T_after_request", bound=ft.AfterRequestCallable)18-T_before_first_request = t.TypeVar(19- "T_before_first_request", bound=ft.BeforeFirstRequestCallable20-)17 T_before_request = t.TypeVar("T_before_request", bound=ft.BeforeRequestCallable)18 T_error_handler = t.TypeVar("T_error_handler", bound=ft.ErrorHandlerCallable)19 T_teardown = t.TypeVar("T_teardown", bound=ft.TeardownCallable)20 T_template_context_processor = t.TypeVar(147 unmodified lines168 """169 170 _got_registered_once = False171 176- _json_encoder: t.Union[t.Type[json.JSONEncoder], None] = None177- _json_decoder: t.Union[t.Type[json.JSONDecoder], None] = None178-179- @property180- def json_encoder(181- self,182- ) -> t.Union[t.Type[json.JSONEncoder], None]:183- """Blueprint-local JSON encoder class to use. Set to ``None`` to use the app's.184-185- .. deprecated:: 2.2186- Will be removed in Flask 2.3. Customize187- :attr:`json_provider_class` instead.188-189- .. versionadded:: 0.10190- """191- import warnings192-193- warnings.warn(194- "'bp.json_encoder' is deprecated and will be removed in Flask 2.3."195- " Customize 'app.json_provider_class' or 'app.json' instead.",196- DeprecationWarning,197- stacklevel=2,198- )199- return self._json_encoder200-201- @json_encoder.setter202- def json_encoder(self, value: t.Union[t.Type[json.JSONEncoder], None]) -> None:203- import warnings204-205- warnings.warn(206- "'bp.json_encoder' is deprecated and will be removed in Flask 2.3."207- " Customize 'app.json_provider_class' or 'app.json' instead.",208- DeprecationWarning,209- stacklevel=2,210- )211- self._json_encoder = value212-213- @property214- def json_decoder(215- self,216- ) -> t.Union[t.Type[json.JSONDecoder], None]:217- """Blueprint-local JSON decoder class to use. Set to ``None`` to use the app's.218-219- .. deprecated:: 2.2220- Will be removed in Flask 2.3. Customize221- :attr:`json_provider_class` instead.222-223- .. versionadded:: 0.10224- """225- import warnings226-227- warnings.warn(228- "'bp.json_decoder' is deprecated and will be removed in Flask 2.3."229- " Customize 'app.json_provider_class' or 'app.json' instead.",230- DeprecationWarning,231- stacklevel=2,232- )233- return self._json_decoder234-235- @json_decoder.setter236- def json_decoder(self, value: t.Union[t.Type[json.JSONDecoder], None]) -> None:237- import warnings238-239- warnings.warn(240- "'bp.json_decoder' is deprecated and will be removed in Flask 2.3."241- " Customize 'app.json_provider_class' or 'app.json' instead.",242- DeprecationWarning,243- stacklevel=2,244- )245- self._json_decoder = value246-172 def __init__(173 self,174 name: str,175 import_name: str,109 unmodified lines285 286 .. versionchanged:: 2.3287 Nested blueprints now correctly apply subdomains.288 289+ .. versionchanged:: 2.1290+ Registering the same blueprint with the same name multiple291+ times is an error.292+293 .. versionchanged:: 2.0.1294 Nested blueprints are registered with their dotted name.295 This allows different blueprints with the same name to be296 nested at different locations.2 unmodified lines299 The ``name`` option can be used to change the (pre-dotted)300 name the blueprint is registered with. This allows the same301 blueprint to be registered multiple times with unique names302 for ``url_for``.374-375- .. versionchanged:: 2.0.1376- Registering the same blueprint with the same name multiple377- times is deprecated and will become an error in Flask 2.1.303 """304 name_prefix = options.get("name_prefix", "")305 self_name = options.get("name", self.name)306 name = f"{name_prefix}.{self_name}".lstrip(".")252 unmodified lines559 )560 return f561 562 @setupmethod638- def before_app_first_request(639- self, f: T_before_first_request640- ) -> T_before_first_request:641- """Register a function to run before the first request to the application is642- handled by the worker. Equivalent to :meth:`.Flask.before_first_request`.643-644- .. deprecated:: 2.2645- Will be removed in Flask 2.3. Run setup code when creating646- the application instead.647- """648- import warnings649-650- warnings.warn(651- "'before_app_first_request' is deprecated and will be"652- " removed in Flask 2.3. Use 'record_once' instead to run"653- " setup code when registering the blueprint.",654- DeprecationWarning,655- stacklevel=2,656- )657- self.record_once(lambda s: s.app.before_first_request_funcs.append(f))658- return f659-660- @setupmethod563 def after_app_request(self, f: T_after_request) -> T_after_request:564 """Like :meth:`after_request`, but after every request, not only those handled565 by the blueprint. Equivalent to :meth:`.Flask.after_request`.566 """62 unmodified linesmodified:src/flask/globals.py+8 added-21 removed
15 unmodified lines16 def __init__(self, name: str, cv: ContextVar[t.Any]) -> None:17 self.name = name18 self.cv = cv19 20- def _warn(self):20+ @property21+ def top(self) -> t.Optional[t.Any]:22 import warnings23 24 warnings.warn(24- f"'_{self.name}_ctx_stack' is deprecated and will be"25- " removed in Flask 2.3. Use 'g' to store data, or"26- f" '{self.name}_ctx' to access the current context.",25+ f"'_{self.name}_ctx_stack' is deprecated and will be removed in Flask 2.4."26+ f" Use 'g' to store data, or '{self.name}_ctx' to access the current"27+ " context.",28 DeprecationWarning,28- stacklevel=3,29+ stacklevel=2,30 )30-31- def push(self, obj: t.Any) -> None:32- self._warn()33- self.cv.set(obj)34-35- def pop(self) -> t.Any:36- self._warn()37- ctx = self.cv.get(None)38- self.cv.set(None)39- return ctx40-41- @property42- def top(self) -> t.Optional[t.Any]:43- self._warn()31 return self.cv.get(None)32 33 34 _no_app_msg = """\39 unmodified lines74 if name == "_app_ctx_stack":75 import warnings76 77 warnings.warn(91- "'_app_ctx_stack' is deprecated and will be removed in Flask 2.3.",78+ "'_app_ctx_stack' is deprecated and will be removed in Flask 2.4.",79 DeprecationWarning,80 stacklevel=2,81 )82 return __app_ctx_stack1 unmodified line84 if name == "_request_ctx_stack":85 import warnings86 87 warnings.warn(101- "'_request_ctx_stack' is deprecated and will be removed in Flask 2.3.",88+ "'_request_ctx_stack' is deprecated and will be removed in Flask 2.4.",89 DeprecationWarning,90 stacklevel=2,91 )92 return __request_ctx_stack2 unmodified linesmodified:src/flask/helpers.py+1 added-34 removed
23 unmodified lines24 from .wrappers import Response25 import typing_extensions as te26 27 28-def get_env() -> str:29- """Get the environment the app is running in, indicated by the30- :envvar:`FLASK_ENV` environment variable. The default is31- ``'production'``.32-33- .. deprecated:: 2.234- Will be removed in Flask 2.3.35- """36- import warnings37-38- warnings.warn(39- "'FLASK_ENV' and 'get_env' are deprecated and will be removed"40- " in Flask 2.3. Use 'FLASK_DEBUG' instead.",41- DeprecationWarning,42- stacklevel=2,43- )44- return os.environ.get("FLASK_ENV") or "production"45-46-28 def get_debug_flag() -> bool:29 """Get whether debug mode should be enabled for the app, indicated by the30 :envvar:`FLASK_DEBUG` environment variable. The default is ``False``.31 """32 val = os.environ.get("FLASK_DEBUG")33+ return bool(val and val.lower() not in {"0", "false", "no"})34 53- if not val:54- env = os.environ.get("FLASK_ENV")35 56- if env is not None:57- print(58- "'FLASK_ENV' is deprecated and will not be used in"59- " Flask 2.3. Use 'FLASK_DEBUG' instead.",60- file=sys.stderr,61- )62- return env == "development"63-64- return False65-66- return val.lower() not in {"0", "false", "no"}67-68-36 def get_load_dotenv(default: bool = True) -> bool:37 """Get whether the user has disabled loading default dotenv files by38 setting :envvar:`FLASK_SKIP_DOTENV`. The default is ``True``, load39 the files.633 unmodified linesmodified:src/flask/scaffold.py-15 removed
1 import importlib.util2-import json2 import os3 import pathlib4 import pkgutil5 import sys66 unmodified lines72 name: str73 _static_folder: t.Optional[str] = None74 _static_url_path: t.Optional[str] = None75 77- #: JSON encoder class used by :func:`flask.json.dumps`. If a78- #: blueprint sets this, it will be used instead of the app's value.79- #:80- #: .. deprecated:: 2.281- #: Will be removed in Flask 2.3.82- json_encoder: t.Union[t.Type[json.JSONEncoder], None] = None83-84- #: JSON decoder class used by :func:`flask.json.loads`. If a85- #: blueprint sets this, it will be used instead of the app's value.86- #:87- #: .. deprecated:: 2.288- #: Will be removed in Flask 2.3.89- json_decoder: t.Union[t.Type[json.JSONDecoder], None] = None90-76 def __init__(77 self,78 import_name: str,79 static_folder: t.Optional[t.Union[str, os.PathLike]] = None,842 unmodified linesmodified:tests/conftest.py-1 removed
18 unmodified lines19 mp = monkeypatch.MonkeyPatch()20 out = (21 (os.environ, "FLASK_ENV_FILE", monkeypatch.notset),22 (os.environ, "FLASK_APP", monkeypatch.notset),23- (os.environ, "FLASK_ENV", monkeypatch.notset),23 (os.environ, "FLASK_DEBUG", monkeypatch.notset),24 (os.environ, "FLASK_RUN_FROM_CLI", monkeypatch.notset),25 (os.environ, "WERKZEUG_RUN_MAIN", monkeypatch.notset),26 )172 unmodified linesmodified:tests/test_async.py-9 removed
93 unmodified lines94 assert response.status_code == 41295 96 97 def test_async_before_after_request():98- app_first_called = False98 app_before_called = False99 app_after_called = False100 bp_before_called = False101 bp_after_called = False3 unmodified lines105 @app.route("/")106 def index():107 return ""108 110- with pytest.deprecated_call():111-112- @app.before_first_request113- async def before_first():114- nonlocal app_first_called115- app_first_called = True116-109 @app.before_request110 async def before():111 nonlocal app_before_called112 app_before_called = True24 unmodified lines137 app.register_blueprint(blueprint, url_prefix="/bp")138 139 test_client = app.test_client()140 test_client.get("/")149- assert app_first_called141 assert app_before_called142 assert app_after_called143 test_client.get("/bp/")144 assert bp_before_called1 unmodified linemodified:tests/test_basic.py-39 removed
1 import gc2 import re3-import time3 import uuid4 import warnings5 import weakref6 from datetime import datetime7 from datetime import timezone8 from platform import python_implementation10-from threading import Thread9 10 import pytest11 import werkzeug.serving12 from werkzeug.exceptions import BadRequest1651 unmodified lines1664 1665 assert "setup method 'add_url_rule'" in str(exc_info.value)1666 1667 1670-def test_before_first_request_functions(app, client):1671- got = []1672-1673- with pytest.deprecated_call():1674-1675- @app.before_first_request1676- def foo():1677- got.append(42)1678-1679- client.get("/")1680- assert got == [42]1681- client.get("/")1682- assert got == [42]1683- assert app.got_first_request1684-1685-1686-def test_before_first_request_functions_concurrent(app, client):1687- got = []1688-1689- with pytest.deprecated_call():1690-1691- @app.before_first_request1692- def foo():1693- time.sleep(0.2)1694- got.append(42)1695-1696- def get_and_assert():1697- client.get("/")1698- assert got == [42]1699-1700- t = Thread(target=get_and_assert)1701- t.start()1702- get_and_assert()1703- t.join()1704- assert app.got_first_request1705-1706-1668 def test_routing_redirect_debugging(monkeypatch, app, client):1669 app.config["DEBUG"] = True1670 1671 @app.route("/user/", methods=["GET", "POST"])248 unmodified linesmodified:tests/test_blueprints.py+2 added-8 removed
720 unmodified lines721 def test_app_request_processing(app, client):722 bp = flask.Blueprint("bp", __name__)723 evts = []724 725- with pytest.deprecated_call():726-727- @bp.before_app_first_request728- def before_first_request():729- evts.append("first")730-725 @bp.before_app_request726 def before_app():727 evts.append("before")728 19 unmodified lines748 749 # first request750 resp = client.get("/").data751 assert resp == b"request|after"758- assert evts == ["first", "before", "after", "teardown"]752+ assert evts == ["before", "after", "teardown"]753 754 # second request755 resp = client.get("/").data756 assert resp == b"request|after"763- assert evts == ["first"] + ["before", "after", "teardown"] * 2757+ assert evts == ["before", "after", "teardown"] * 2758 759 760 def test_app_url_processors(app, client):761 bp = flask.Blueprint("bp", __name__)287 unmodified linesmodified:tests/test_helpers.py+8 added-14 removed
300 unmodified lines301 302 303 class TestHelpers:304 @pytest.mark.parametrize(305- "debug, expected_flag, expected_default_flag",305+ ("debug", "expect"),306 [307- ("", False, False),308- ("0", False, False),309- ("False", False, False),310- ("No", False, False),311- ("True", True, True),307+ ("", False),308+ ("0", False),309+ ("False", False),310+ ("No", False),311+ ("True", True),312 ],313 )314- def test_get_debug_flag(315- self, monkeypatch, debug, expected_flag, expected_default_flag316- ):314+ def test_get_debug_flag(self, monkeypatch, debug, expect):315 monkeypatch.setenv("FLASK_DEBUG", debug)318- if expected_flag is None:319- assert get_debug_flag() is None320- else:321- assert get_debug_flag() == expected_flag316+ assert get_debug_flag() == expect322- assert get_debug_flag() == expected_default_flag317 318 def test_make_response(self):319 app = flask.Flask(__name__)320 with app.test_request_context():22 unmodified linesmodified:CHANGES.rst+18 added
1 unmodified line2 -------------3 4 Unreleased5 6+- Remove previously deprecated code. :pr:`4995`7+8+ - The ``push`` and ``pop`` methods of the deprecated ``_app_ctx_stack`` and9+ ``_request_ctx_stack`` objects are removed. ``top`` still exists to give10+ extensions more time to update, but it will be removed.11+ - The ``FLASK_ENV`` environment variable, ``ENV`` config key, and ``app.env``12+ property are removed.13+ - The ``session_cookie_name``, ``send_file_max_age_default``, ``use_x_sendfile``,14+ ``propagate_exceptions``, and ``templates_auto_reload`` properties on ``app``15+ are removed.16+ - The ``JSON_AS_ASCII``, ``JSON_SORT_KEYS``, ``JSONIFY_MIMETYPE``, and17+ ``JSONIFY_PRETTYPRINT_REGULAR`` config keys are removed.18+ - The ``app.before_first_request`` and ``bp.before_app_first_request`` decorators19+ are removed.20+ - ``json_encoder`` and ``json_decoder`` attributes on app and blueprint, and the21+ corresponding ``json.JSONEncoder`` and ``JSONDecoder`` classes, are removed.22+ - The ``json.htmlsafe_dumps`` and ``htmlsafe_dump`` functions are removed.23+24 - Use modern packaging metadata with ``pyproject.toml`` instead of ``setup.cfg``.25 :pr:`4947`26 - Ensure subdomains are applied with nested blueprints. :issue:`4834`27 1418 unmodified lines