diff options
author | Senthil Kumaran <senthil@uthcode.com> | 2016-07-10 06:49:49 -0700 |
---|---|---|
committer | Senthil Kumaran <senthil@uthcode.com> | 2016-07-10 06:49:49 -0700 |
commit | 290b42de73d09dadc50fcd213787a4ba5e8724a3 (patch) | |
tree | dd979f8fc1a07280d4a22d936ac29325a60f52d9 /Lib | |
parent | f9efb8b18b689ff5ef7f12e6124f21532d799516 (diff) | |
parent | d5b47fb8ce8acefaf952cfa60ec73a875e407e66 (diff) | |
download | cpython-git-290b42de73d09dadc50fcd213787a4ba5e8724a3.tar.gz |
[merge from 3.5] - Issue #27466: Change time format returned by
http.cookie.time2netscape, confirming the netscape cookie format.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/http/cookiejar.py | 2 | ||||
-rw-r--r-- | Lib/test/test_http_cookiejar.py | 22 |
2 files changed, 23 insertions, 1 deletions
diff --git a/Lib/http/cookiejar.py b/Lib/http/cookiejar.py index 265ccf99f2..4466d2ece0 100644 --- a/Lib/http/cookiejar.py +++ b/Lib/http/cookiejar.py @@ -120,7 +120,7 @@ def time2netscape(t=None): 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 index 585838bd6c..a7826087a6 100644 --- a/Lib/test/test_http_cookiejar.py +++ b/Lib/test/test_http_cookiejar.py @@ -31,6 +31,28 @@ class DateTimeTests(unittest.TestCase): 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] |