diff options
Diffstat (limited to 'netlib/http')
-rw-r--r-- | netlib/http/cookies.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/netlib/http/cookies.py b/netlib/http/cookies.py index 90789365..dd0af99c 100644 --- a/netlib/http/cookies.py +++ b/netlib/http/cookies.py @@ -262,23 +262,28 @@ def refresh_set_cookie_header(c, delta): raise ValueError("Invalid Cookie") return ret + def is_expired(cookie_attrs): """ Determines whether a cookie has expired. Returns: boolean """ - expired = False # 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() - expired = exp_ts < now_ts + expires = exp_ts < now_ts # or if Max-Age is 0 - expired = expired or (int(cookie_attrs.get('Max-Age', 1)) == 0) + max_age = False + try: + max_age = int(cookie_attrs.get('Max-Age', 1)) == 0 + except ValueError: + pass - return expired + return expires or max_age |