diff -r ab9d6c4907e7 Lib/imaplib.py --- a/Lib/imaplib.py Thu Apr 19 23:55:01 2012 +0200 +++ b/Lib/imaplib.py Fri Apr 20 16:44:27 2012 -0700 @@ -22,7 +22,7 @@ __version__ = "2.58" -import binascii, errno, random, re, socket, subprocess, sys, time +import binascii, errno, random, re, socket, subprocess, sys, time, calendar __all__ = ["IMAP4", "IMAP4_stream", "Internaldate2tuple", "Int2AP", "ParseFlags", "Time2Internaldate"] @@ -1339,19 +1339,9 @@ zone = -zone tt = (year, mon, day, hour, min, sec, -1, -1, -1) + utc = calendar.timegm(tt) - zone - utc = time.mktime(tt) - - # Following is necessary because the time module has no 'mkgmtime'. - # 'mktime' assumes arg in local timezone, so adds timezone/altzone. - - lt = time.localtime(utc) - if time.daylight and lt[-1]: - zone = zone + time.altzone - else: - zone = zone + time.timezone - - return time.localtime(utc - zone) + return time.localtime(utc) diff -r ab9d6c4907e7 Lib/test/test_imaplib.py --- a/Lib/test/test_imaplib.py Thu Apr 19 23:55:01 2012 +0200 +++ b/Lib/test/test_imaplib.py Fri Apr 20 16:44:27 2012 -0700 @@ -10,7 +10,7 @@ import SocketServer import time -from test_support import reap_threads, verbose, transient_internet +from test_support import reap_threads, verbose, transient_internet, run_with_tz import unittest try: @@ -23,6 +23,13 @@ class TestImaplib(unittest.TestCase): + @run_with_tz('MST+07MDT,M4.1.0,M10.5.0') + def test_Internaldate2tuple_issue10941(self): + self.assertNotEqual(imaplib.Internaldate2tuple( + '25 (INTERNALDATE "02-Apr-2000 02:30:00 +0000")'), + imaplib.Internaldate2tuple( + '25 (INTERNALDATE "02-Apr-2000 03:30:00 +0000")')) + def test_that_Time2Internaldate_returns_a_result(self): # We can check only that it successfully produces a result, # not the correctness of the result itself, since the result diff -r ab9d6c4907e7 Lib/test/test_support.py --- a/Lib/test/test_support.py Thu Apr 19 23:55:01 2012 +0200 +++ b/Lib/test/test_support.py Fri Apr 20 16:44:27 2012 -0700 @@ -32,7 +32,8 @@ "open_urlresource", "check_warnings", "check_py3k_warnings", "CleanImport", "EnvironmentVarGuard", "captured_output", "captured_stdout", "TransientResource", "transient_internet", - "run_with_locale", "set_memlimit", "bigmemtest", "bigaddrspacetest", + "run_with_locale", "run_with_tz", + "set_memlimit", "bigmemtest", "bigaddrspacetest", "BasicTestRunner", "run_unittest", "run_doctest", "threading_setup", "threading_cleanup", "reap_children", "cpython_only", "check_impl_detail", "get_attribute", "py3k_bytes", @@ -895,6 +896,35 @@ return decorator #======================================================================= +# Decorator for running a function in a specific timezone, correctly +# resetting it afterwards. + +def run_with_tz(tz): + def decorator(func): + def inner(*args, **kwds): + if 'TZ' in os.environ: + orig_tz = os.environ['TZ'] + else: + orig_tz = None + os.environ['TZ'] = tz + time.tzset() + + # now run the function, resetting the tz on exceptions + try: + return func(*args, **kwds) + finally: + if orig_tz == None: + del os.environ['TZ'] + else: + os.environ['TZ'] = orig_tz + time.tzset() + + inner.func_name = func.func_name + inner.__doc__ = func.__doc__ + return inner + return decorator + +#======================================================================= # Big-memory-test support. Separate from 'resources' because memory use should be configurable. # Some handy shorthands. Note that these are used for byte-limits as well