Bug #1030125: rfc822 __iter__ problem

Add iteration support to the Message class.
This commit is contained in:
Raymond Hettinger 2004-09-22 17:17:32 +00:00
parent c6646c097a
commit ce96d8b684
3 changed files with 15 additions and 0 deletions

View file

@ -444,6 +444,9 @@ def __contains__(self, name):
"""Determine whether a message contains the named header."""
return name.lower() in self.dict
def __iter__(self):
return iter(self.dict)
def keys(self):
"""Get all of a message's header field names."""
return self.dict.keys()

View file

@ -176,6 +176,17 @@ def test_addr_ipquad(self):
'foo',
[('', 'guido@[132.151.1.21]')])
def test_iter(self):
m = rfc822.Message(StringIO(
'Date: Wed, 13 Jan 1999 23:57:35 -0500\n'
'From: Guido van Rossum <guido@CNRI.Reston.VA.US>\n'
'To: "Guido van\n'
'\t : Rossum" <guido@python.org>\n'
'Subject: test2\n'
'\n'
'test2\n' ))
self.assertEqual(sorted(m), ['date', 'from', 'subject', 'to'])
def test_rfc2822_phrases(self):
# RFC 2822 (the update to RFC 822) specifies that dots in phrases are
# obsolete syntax, which conforming programs MUST recognize but NEVER

View file

@ -21,6 +21,7 @@ Extension modules
Library
-------
- rfc822 Messages now support iteration.
- The (undocumented) tarfile.Tarfile.membernames has been removed;
applications should use the getmember function.