deprecate total_seconds

This commit is contained in:
David Lord 2021-04-15 23:05:24 -07:00
parent f3ed1322a6
commit 85b430a366
No known key found for this signature in database
GPG Key ID: 7A1C87E3F5BC42A8
3 changed files with 13 additions and 2 deletions

View File

@ -72,6 +72,8 @@ Unreleased
- Support nesting blueprints. :issue:`593, 1548`, :pr:`3923`
- ``flask shell`` sets up tab and history completion like the default
``python`` shell if ``readline`` is installed. :issue:`3941`
- ``helpers.total_seconds()`` is deprecated. Use
``timedelta.total_seconds()`` instead. :pr:`3962`
Version 1.1.2

View File

@ -709,7 +709,17 @@ def total_seconds(td):
:returns: number of seconds
:rtype: int
.. deprecated:: 2.0
Will be removed in Flask 2.1. Use
:meth:`timedelta.total_seconds` instead.
"""
warnings.warn(
"'total_seconds' is deprecated and will be removed in Flask"
" 2.1. Use 'timedelta.total_seconds' instead.",
DeprecationWarning,
stacklevel=2,
)
return td.days * 60 * 60 * 24 + td.seconds

View File

@ -8,7 +8,6 @@ from itsdangerous import URLSafeTimedSerializer
from werkzeug.datastructures import CallbackDict
from .helpers import is_ip
from .helpers import total_seconds
from .json.tag import TaggedJSONSerializer
@ -340,7 +339,7 @@ class SecureCookieSessionInterface(SessionInterface):
val = request.cookies.get(self.get_cookie_name(app))
if not val:
return self.session_class()
max_age = total_seconds(app.permanent_session_lifetime)
max_age = int(app.permanent_session_lifetime.total_seconds())
try:
data = s.loads(val, max_age=max_age)
return self.session_class(data)