File tree Expand file tree Collapse file tree 4 files changed +21
-24
lines changed Expand file tree Collapse file tree 4 files changed +21
-24
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,8 @@ def parsedate_tz(data):
48
48
Accounts for military timezones.
49
49
"""
50
50
res = _parsedate_tz (data )
51
+ if not res :
52
+ return
51
53
if res [9 ] is None :
52
54
res [9 ] = 0
53
55
return tuple (res )
@@ -62,6 +64,8 @@ def _parsedate_tz(data):
62
64
source timezone really was UTC.
63
65
64
66
"""
67
+ if not data :
68
+ return
65
69
data = data .split ()
66
70
# The FWS after the comma after the day-of-week is optional, so search and
67
71
# adjust for this.
Original file line number Diff line number Diff line change 37
37
from email ._parseaddr import AddressList as _AddressList
38
38
from email ._parseaddr import mktime_tz
39
39
40
- # We need wormarounds for bugs in these methods in older Pythons (see below)
41
- from email ._parseaddr import parsedate as _parsedate
42
- from email ._parseaddr import parsedate_tz as _parsedate_tz
43
- from email ._parseaddr import _parsedate_tz as __parsedate_tz
40
+ from email ._parseaddr import parsedate , parsedate_tz , _parsedate_tz
44
41
45
42
from quopri import decodestring as _qdecode
46
43
@@ -222,25 +219,8 @@ def make_msgid(idstring=None, domain=None):
222
219
return msgid
223
220
224
221
225
-
226
- # These functions are in the standalone mimelib version only because they've
227
- # subsequently been fixed in the latest Python versions. We use this to worm
228
- # around broken older Pythons.
229
- def parsedate (data ):
230
- if not data :
231
- return None
232
- return _parsedate (data )
233
-
234
-
235
- def parsedate_tz (data ):
236
- if not data :
237
- return None
238
- return _parsedate_tz (data )
239
-
240
222
def parsedate_to_datetime (data ):
241
- if not data :
242
- return None
243
- * dtuple , tz = __parsedate_tz (data )
223
+ * dtuple , tz = _parsedate_tz (data )
244
224
if tz is None :
245
225
return datetime .datetime (* dtuple [:6 ])
246
226
return datetime .datetime (* dtuple [:6 ],
Original file line number Diff line number Diff line change @@ -2718,8 +2718,17 @@ def test_formatdate_usegmt(self):
2718
2718
utils .formatdate (now , localtime = False , usegmt = True ),
2719
2719
time .strftime ('%a, %d %b %Y %H:%M:%S GMT' , time .gmtime (now )))
2720
2720
2721
- def test_parsedate_none (self ):
2722
- self .assertEqual (utils .parsedate ('' ), None )
2721
+ # parsedate and parsedate_tz will become deprecated interfaces someday
2722
+ def test_parsedate_returns_None_for_invalid_strings (self ):
2723
+ self .assertIsNone (utils .parsedate ('' ))
2724
+ self .assertIsNone (utils .parsedate_tz ('' ))
2725
+ self .assertIsNone (utils .parsedate ('0' ))
2726
+ self .assertIsNone (utils .parsedate_tz ('0' ))
2727
+ self .assertIsNone (utils .parsedate ('A Complete Waste of Time' ))
2728
+ self .assertIsNone (utils .parsedate_tz ('A Complete Waste of Time' ))
2729
+ # Not a part of the spec but, but this has historically worked:
2730
+ self .assertIsNone (utils .parsedate (None ))
2731
+ self .assertIsNone (utils .parsedate_tz (None ))
2723
2732
2724
2733
def test_parsedate_compact (self ):
2725
2734
# The FWS after the comma is optional
Original file line number Diff line number Diff line change @@ -22,6 +22,10 @@ Library
22
22
with decimal.py: Infinity coefficients are undefined in _decimal
23
23
(in accordance with the specification).
24
24
25
+ - Issue #15925: Fix a regression in email.util where the parsedate() and
26
+ parsedate_tz() functions did not return None anymore when the argument could
27
+ not be parsed.
28
+
25
29
Extension Modules
26
30
-----------------
27
31
You can’t perform that action at this time.
0 commit comments