Refactoring

#1029
This commit is contained in:
Jakub Roztocil 2021-02-06 10:58:36 +01:00
parent 1ac8f69651
commit 5414d1853e

View File

@ -109,14 +109,7 @@ def get_expired_cookies(
for attrs in attr_sets for attrs in attr_sets
] ]
# HACK/FIXME: https://github.com/psf/requests/issues/5743 _max_age_to_expires(cookies=cookies, now=now)
for cookie in cookies:
if 'expires' in cookie:
continue
max_age = cookie.get('max-age')
if max_age and max_age.isdigit():
cookie['expires'] = now + float(max_age)
return [ return [
{ {
@ -126,3 +119,18 @@ def get_expired_cookies(
for cookie in cookies for cookie in cookies
if is_expired(expires=cookie.get('expires')) if is_expired(expires=cookie.get('expires'))
] ]
def _max_age_to_expires(cookies, now):
"""
Translate `max-age` into `expires` for Requests to take it into account.
HACK/FIXME: <https://github.com/psf/requests/issues/5743>
"""
for cookie in cookies:
if 'expires' in cookie:
continue
max_age = cookie.get('max-age')
if max_age and max_age.isdigit():
cookie['expires'] = now + float(max_age)