Kaydet (Commit) 2d2e6be3 authored tarafından Senthil Kumaran's avatar Senthil Kumaran

[port to 2.7] - Issue #27466: Change time format returned by

http.cookie.time2netscape, confirming the netscape cookie format.
üst e5fa8b0b
...@@ -113,7 +113,7 @@ def time2netscape(t=None): ...@@ -113,7 +113,7 @@ def time2netscape(t=None):
""" """
if t is None: t = time.time() if t is None: t = time.time()
year, mon, mday, hour, min, sec, wday = time.gmtime(t)[:7] year, mon, mday, hour, min, sec, wday = time.gmtime(t)[:7]
return "%s %02d-%s-%04d %02d:%02d:%02d GMT" % ( return "%s, %02d-%s-%04d %02d:%02d:%02d GMT" % (
DAYS[wday], mday, MONTHS[mon-1], year, hour, min, sec) DAYS[wday], mday, MONTHS[mon-1], year, hour, min, sec)
......
...@@ -6,6 +6,7 @@ import os ...@@ -6,6 +6,7 @@ import os
import re import re
import time import time
from cookielib import http2time, time2isoz, time2netscape
from unittest import TestCase from unittest import TestCase
from test import test_support from test import test_support
...@@ -14,8 +15,6 @@ from test import test_support ...@@ -14,8 +15,6 @@ from test import test_support
class DateTimeTests(TestCase): class DateTimeTests(TestCase):
def test_time2isoz(self): def test_time2isoz(self):
from cookielib import time2isoz
base = 1019227000 base = 1019227000
day = 24*3600 day = 24*3600
self.assertEqual(time2isoz(base), "2002-04-19 14:36:40Z") self.assertEqual(time2isoz(base), "2002-04-19 14:36:40Z")
...@@ -30,9 +29,29 @@ class DateTimeTests(TestCase): ...@@ -30,9 +29,29 @@ class DateTimeTests(TestCase):
r"^\d{4}-\d\d-\d\d \d\d:\d\d:\d\dZ$", r"^\d{4}-\d\d-\d\d \d\d:\d\d:\d\dZ$",
"bad time2isoz format: %s %s" % (az, bz)) "bad time2isoz format: %s %s" % (az, bz))
def test_http2time(self): def test_time2netscape(self):
from cookielib import http2time 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.assertRegexpMatches(
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): def parse_date(text):
return time.gmtime(http2time(text))[:6] return time.gmtime(http2time(text))[:6]
...@@ -45,7 +64,7 @@ class DateTimeTests(TestCase): ...@@ -45,7 +64,7 @@ class DateTimeTests(TestCase):
self.assertEqual(parse_date("03-Feb-98"), (1998, 2, 3, 0, 0, 0.0)) self.assertEqual(parse_date("03-Feb-98"), (1998, 2, 3, 0, 0, 0.0))
def test_http2time_formats(self): def test_http2time_formats(self):
from cookielib import http2time, time2isoz
# test http2time for supported dates. Test cases with 2 digit year # test http2time for supported dates. Test cases with 2 digit year
# will probably break in year 2044. # will probably break in year 2044.
...@@ -81,8 +100,6 @@ class DateTimeTests(TestCase): ...@@ -81,8 +100,6 @@ class DateTimeTests(TestCase):
self.assertEqual(http2time(s.upper()), test_t, s.upper()) self.assertEqual(http2time(s.upper()), test_t, s.upper())
def test_http2time_garbage(self): def test_http2time_garbage(self):
from cookielib import http2time
for test in [ for test in [
'', '',
'Garbage', 'Garbage',
......
...@@ -17,6 +17,10 @@ Core and Builtins ...@@ -17,6 +17,10 @@ Core and Builtins
Library Library
------- -------
- Issue #27466: Change time format returned by http.cookie.time2netscape,
confirming the netscape cookie format and making it consistent with
documentation.
- Issue #22115: Fixed tracing Tkinter variables: trace_vdelete() with wrong - Issue #22115: Fixed tracing Tkinter variables: trace_vdelete() with wrong
mode no longer break tracing, trace_vinfo() now always returns a list of mode no longer break tracing, trace_vinfo() now always returns a list of
pairs of strings. pairs of strings.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment