diff options
| author | Shadab Zafar <dufferzafar0@gmail.com> | 2016-08-08 12:55:58 +0530 | 
|---|---|---|
| committer | Shadab Zafar <dufferzafar0@gmail.com> | 2016-08-15 12:00:23 +0530 | 
| commit | 3caebe7e7369bebb44421177d9b2f4efbf0bc79b (patch) | |
| tree | a0855435f0dacd54a40a2106535bebf55175c81d /netlib/http | |
| parent | 03e61170424bb92199cff22797135498d5ec8ce5 (diff) | |
| download | mitmproxy-3caebe7e7369bebb44421177d9b2f4efbf0bc79b.tar.gz mitmproxy-3caebe7e7369bebb44421177d9b2f4efbf0bc79b.tar.bz2 mitmproxy-3caebe7e7369bebb44421177d9b2f4efbf0bc79b.zip | |
Simplify cookies.is_expired
Diffstat (limited to 'netlib/http')
| -rw-r--r-- | netlib/http/cookies.py | 23 | 
1 files changed, 7 insertions, 16 deletions
| diff --git a/netlib/http/cookies.py b/netlib/http/cookies.py index 7f32eddf..1421d8eb 100644 --- a/netlib/http/cookies.py +++ b/netlib/http/cookies.py @@ -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): | 
