From: Raymond Hettinger Date: Wed, 22 Sep 2004 17:17:32 +0000 (+0000) Subject: Bug #1030125: rfc822 __iter__ problem X-Git-Tag: v2.4b1~220 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ce96d8b6846f5658018923efcb8a5810bbb0bfb7;p=python Bug #1030125: rfc822 __iter__ problem Add iteration support to the Message class. --- diff --git a/Lib/rfc822.py b/Lib/rfc822.py index 3b4246de92..18277d6dff 100644 --- a/Lib/rfc822.py +++ b/Lib/rfc822.py @@ -444,6 +444,9 @@ class Message: """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() diff --git a/Lib/test/test_rfc822.py b/Lib/test/test_rfc822.py index 491bc8aba0..0d9f28a777 100644 --- a/Lib/test/test_rfc822.py +++ b/Lib/test/test_rfc822.py @@ -176,6 +176,17 @@ class MessageTestCase(unittest.TestCase): '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 \n' + 'To: "Guido van\n' + '\t : Rossum" \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 diff --git a/Misc/NEWS b/Misc/NEWS index 3dac4a87d1..617e815867 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -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.