[web] kill GMTOFFSET (closes #2154655)
authorJulien Cristau <julien.cristau@logilab.fr>
Mon, 16 Mar 2015 16:46:34 +0100
changeset 10305 937deb71a681
parent 10304 b6c55274135a
child 10306 ea73a949e802
[web] kill GMTOFFSET (closes #2154655) Its last user, set_cookie(expires=...), can just as well interpret its argument as UTC. Naïve datetime objects with an implicit non-UTC timezone are just awful.
doc/3.21.rst
web/httpcache.py
web/request.py
--- a/doc/3.21.rst	Thu Mar 26 08:34:47 2015 +0100
+++ b/doc/3.21.rst	Mon Mar 16 16:46:34 2015 +0100
@@ -9,6 +9,14 @@
 
 .. _cube: https://www.cubicweb.org/project/cubicweb-timeline
 
+API changes
+-----------
+
+* req.set_cookie's "expires" argument, if not None, is expected to be a
+  date or a datetime in UTC.  It was previously interpreted as localtime
+  with the UTC offset the server started in, which was inconsistent (we
+  are not aware of any users of that API).
+
 Deprecated code drops
 ---------------------
 
--- a/web/httpcache.py	Thu Mar 26 08:34:47 2015 +0100
+++ b/web/httpcache.py	Mon Mar 16 16:46:34 2015 +0100
@@ -22,10 +22,6 @@
 from time import mktime
 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):
     """default cache manager: set no-cache cache control policy"""
     def __init__(self, view):
--- a/web/request.py	Thu Mar 26 08:34:47 2015 +0100
+++ b/web/request.py	Mon Mar 16 16:46:34 2015 +0100
@@ -45,7 +45,7 @@
 from cubicweb.view import TRANSITIONAL_DOCTYPE_NOEXT
 from cubicweb.web import (INTERNAL_FIELD_VALUE, LOGGER, NothingToEdit,
                           RequestError, StatusResponse)
-from cubicweb.web.httpcache import GMTOFFSET, get_validators
+from cubicweb.web.httpcache import get_validators
 from cubicweb.web.http_headers import Headers, Cookie, parseDateTime
 
 _MARKER = object()
@@ -536,8 +536,8 @@
             # 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())
+            assert expires > date(1970, 1, 1)
+            expires = timegm(expires.timetuple())
         else:
             expires = None
         # make sure cookie is set on the correct path