[req cookie] fix remove_cookie expires which was leading to expires computed to 0 in set_cookie and the Cookie class interpret that has no expires. Closes #2154654 oldstable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 19 Jan 2012 12:57:02 +0100
brancholdstable
changeset 8176 eff4fe02ec64
parent 8123 a4e667270dd4
child 8177 e4ab883f07d9
child 8231 1bb43e31032d
[req cookie] fix remove_cookie expires which was leading to expires computed to 0 in set_cookie and the Cookie class interpret that has no expires. Closes #2154654
web/httpcache.py
web/request.py
--- a/web/httpcache.py	Fri Dec 09 12:08:27 2011 +0100
+++ b/web/httpcache.py	Thu Jan 19 12:57:02 2012 +0100
@@ -23,6 +23,7 @@
 from datetime import datetime
 
 # time delta usable to convert localized time to GMT time
+# XXX this become erroneous after a DST transition!!!
 GMTOFFSET = - (datetime.now() - datetime.utcnow())
 
 class NoHTTPCacheManager(object):
--- a/web/request.py	Fri Dec 09 12:08:27 2011 +0100
+++ b/web/request.py	Thu Jan 19 12:57:02 2012 +0100
@@ -543,6 +543,10 @@
             assert expires is None, 'both max age and expires cant be specified'
             expires = maxage + time.time()
         elif expires:
+            # we don't want to handle times before the EPOCH (cause bug on
+            # windows). Also use > and not >= else expires == 0 and Cookie think
+            # that means no expire...
+            assert expires + GMTOFFSET > date(1970, 1, 1)
             expires = timegm((expires + GMTOFFSET).timetuple())
         else:
             expires = None
@@ -557,11 +561,7 @@
             warn('[3.13] remove_cookie now take only a name as argument',
                  DeprecationWarning, stacklevel=2)
             name = bwcompat
-        self.set_cookie(name, '', maxage=0,
-                        # substracting GMTOFFSET because set_cookie
-                        # expects a localtime and we don't want to
-                        # handle times before the EPOCH
-                        expires=date(1970, 1, 1) - GMTOFFSET) 
+        self.set_cookie(name, '', maxage=0, expires=date(2000, 1, 1))
 
     def set_content_type(self, content_type, filename=None, encoding=None):
         """set output content type for this request. An optional filename