Merge pull request #3963 from pallets/deprecate-helpers

deprecate `helpers.total_seconds`
This commit is contained in:
David Lord 2021-04-15 23:18:39 -07:00 committed by GitHub
commit fab26dcbe9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 9 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

@ -18,13 +18,6 @@ from .globals import request
from .globals import session
from .signals import message_flashed
# what separators does this operating system provide that are not a slash?
# this is used by the send_from_directory function to ensure that nobody is
# able to access files from outside the filesystem.
_os_alt_seps = list(
sep for sep in [os.path.sep, os.path.altsep] if sep not in (None, "/")
)
def get_env():
"""Get the environment the app is running in, indicated by the
@ -709,7 +702,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)