@@ -99,7 +99,7 @@ def iscoroutinefunction(func: t.Any) -> bool:
99
99
return inspect .iscoroutinefunction (func )
100
100
101
101
102
- def _make_timedelta (value : t .Optional [timedelta ]) -> t .Optional [timedelta ]:
102
+ def _make_timedelta (value : t .Union [timedelta , int , None ]) -> t .Optional [timedelta ]:
103
103
if value is None or isinstance (value , timedelta ):
104
104
return value
105
105
@@ -273,11 +273,35 @@ class Flask(Scaffold):
273
273
#: :data:`SECRET_KEY` configuration key. Defaults to ``None``.
274
274
secret_key = ConfigAttribute ("SECRET_KEY" )
275
275
276
- #: The secure cookie uses this for the name of the session cookie.
277
- #:
278
- #: This attribute can also be configured from the config with the
279
- #: ``SESSION_COOKIE_NAME`` configuration key. Defaults to ``'session'``
280
- session_cookie_name = ConfigAttribute ("SESSION_COOKIE_NAME" )
276
+ @property
277
+ def session_cookie_name (self ) -> str :
278
+ """The name of the cookie set by the session interface.
279
+
280
+ .. deprecated:: 2.2
281
+ Will be removed in Flask 2.3. Use ``app.config["SESSION_COOKIE_NAME"]``
282
+ instead.
283
+ """
284
+ import warnings
285
+
286
+ 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" ]
293
+
294
+ @session_cookie_name .setter
295
+ def session_cookie_name (self , value : str ) -> None :
296
+ import warnings
297
+
298
+ 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" ] = value
281
305
282
306
#: A :class:`~datetime.timedelta` which is used to set the expiration
283
307
#: date of a permanent session. The default is 31 days which makes a
@@ -290,29 +314,70 @@ class Flask(Scaffold):
290
314
"PERMANENT_SESSION_LIFETIME" , get_converter = _make_timedelta
291
315
)
292
316
293
- #: A :class:`~datetime.timedelta` or number of seconds which is used
294
- #: as the default ``max_age`` for :func:`send_file`. The default is
295
- #: ``None``, which tells the browser to use conditional requests
296
- #: instead of a timed cache.
297
- #:
298
- #: Configured with the :data:`SEND_FILE_MAX_AGE_DEFAULT`
299
- #: configuration key.
300
- #:
301
- #: .. versionchanged:: 2.0
302
- #: Defaults to ``None`` instead of 12 hours.
303
- send_file_max_age_default = ConfigAttribute (
304
- "SEND_FILE_MAX_AGE_DEFAULT" , get_converter = _make_timedelta
305
- )
317
+ @property
318
+ def send_file_max_age_default (self ) -> t .Optional [timedelta ]:
319
+ """The default value for ``max_age`` for :func:`~flask.send_file`. The default
320
+ is ``None``, which tells the browser to use conditional requests instead of a
321
+ timed cache.
306
322
307
- #: Enable this if you want to use the X-Sendfile feature. Keep in
308
- #: mind that the server has to support this. This only affects files
309
- #: sent with the :func:`send_file` method.
310
- #:
311
- #: .. versionadded:: 0.2
312
- #:
313
- #: This attribute can also be configured from the config with the
314
- #: ``USE_X_SENDFILE`` configuration key. Defaults to ``False``.
315
- use_x_sendfile = ConfigAttribute ("USE_X_SENDFILE" )
323
+ .. deprecated:: 2.2
324
+ Will be removed in Flask 2.3. Use
325
+ ``app.config["SEND_FILE_MAX_AGE_DEFAULT"]`` instead.
326
+
327
+ .. versionchanged:: 2.0
328
+ Defaults to ``None`` instead of 12 hours.
329
+ """
330
+ import warnings
331
+
332
+ 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" ])
339
+
340
+ @send_file_max_age_default .setter
341
+ def send_file_max_age_default (self , value : t .Union [int , timedelta , None ]) -> None :
342
+ import warnings
343
+
344
+ 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 )
351
+
352
+ @property
353
+ def use_x_sendfile (self ) -> bool :
354
+ """Enable this to use the ``X-Sendfile`` feature, assuming the server supports
355
+ it, from :func:`~flask.send_file`.
356
+
357
+ .. deprecated:: 2.2
358
+ Will be removed in Flask 2.3. Use ``app.config["USE_X_SENDFILE"]`` instead.
359
+ """
360
+ import warnings
361
+
362
+ 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" ]
369
+
370
+ @use_x_sendfile .setter
371
+ def use_x_sendfile (self , value : bool ) -> None :
372
+ import warnings
373
+
374
+ 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" ] = value
316
381
317
382
#: The JSON encoder class to use. Defaults to
318
383
#: :class:`~flask.json.JSONEncoder`.
@@ -624,8 +689,18 @@ def propagate_exceptions(self) -> bool:
624
689
"""Returns the value of the ``PROPAGATE_EXCEPTIONS`` configuration
625
690
value in case it's set, otherwise a sensible default is returned.
626
691
692
+ .. deprecated:: 2.2
693
+ Will be removed in Flask 2.3.
694
+
627
695
.. versionadded:: 0.7
628
696
"""
697
+ import warnings
698
+
699
+ warnings .warn (
700
+ "'propagate_exceptions' is deprecated and will be removed in Flask 2.3." ,
701
+ DeprecationWarning ,
702
+ stacklevel = 2 ,
703
+ )
629
704
rv = self .config ["PROPAGATE_EXCEPTIONS" ]
630
705
if rv is not None :
631
706
return rv
@@ -734,20 +809,37 @@ def open_instance_resource(self, resource: str, mode: str = "rb") -> t.IO[t.AnyS
734
809
@property
735
810
def templates_auto_reload (self ) -> bool :
736
811
"""Reload templates when they are changed. Used by
737
- :meth:`create_jinja_environment`.
812
+ :meth:`create_jinja_environment`. It is enabled by default in debug mode.
738
813
739
- This attribute can be configured with :data:`TEMPLATES_AUTO_RELOAD`. If
740
- not set, it will be enabled in debug mode.
814
+ .. deprecated:: 2.2
815
+ Will be removed in Flask 2.3. Use ``app.config["TEMPLATES_AUTO_RELOAD"]``
816
+ instead.
741
817
742
818
.. versionadded:: 1.0
743
819
This property was added but the underlying config and behavior
744
820
already existed.
745
821
"""
822
+ import warnings
823
+
824
+ 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
+ )
746
830
rv = self .config ["TEMPLATES_AUTO_RELOAD" ]
747
831
return rv if rv is not None else self .debug
748
832
749
833
@templates_auto_reload .setter
750
834
def templates_auto_reload (self , value : bool ) -> None :
835
+ import warnings
836
+
837
+ 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
+ )
751
843
self .config ["TEMPLATES_AUTO_RELOAD" ] = value
752
844
753
845
def create_jinja_environment (self ) -> Environment :
@@ -768,7 +860,12 @@ def create_jinja_environment(self) -> Environment:
768
860
options ["autoescape" ] = self .select_jinja_autoescape
769
861
770
862
if "auto_reload" not in options :
771
- options ["auto_reload" ] = self .templates_auto_reload
863
+ auto_reload = self .config ["TEMPLATES_AUTO_RELOAD" ]
864
+
865
+ if auto_reload is None :
866
+ auto_reload = self .debug
867
+
868
+ options ["auto_reload" ] = auto_reload
772
869
773
870
rv = self .jinja_environment (self , ** options )
774
871
rv .globals .update (
@@ -898,7 +995,9 @@ def debug(self) -> bool:
898
995
@debug .setter
899
996
def debug (self , value : bool ) -> None :
900
997
self .config ["DEBUG" ] = value
901
- self .jinja_env .auto_reload = self .templates_auto_reload
998
+
999
+ if self .config ["TEMPLATES_AUTO_RELOAD" ] is None :
1000
+ self .jinja_env .auto_reload = value
902
1001
903
1002
def run (
904
1003
self ,
@@ -1541,8 +1640,12 @@ def handle_exception(self, e: Exception) -> Response:
1541
1640
"""
1542
1641
exc_info = sys .exc_info ()
1543
1642
got_request_exception .send (self , exception = e )
1643
+ propagate = self .config ["PROPAGATE_EXCEPTIONS" ]
1644
+
1645
+ if propagate is None :
1646
+ propagate = self .testing or self .debug
1544
1647
1545
- if self . propagate_exceptions :
1648
+ if propagate :
1546
1649
# Re-raise if called with an active exception, otherwise
1547
1650
# raise the passed in exception.
1548
1651
if exc_info [1 ] is e :
0 commit comments