Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bpo-30681: Add InvalidDateDefect
  • Loading branch information
timb07 committed Nov 29, 2018
commit 0f5c299c148f99c5ef7e3d8b17d0ba91b67a105c
3 changes: 3 additions & 0 deletions Lib/email/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,6 @@ class NonASCIILocalPartDefect(HeaderDefect):
"""local_part contains non-ASCII characters"""
# This defect only occurs during unicode parsing, not when
# parsing messages decoded from binary.

class InvalidDateDefect(HeaderDefect):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also please add this to documentation under email.errors.rst ?

"""Header has unparseable or invalid date"""
2 changes: 1 addition & 1 deletion Lib/email/headerregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def parse(cls, value, kwds):
try:
value = utils.parsedate_to_datetime(value)
except (ValueError, TypeError):
kwds['defects'].append(errors.InvalidHeaderDefect('Invalid date value or format'))
kwds['defects'].append(errors.InvalidDateDefect('Invalid date value or format'))
kwds['datetime'] = None
kwds['parse_tree'] = parser.TokenList()
return
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_email/test_headerregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ def test_invalid_date_format(self):
self.assertEqual(h, s)
self.assertIsNone(h.datetime)
self.assertEqual(len(h.defects), 1)
self.assertIsInstance(h.defects[0], errors.InvalidHeaderDefect)
self.assertIsInstance(h.defects[0], errors.InvalidDateDefect)

def test_invalid_date_value(self):
s = 'Tue, 06 Jun 2017 27:39:33 +0600'
h = self.make_header('date', s)
self.assertEqual(h, s)
self.assertIsNone(h.datetime)
self.assertEqual(len(h.defects), 1)
self.assertIsInstance(h.defects[0], errors.InvalidHeaderDefect)
self.assertIsInstance(h.defects[0], errors.InvalidDateDefect)

def test_datetime_read_only(self):
h = self.make_header('date', self.datestring)
Expand Down