summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2012-06-22 00:48:23 (GMT)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2012-06-22 00:48:23 (GMT)
commit76935b9c8cc083f4d00bee3b8f0c76054dd31013 (patch)
tree98f6ece8d6a3a7d582c76b209c1c943719fc3db0
parent2180c97a0055c8c2f6f2cf0754bfb650d7cc0f34 (diff)
parenta07548e97bd819884ed1ddcfedb0fcbcbfdc58fe (diff)
downloadcpython-76935b9c8cc083f4d00bee3b8f0c76054dd31013.zip
cpython-76935b9c8cc083f4d00bee3b8f0c76054dd31013.tar.gz
cpython-76935b9c8cc083f4d00bee3b8f0c76054dd31013.tar.bz2
Issue #14653: email.utils.mktime_tz() no longer relies on system
mktime() when timezone offest is supplied.
-rw-r--r--Lib/email/_parseaddr.py8
-rw-r--r--Lib/test/test_email/test_email.py6
-rw-r--r--Misc/NEWS3
3 files changed, 13 insertions, 4 deletions
diff --git a/Lib/email/_parseaddr.py b/Lib/email/_parseaddr.py
index 0342469..3528d02 100644
--- a/Lib/email/_parseaddr.py
+++ b/Lib/email/_parseaddr.py
@@ -13,7 +13,7 @@ __all__ = [
'quote',
]
-import time
+import time, calendar
SPACE = ' '
EMPTYSTRING = ''
@@ -177,13 +177,13 @@ def parsedate(data):
def mktime_tz(data):
- """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp."""
+ """Turn a 10-tuple as returned by parsedate_tz() into a POSIX timestamp."""
if data[9] is None:
# No zone info, so localtime is better assumption than GMT
return time.mktime(data[:8] + (-1,))
else:
- t = time.mktime(data[:8] + (0,))
- return t - data[9] - time.timezone
+ t = calendar.timegm(data)
+ return t - data[9]
def quote(str):
diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py
index 5aefc47..8cc2da0 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -2722,6 +2722,12 @@ class TestMiscellaneous(TestEmailBase):
eq(time.localtime(t)[:6], timetup[:6])
eq(int(time.strftime('%Y', timetup[:9])), 2003)
+ def test_mktime_tz(self):
+ self.assertEqual(utils.mktime_tz((1970, 1, 1, 0, 0, 0,
+ -1, -1, -1, 0)), 0)
+ self.assertEqual(utils.mktime_tz((1970, 1, 1, 0, 0, 0,
+ -1, -1, -1, 1234)), -1234)
+
def test_parsedate_y2k(self):
"""Test for parsing a date with a two-digit year.
diff --git a/Misc/NEWS b/Misc/NEWS
index 5ce4f12..c32697d 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -37,6 +37,9 @@ Core and Builtins
Library
-------
+- Issue #14653: email.utils.mktime_tz() no longer relies on system
+ mktime() when timezone offest is supplied.
+
- Issue #14684: zlib.compressobj() and zlib.decompressobj() now support the use
of predefined compression dictionaries. Original patch by Sam Rushing.