[Python-checkins] cpython (merge 3.2 -> default): Issue #14653: email.utils.mktime_tz() no longer relies on system

alexander.belopolsky python-checkins at python.org
Fri Jun 22 02:49:13 CEST 2012


http://hg.python.org/cpython/rev/9f88c38318ac
changeset:   77561:9f88c38318ac
parent:      77559:1cfa44cb5af0
parent:      77560:ffc048f43a70
user:        Alexander Belopolsky <alexander.belopolsky at gmail.com>
date:        Thu Jun 21 20:48:23 2012 -0400
summary:
  Issue #14653: email.utils.mktime_tz() no longer relies on system
mktime() when timezone offest is supplied.

files:
  Lib/email/_parseaddr.py           |  8 ++++----
  Lib/test/test_email/test_email.py |  6 ++++++
  Misc/NEWS                         |  3 +++
  3 files changed, 13 insertions(+), 4 deletions(-)


diff --git a/Lib/email/_parseaddr.py b/Lib/email/_parseaddr.py
--- a/Lib/email/_parseaddr.py
+++ b/Lib/email/_parseaddr.py
@@ -13,7 +13,7 @@
     'quote',
     ]
 
-import time
+import time, calendar
 
 SPACE = ' '
 EMPTYSTRING = ''
@@ -177,13 +177,13 @@
 
 
 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
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -2722,6 +2722,12 @@
         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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -37,6 +37,9 @@
 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.
 

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


More information about the Python-checkins mailing list