[Python-checkins] cpython (merge 3.5 -> default): [merge from 3.5] - Issue #27466: Change time format returned by

senthil.kumaran python-checkins at python.org
Sun Jul 10 09:49:56 EDT 2016


https://hg.python.org/cpython/rev/324ade62c0f0
changeset:   102295:324ade62c0f0
parent:      102293:93ab72de7431
parent:      102294:3356d7c57750
user:        Senthil Kumaran <senthil at uthcode.com>
date:        Sun Jul 10 06:49:49 2016 -0700
summary:
  [merge from 3.5] - Issue #27466: Change time format returned by
http.cookie.time2netscape, confirming the netscape cookie format.

files:
  Lib/http/cookiejar.py           |   2 +-
  Lib/test/test_http_cookiejar.py |  22 +++++++++++++++++++++
  Misc/NEWS                       |   4 +++
  3 files changed, 27 insertions(+), 1 deletions(-)


diff --git a/Lib/http/cookiejar.py b/Lib/http/cookiejar.py
--- a/Lib/http/cookiejar.py
+++ b/Lib/http/cookiejar.py
@@ -120,7 +120,7 @@
         dt = datetime.datetime.utcnow()
     else:
         dt = datetime.datetime.utcfromtimestamp(t)
-    return "%s %02d-%s-%04d %02d:%02d:%02d GMT" % (
+    return "%s, %02d-%s-%04d %02d:%02d:%02d GMT" % (
         DAYS[dt.weekday()], dt.day, MONTHS[dt.month-1],
         dt.year, dt.hour, dt.minute, dt.second)
 
diff --git a/Lib/test/test_http_cookiejar.py b/Lib/test/test_http_cookiejar.py
--- a/Lib/test/test_http_cookiejar.py
+++ b/Lib/test/test_http_cookiejar.py
@@ -31,6 +31,28 @@
             self.assertRegex(text, r"^\d{4}-\d\d-\d\d \d\d:\d\d:\d\dZ$",
                              "bad time2isoz format: %s %s" % (az, bz))
 
+    def test_time2netscape(self):
+        base = 1019227000
+        day = 24*3600
+        self.assertEqual(time2netscape(base), "Fri, 19-Apr-2002 14:36:40 GMT")
+        self.assertEqual(time2netscape(base+day),
+                         "Sat, 20-Apr-2002 14:36:40 GMT")
+
+        self.assertEqual(time2netscape(base+2*day),
+                         "Sun, 21-Apr-2002 14:36:40 GMT")
+
+        self.assertEqual(time2netscape(base+3*day),
+                         "Mon, 22-Apr-2002 14:36:40 GMT")
+
+        az = time2netscape()
+        bz = time2netscape(500000)
+        for text in (az, bz):
+            # Format "%s, %02d-%s-%04d %02d:%02d:%02d GMT"
+            self.assertRegex(
+                text,
+                r"[a-zA-Z]{3}, \d{2}-[a-zA-Z]{3}-\d{4} \d{2}:\d{2}:\d{2} GMT$",
+                "bad time2netscape format: %s %s" % (az, bz))
+
     def test_http2time(self):
         def parse_date(text):
             return time.gmtime(http2time(text))[:6]
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -24,6 +24,10 @@
 Library
 -------
 
+- Issue #27466: Change time format returned by http.cookie.time2netscape,
+  confirming the netscape cookie format and making it consistent with
+  documentation.
+
 - Issue #21708: Deprecated dbm.dumb behavior that differs from common dbm
   behavior: creating a database in 'r' and 'w' modes and modifying a database
   in 'r' mode.

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list