Skip to content

Commit

Permalink
Simplify cookies.is_expired
Browse files Browse the repository at this point in the history
  • Loading branch information
dufferzafar committed Aug 8, 2016
1 parent ce0a564 commit ec54180
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions netlib/http/cookies.py
Expand Up @@ -302,23 +302,14 @@ def is_expired(cookie_attrs):
Returns: boolean
"""

# See if 'expires' time is in the past
expires = False
if 'expires' in cookie_attrs:
e = email.utils.parsedate_tz(cookie_attrs["expires"])
if e:
exp_ts = email.utils.mktime_tz(e)
now_ts = time.time()
expires = exp_ts < now_ts

# or if Max-Age is 0
max_age = False
try:
max_age = int(cookie_attrs.get('Max-Age', 1)) == 0
except ValueError:
pass
exp_ts = get_expiration_ts(cookie_attrs)
now_ts = time.time()

return expires or max_age
# If no expiration information was provided with the cookie
if exp_ts is None:
return False
else:
return exp_ts <= now_ts


def group_cookies(pairs):
Expand Down

0 comments on commit ec54180

Please sign in to comment.