File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,6 +48,8 @@ def parsedate_tz(data):
4848 Accounts for military timezones.
4949 """
5050 res = _parsedate_tz (data )
51+ if not res :
52+ return
5153 if res [9 ] is None :
5254 res [9 ] = 0
5355 return tuple (res )
@@ -62,6 +64,8 @@ def _parsedate_tz(data):
6264 source timezone really was UTC.
6365
6466 """
67+ if not data :
68+ return
6569 data = data .split ()
6670 # The FWS after the comma after the day-of-week is optional, so search and
6771 # adjust for this.
Original file line number Diff line number Diff line change 3737from email ._parseaddr import AddressList as _AddressList
3838from email ._parseaddr import mktime_tz
3939
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
4441
4542from quopri import decodestring as _qdecode
4643
@@ -222,25 +219,8 @@ def make_msgid(idstring=None, domain=None):
222219 return msgid
223220
224221
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-
240222def parsedate_to_datetime (data ):
241- if not data :
242- return None
243- * dtuple , tz = __parsedate_tz (data )
223+ * dtuple , tz = _parsedate_tz (data )
244224 if tz is None :
245225 return datetime .datetime (* dtuple [:6 ])
246226 return datetime .datetime (* dtuple [:6 ],
Original file line number Diff line number Diff line change @@ -2718,8 +2718,17 @@ def test_formatdate_usegmt(self):
27182718 utils .formatdate (now , localtime = False , usegmt = True ),
27192719 time .strftime ('%a, %d %b %Y %H:%M:%S GMT' , time .gmtime (now )))
27202720
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 ))
27232732
27242733 def test_parsedate_compact (self ):
27252734 # The FWS after the comma is optional
Original file line number Diff line number Diff line change @@ -22,6 +22,10 @@ Library
2222 with decimal.py: Infinity coefficients are undefined in _decimal
2323 (in accordance with the specification).
2424
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+
2529Extension Modules
2630-----------------
2731
You can’t perform that action at this time.
0 commit comments