Skip to content

Commit 53c6651

Browse files
committed
merge
2 parents 678e7f3 + 5a38f80 commit 53c6651

5 files changed

Lines changed: 45 additions & 15 deletions

File tree

Lib/imaplib.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
__version__ = "2.58"
2424

25-
import binascii, errno, random, re, socket, subprocess, sys, time
25+
import binascii, errno, random, re, socket, subprocess, sys, time, calendar
2626

2727
try:
2828
import ssl
@@ -1347,19 +1347,9 @@ def Internaldate2tuple(resp):
13471347
zone = -zone
13481348

13491349
tt = (year, mon, day, hour, min, sec, -1, -1, -1)
1350+
utc = calendar.timegm(tt) - zone
13501351

1351-
utc = time.mktime(tt)
1352-
1353-
# Following is necessary because the time module has no 'mkgmtime'.
1354-
# 'mktime' assumes arg in local timezone, so adds timezone/altzone.
1355-
1356-
lt = time.localtime(utc)
1357-
if time.daylight and lt[-1]:
1358-
zone = zone + time.altzone
1359-
else:
1360-
zone = zone + time.timezone
1361-
1362-
return time.localtime(utc - zone)
1352+
return time.localtime(utc)
13631353

13641354

13651355

Lib/test/support.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"get_attribute", "swap_item", "swap_attr", "requires_IEEE_754",
5858
"TestHandler", "Matcher", "can_symlink", "skip_unless_symlink",
5959
"import_fresh_module", "requires_zlib", "PIPE_MAX_SIZE", "failfast",
60-
"anticipate_failure"
60+
"anticipate_failure", "run_with_tz"
6161
]
6262

6363
class Error(Exception):
@@ -1099,6 +1099,35 @@ def inner(*args, **kwds):
10991099
return inner
11001100
return decorator
11011101

1102+
#=======================================================================
1103+
# Decorator for running a function in a specific timezone, correctly
1104+
# resetting it afterwards.
1105+
1106+
def run_with_tz(tz):
1107+
def decorator(func):
1108+
def inner(*args, **kwds):
1109+
if 'TZ' in os.environ:
1110+
orig_tz = os.environ['TZ']
1111+
else:
1112+
orig_tz = None
1113+
os.environ['TZ'] = tz
1114+
time.tzset()
1115+
1116+
# now run the function, resetting the tz on exceptions
1117+
try:
1118+
return func(*args, **kwds)
1119+
finally:
1120+
if orig_tz == None:
1121+
del os.environ['TZ']
1122+
else:
1123+
os.environ['TZ'] = orig_tz
1124+
time.tzset()
1125+
1126+
inner.__name__ = func.__name__
1127+
inner.__doc__ = func.__doc__
1128+
return inner
1129+
return decorator
1130+
11021131
#=======================================================================
11031132
# Big-memory-test support. Separate from 'resources' because memory use
11041133
# should be configurable.

Lib/test/test_imaplib.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import time
1212
import calendar
1313

14-
from test.support import reap_threads, verbose, transient_internet
14+
from test.support import reap_threads, verbose, transient_internet, run_with_tz
1515
import unittest
1616

1717
try:
@@ -36,6 +36,13 @@ def test_Internaldate2tuple(self):
3636
b'25 (INTERNALDATE "31-Dec-1999 12:30:00 -1130")')
3737
self.assertEqual(time.mktime(tt), t0)
3838

39+
@run_with_tz('MST+07MDT,M4.1.0,M10.5.0')
40+
def test_Internaldate2tuple_issue10941(self):
41+
self.assertNotEqual(imaplib.Internaldate2tuple(
42+
b'25 (INTERNALDATE "02-Apr-2000 02:30:00 +0000")'),
43+
imaplib.Internaldate2tuple(
44+
b'25 (INTERNALDATE "02-Apr-2000 03:30:00 +0000")'))
45+
3946
def test_that_Time2Internaldate_returns_a_result(self):
4047
# We can check only that it successfully produces a result,
4148
# not the correctness of the result itself, since the result

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ Alexandre Parenteau
770770
Dan Parisien
771771
Harri Pasanen
772772
Gaël Pasgrimaud
773+
Joe Peterson
773774
Randy Pausch
774775
Samuele Pedroni
775776
Marcel van der Peijl

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ Core and Builtins
8484
Library
8585
-------
8686

87+
- Issue #10941: Fix imaplib.Internaldate2tuple to produce correct result near
88+
the DST transition. Patch by Joe Peterson.
89+
8790
- Issue #9154: Fix parser module to understand function annotations.
8891

8992
- Issue #6085: In http.server.py SimpleHTTPServer.address_string returns the

0 commit comments

Comments
 (0)