Skip to content
Myr

deprecate config attributes

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 98ca00d · Browse files · 8 files+154 added−57 removed
This commit

State

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

Diff stats

8 files+154 added−57 removed

  • tests:+0 added−11 removed
  • other:+154 added−46 removed

8 files+154 added−57 removed

modified:docs/api.rst+3 added-4 removed
123 unmodified lines
124 :members:125126.. admonition:: Notice127128 The ``PERMANENT_SESSION_LIFETIME`` config key can also be an integer129 starting with Flask 0.8. Either catch this down yourself or use130 the :attr:`~flask.Flask.permanent_session_lifetime` attribute on the131 app which converts the result to an integer automatically.128 The :data:`PERMANENT_SESSION_LIFETIME` config can be an integer or ``timedelta``.129 The :attr:`~flask.Flask.permanent_session_lifetime` attribute is always a130 ``timedelta``.131132133Test Client134-----------
616 unmodified lines
modified:src/flask/app.py+137 added-34 removed
97 unmodified lines
9899 return inspect.iscoroutinefunction(func)100101102def _make_timedelta(value: t.Optional[timedelta]) -> t.Optional[timedelta]:102def _make_timedelta(value: t.Union[timedelta, int, None]) -> t.Optional[timedelta]:103 if value is None or isinstance(value, timedelta):104 return value105106 return timedelta(seconds=value)
165 unmodified lines
272 #: This attribute can also be configured from the config with the273 #: :data:`SECRET_KEY` configuration key. Defaults to ``None``.274 secret_key = ConfigAttribute("SECRET_KEY")275276 #: The secure cookie uses this for the name of the session cookie.277 #:278 #: This attribute can also be configured from the config with the279 #: ``SESSION_COOKIE_NAME`` configuration key. Defaults to ``'session'``280 session_cookie_name = ConfigAttribute("SESSION_COOKIE_NAME")276 @property277 def session_cookie_name(self) -> str:278 """The name of the cookie set by the session interface.279280 .. deprecated:: 2.2281 Will be removed in Flask 2.3. Use ``app.config["SESSION_COOKIE_NAME"]``282 instead.283 """284 import warnings285286 warnings.warn(287 "'session_cookie_name' is deprecated and will be removed in Flask 2.3. Use"288 " 'SESSION_COOKIE_NAME' in 'app.config' instead.",289 DeprecationWarning,290 stacklevel=2,291 )292 return self.config["SESSION_COOKIE_NAME"]293294 @session_cookie_name.setter295 def session_cookie_name(self, value: str) -> None:296 import warnings297298 warnings.warn(299 "'session_cookie_name' is deprecated and will be removed in Flask 2.3. Use"300 " 'SESSION_COOKIE_NAME' in 'app.config' instead.",301 DeprecationWarning,302 stacklevel=2,303 )304 self.config["SESSION_COOKIE_NAME"] = value305306 #: A :class:`~datetime.timedelta` which is used to set the expiration307 #: date of a permanent session. The default is 31 days which makes a308 #: permanent session survive for roughly one month.309 #:
3 unmodified lines
313 permanent_session_lifetime = ConfigAttribute(314 "PERMANENT_SESSION_LIFETIME", get_converter=_make_timedelta315 )316293 #: A :class:`~datetime.timedelta` or number of seconds which is used294 #: as the default ``max_age`` for :func:`send_file`. The default is295 #: ``None``, which tells the browser to use conditional requests296 #: instead of a timed cache.297 #:298 #: Configured with the :data:`SEND_FILE_MAX_AGE_DEFAULT`299 #: configuration key.300 #:301 #: .. versionchanged:: 2.0302 #: Defaults to ``None`` instead of 12 hours.303 send_file_max_age_default = ConfigAttribute(304 "SEND_FILE_MAX_AGE_DEFAULT", get_converter=_make_timedelta305 )317 @property318 def send_file_max_age_default(self) -> t.Optional[timedelta]:319 """The default value for ``max_age`` for :func:`~flask.send_file`. The default320 is ``None``, which tells the browser to use conditional requests instead of a321 timed cache.322307 #: Enable this if you want to use the X-Sendfile feature. Keep in308 #: mind that the server has to support this. This only affects files309 #: sent with the :func:`send_file` method.310 #:311 #: .. versionadded:: 0.2312 #:313 #: This attribute can also be configured from the config with the314 #: ``USE_X_SENDFILE`` configuration key. Defaults to ``False``.315 use_x_sendfile = ConfigAttribute("USE_X_SENDFILE")323 .. deprecated:: 2.2324 Will be removed in Flask 2.3. Use325 ``app.config["SEND_FILE_MAX_AGE_DEFAULT"]`` instead.326327 .. versionchanged:: 2.0328 Defaults to ``None`` instead of 12 hours.329 """330 import warnings331332 warnings.warn(333 "'send_file_max_age_default' is deprecated and will be removed in Flask"334 " 2.3. Use 'SEND_FILE_MAX_AGE_DEFAULT' in 'app.config' instead.",335 DeprecationWarning,336 stacklevel=2,337 )338 return _make_timedelta(self.config["SEND_FILE_MAX_AGE_DEFAULT"])339340 @send_file_max_age_default.setter341 def send_file_max_age_default(self, value: t.Union[int, timedelta, None]) -> None:342 import warnings343344 warnings.warn(345 "'send_file_max_age_default' is deprecated and will be removed in Flask"346 " 2.3. Use 'SEND_FILE_MAX_AGE_DEFAULT' in 'app.config' instead.",347 DeprecationWarning,348 stacklevel=2,349 )350 self.config["SEND_FILE_MAX_AGE_DEFAULT"] = _make_timedelta(value)351352 @property353 def use_x_sendfile(self) -> bool:354 """Enable this to use the ``X-Sendfile`` feature, assuming the server supports355 it, from :func:`~flask.send_file`.356357 .. deprecated:: 2.2358 Will be removed in Flask 2.3. Use ``app.config["USE_X_SENDFILE"]`` instead.359 """360 import warnings361362 warnings.warn(363 "'use_x_sendfile' is deprecated and will be removed in Flask 2.3. Use"364 " 'USE_X_SENDFILE' in 'app.config' instead.",365 DeprecationWarning,366 stacklevel=2,367 )368 return self.config["USE_X_SENDFILE"]369370 @use_x_sendfile.setter371 def use_x_sendfile(self, value: bool) -> None:372 import warnings373374 warnings.warn(375 "'use_x_sendfile' is deprecated and will be removed in Flask 2.3. Use"376 " 'USE_X_SENDFILE' in 'app.config' instead.",377 DeprecationWarning,378 stacklevel=2,379 )380 self.config["USE_X_SENDFILE"] = value381382 #: The JSON encoder class to use. Defaults to383 #: :class:`~flask.json.JSONEncoder`.384 #:385 #: .. deprecated:: 2.2
302 unmodified lines
688 def propagate_exceptions(self) -> bool:689 """Returns the value of the ``PROPAGATE_EXCEPTIONS`` configuration690 value in case it's set, otherwise a sensible default is returned.691692 .. deprecated:: 2.2693 Will be removed in Flask 2.3.694695 .. versionadded:: 0.7696 """697 import warnings698699 warnings.warn(700 "'propagate_exceptions' is deprecated and will be removed in Flask 2.3.",701 DeprecationWarning,702 stacklevel=2,703 )704 rv = self.config["PROPAGATE_EXCEPTIONS"]705 if rv is not None:706 return rv707 return self.testing or self.debug
100 unmodified lines
808809 @property810 def templates_auto_reload(self) -> bool:811 """Reload templates when they are changed. Used by737 :meth:`create_jinja_environment`.812 :meth:`create_jinja_environment`. It is enabled by default in debug mode.813739 This attribute can be configured with :data:`TEMPLATES_AUTO_RELOAD`. If740 not set, it will be enabled in debug mode.814 .. deprecated:: 2.2815 Will be removed in Flask 2.3. Use ``app.config["TEMPLATES_AUTO_RELOAD"]``816 instead.817818 .. versionadded:: 1.0819 This property was added but the underlying config and behavior820 already existed.821 """822 import warnings823824 warnings.warn(825 "'templates_auto_reload' is deprecated and will be removed in Flask 2.3."826 " Use 'TEMPLATES_AUTO_RELOAD' in 'app.config' instead.",827 DeprecationWarning,828 stacklevel=2,829 )830 rv = self.config["TEMPLATES_AUTO_RELOAD"]831 return rv if rv is not None else self.debug832833 @templates_auto_reload.setter834 def templates_auto_reload(self, value: bool) -> None:835 import warnings836837 warnings.warn(838 "'templates_auto_reload' is deprecated and will be removed in Flask 2.3."839 " Use 'TEMPLATES_AUTO_RELOAD' in 'app.config' instead.",840 DeprecationWarning,841 stacklevel=2,842 )843 self.config["TEMPLATES_AUTO_RELOAD"] = value844845 def create_jinja_environment(self) -> Environment:846 """Create the Jinja environment based on :attr:`jinja_options`
12 unmodified lines
859 if "autoescape" not in options:860 options["autoescape"] = self.select_jinja_autoescape861862 if "auto_reload" not in options:771 options["auto_reload"] = self.templates_auto_reload863 auto_reload = self.config["TEMPLATES_AUTO_RELOAD"]864865 if auto_reload is None:866 auto_reload = self.debug867868 options["auto_reload"] = auto_reload869870 rv = self.jinja_environment(self, **options)871 rv.globals.update(872 url_for=self.url_for,873 get_flashed_messages=get_flashed_messages,
120 unmodified lines
994995 @debug.setter996 def debug(self, value: bool) -> None:997 self.config["DEBUG"] = value901 self.jinja_env.auto_reload = self.templates_auto_reload998999 if self.config["TEMPLATES_AUTO_RELOAD"] is None:1000 self.jinja_env.auto_reload = value10011002 def run(1003 self,1004 host: t.Optional[str] = None,1005 port: t.Optional[int] = None,
633 unmodified lines
1639 .. versionadded:: 0.31640 """1641 exc_info = sys.exc_info()1642 got_request_exception.send(self, exception=e)1643 propagate = self.config["PROPAGATE_EXCEPTIONS"]16441545 if self.propagate_exceptions:1645 if propagate is None:1646 propagate = self.testing or self.debug16471648 if propagate:1649 # Re-raise if called with an active exception, otherwise1650 # raise the passed in exception.1651 if exc_info[1] is e:1652 raise
834 unmodified lines
modified:src/flask/helpers.py+1 added-1 removed
412 unmodified lines
413 kwargs["max_age"] = current_app.get_send_file_max_age414415 kwargs.update(416 environ=request.environ,417 use_x_sendfile=current_app.use_x_sendfile,417 use_x_sendfile=current_app.config["USE_X_SENDFILE"],418 response_class=current_app.response_class,419 _root_path=current_app.root_path, # type: ignore420 )421 return kwargs
284 unmodified lines
modified:src/flask/scaffold.py+6 added-2 removed
3 unmodified lines
4import pkgutil5import sys6import typing as t7from collections import defaultdict8from datetime import timedelta9from functools import update_wrapper1011from jinja2 import FileSystemLoader12from werkzeug.exceptions import default_exceptions
289 unmodified lines
302 The default configuration is ``None`` instead of 12 hours.303304 .. versionadded:: 0.9305 """305 value = current_app.send_file_max_age_default306 value = current_app.config["SEND_FILE_MAX_AGE_DEFAULT"]307308 if value is None:309 return None310311 if isinstance(value, timedelta):310 return int(value.total_seconds())312 return int(value.total_seconds())313314 return value315316 def send_static_file(self, filename: str) -> "Response":317 """The view function used to serve files from318 :attr:`static_folder`. A route is automatically registered for319 this view at :attr:`static_url_path` if :attr:`static_folder` is
578 unmodified lines
modified:src/flask/sessions.py+2 added-5 removed
175 unmodified lines
176 """177 return isinstance(obj, self.null_session_class)178179 def get_cookie_name(self, app: "Flask") -> str:180 """Returns the name of the session cookie.180 """The name of the session cookie. Uses``app.config["SESSION_COOKIE_NAME"]``."""181 return app.config["SESSION_COOKIE_NAME"]182182 Uses ``app.session_cookie_name`` which is set to ``SESSION_COOKIE_NAME``183 """184 return app.session_cookie_name185183 def get_cookie_domain(self, app: "Flask") -> t.Optional[str]:184 """Returns the domain that should be set for the session cookie.185186 Uses ``SESSION_COOKIE_DOMAIN`` if it is configured, otherwise
233 unmodified lines
modified:tests/test_config.py-9 removed
1import json2import os3import textwrap4from datetime import timedelta45import pytest67import flask
197 unmodified lines
205 app.config["PERMANENT_SESSION_LIFETIME"] = 42206 assert app.permanent_session_lifetime.seconds == 42207208210def test_send_file_max_age():211 app = flask.Flask(__name__)212 app.config["SEND_FILE_MAX_AGE_DEFAULT"] = 3600213 assert app.send_file_max_age_default.seconds == 3600214 app.config["SEND_FILE_MAX_AGE_DEFAULT"] = timedelta(hours=2)215 assert app.send_file_max_age_default.seconds == 7200216217209def test_get_namespace():210 app = flask.Flask(__name__)211 app.config["FOO_OPTION_1"] = "foo option 1"212 app.config["FOO_OPTION_2"] = "foo option 2"
37 unmodified lines
modified:tests/test_templating.py-2 removed
395 unmodified lines
396397 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)398399 app.run()400 assert not app.templates_auto_reload400 assert not app.jinja_env.auto_reload401402 app.run(debug=True)404 assert app.templates_auto_reload403 assert app.jinja_env.auto_reload404405406def test_template_loader_debugging(test_apps, monkeypatch):
44 unmodified lines
modified:CHANGES.rst+5 added
25 unmodified lines
26- The ``FLASK_ENV`` environment variable and ``app.env`` attribute are27 deprecated, removing the distinction between development and debug28 mode. Debug mode should be controlled directly using the ``--debug``29 option or ``app.run(debug=True)``. :issue:`4714`30- Some attributes that proxied config keys on ``app`` are deprecated:31 ``session_cookie_name``, ``send_file_max_age_default``,32 ``use_x_sendfile``, ``propagate_exceptions``, and33 ``templates_auto_reload``. Use the relevant config keys instead.34 :issue:`4716`35- Add new customization points to the ``Flask`` app object for many36 previously global behaviors.3738 - ``flask.url_for`` will call ``app.url_for``. :issue:`4568`
1348 unmodified lines