1. Matthew Schinckel
  2. werkzeug-main

Commits

mitsuhiko  committed 6440099

fixed a bug in the secure cookie that made server-side expiration
on servers with a local time that was not set to UTC impossible.

  • Participants
  • Parent commits 2f7121e
  • Branches default

Comments (0)

Files changed (3)

File CHANGES

View file
 - fixed a bug with client cookie header parsing being case sensitive.
 - fixed a not-working deprecation warning.
 - fixed package loading for :cls:`SharedDataMiddleware`.
+- fixed a bug in the secure cookie that made server-side expiration
+  on servers with a local time that was not set to UTC impossible.
 
 
 Version 0.5

File werkzeug/_internal.py

View file
     )
 
 
+_timegm = None
+def _date_to_unix(arg):
+    """Converts a timetuple, integer or datetime object into the seconds from
+    epoch in utc.
+    """
+    global _timegm
+    if isinstance(arg, datetime):
+        arg = arg.utctimetuple()
+    elif isinstance(arg, (int, long, float)):
+        return int(arg)
+    if _timegm is None:
+        from calendar import timegm as _timegm
+    return _timegm(arg)
+
+
 class _ExtendedMorsel(Morsel):
     _reserved = {'httponly': 'HttpOnly'}
     _reserved.update(Morsel._reserved)

File werkzeug/contrib/securecookie.py

View file
 from datetime import datetime
 from time import time, mktime, gmtime
 from werkzeug import url_quote_plus, url_unquote_plus
+from werkzeug._internal import _date_to_unix
 from werkzeug.contrib.sessions import ModificationTrackingDict
 
 
         if self.secret_key is None:
             raise RuntimeError('no secret key defined')
         if expires:
-            if isinstance(expires, datetime):
-                expires = expires.utctimetuple()
-            elif isinstance(expires, (int, long, float)):
-                expires = gmtime(expires)
-            self['_expires'] = int(mktime(expires))
+            self['_expires'] = _date_to_unix(expires)
         result = []
         mac = hmac(self.secret_key, None, self.hash_method)
         for key, value in sorted(self.items()):