]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #5537: Fix time2isoz() and time2netscape() functions of httplib.cookiejar
authorVictor Stinner <victor.stinner@haypocalc.com>
Mon, 21 Mar 2011 01:38:51 +0000 (02:38 +0100)
committerVictor Stinner <victor.stinner@haypocalc.com>
Mon, 21 Mar 2011 01:38:51 +0000 (02:38 +0100)
for expiration year greater than 2038 on 32-bit systems.

Lib/http/cookiejar.py
Misc/NEWS

index 9b0ee8039cfc402fd9211366f4ffa457a7dd52aa..e7f0b4b321378c68423a07755b4483f7c52bf19a 100644 (file)
@@ -29,6 +29,7 @@ __all__ = ['Cookie', 'CookieJar', 'CookiePolicy', 'DefaultCookiePolicy',
            'FileCookieJar', 'LWPCookieJar', 'LoadError', 'MozillaCookieJar']
 
 import copy
+import datetime
 import re
 import time
 import urllib.parse, urllib.request
@@ -97,10 +98,12 @@ def time2isoz(t=None):
     1994-11-24 08:49:37Z
 
     """
-    if t is None: t = time.time()
-    year, mon, mday, hour, min, sec = time.gmtime(t)[:6]
+    if t is None:
+        dt = datetime.datetime.utcnow()
+    else:
+        dt = datetime.datetime.utcfromtimestamp(t)
     return "%04d-%02d-%02d %02d:%02d:%02dZ" % (
-        year, mon, mday, hour, min, sec)
+        dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second)
 
 def time2netscape(t=None):
     """Return a string representing time in seconds since epoch, t.
@@ -113,10 +116,13 @@ def time2netscape(t=None):
     Wed, DD-Mon-YYYY HH:MM:SS GMT
 
     """
-    if t is None: t = time.time()
-    year, mon, mday, hour, min, sec, wday = time.gmtime(t)[:7]
+    if t is None:
+        dt = datetime.datetime.utcnow()
+    else:
+        dt = datetime.datetime.utcfromtimestamp(t)
     return "%s %02d-%s-%04d %02d:%02d:%02d GMT" % (
-        DAYS[wday], mday, MONTHS[mon-1], year, hour, min, sec)
+        DAYS[dt.weekday()], dt.day, MONTHS[dt.month-1],
+        dt.year, dt.hour, dt.minute, dt.second)
 
 
 UTC_ZONES = {"GMT": None, "UTC": None, "UT": None, "Z": None}
index be44a06ac14bfbcd1ea2003684f4be275b8faea5..90e1ab1a92864b1c94c42c2b1b167b89368ccd79 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -40,6 +40,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #5537: Fix time2isoz() and time2netscape() functions of
+  httplib.cookiejar for expiration year greater than 2038 on 32-bit systems.
+
 - Issue #11459: A ``bufsize`` value of 0 in subprocess.Popen() really creates
   unbuffered pipes, such that select() works properly on them.
 
@@ -64,7 +67,7 @@ Library
 - Issue #11491: dbm.error is no longer raised when dbm.open is called with
   the "n" as the flag argument and the file exists. The behavior matches
   the documentation and general logic.
-   
+
 - Issue #11131: Fix sign of zero in decimal.Decimal plus and minus
   operations when the rounding mode is ROUND_FLOOR.
 
@@ -218,8 +221,8 @@ Library
   OSError exception when The OS had been told to ignore SIGCLD in our process
   or otherwise not wait for exiting child processes.
 
-- Issue #11500: Fixed a bug in the os x proxy bypass code for fully qualified 
-  IP addresses in the proxy exception list. 
+- Issue #11500: Fixed a bug in the os x proxy bypass code for fully qualified
+  IP addresses in the proxy exception list.
 
 Extensions
 ----------