[http, windows] fix remove_cookie trying to expire a cookie before the Epoch (closes: #2087998) stable
authorAlexandre Fayolle <alexandre.fayolle@logilab.fr>
Thu, 10 Nov 2011 23:18:56 +0100
branchstable
changeset 8081 e8091b415ad8
parent 8063 1b2a05c9b71c
child 8082 1c37783ff610
child 8085 51929d531aff
[http, windows] fix remove_cookie trying to expire a cookie before the Epoch (closes: #2087998) time.gmtime on windows will raise a ValueError if a negative argument is supplied
web/http_headers.py
web/request.py
--- a/web/http_headers.py	Mon Nov 07 18:08:40 2011 +0100
+++ b/web/http_headers.py	Thu Nov 10 23:18:56 2011 +0100
@@ -744,7 +744,8 @@
 
 def generateDateTime(secSinceEpoch):
     """Convert seconds since epoch to HTTP datetime string."""
-    year, month, day, hh, mm, ss, wd, y, z = time.gmtime(secSinceEpoch)
+    # take care gmtime doesn't handle time before epoch (crash on windows at least)
+    year, month, day, hh, mm, ss, wd, y, z = time.gmtime(max(0, secSinceEpoch))
     s = "%s, %02d %3s %4d %02d:%02d:%02d GMT" % (
         weekdayname[wd],
         day, monthname[month], year,
--- a/web/request.py	Mon Nov 07 18:08:40 2011 +0100
+++ b/web/request.py	Thu Nov 10 23:18:56 2011 +0100
@@ -557,7 +557,11 @@
             warn('[3.13] remove_cookie now take only a name as argument',
                  DeprecationWarning, stacklevel=2)
             name = bwcompat
-        self.set_cookie(name, '', maxage=0, expires=date(1970, 1, 1))
+        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) 
 
     def set_content_type(self, content_type, filename=None, encoding=None):
         """set output content type for this request. An optional filename