]> granicus.if.org Git - python/commitdiff
Bug #1030125: rfc822 __iter__ problem
authorRaymond Hettinger <python@rcn.com>
Wed, 22 Sep 2004 17:17:32 +0000 (17:17 +0000)
committerRaymond Hettinger <python@rcn.com>
Wed, 22 Sep 2004 17:17:32 +0000 (17:17 +0000)
Add iteration support to the Message class.

Lib/rfc822.py
Lib/test/test_rfc822.py
Misc/NEWS

index 3b4246de924eed661c6b119c54d1330a080a2d5d..18277d6dff4dbe080e9902d65e961623b1f8e354 100644 (file)
@@ -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()
index 491bc8aba0b511b95f5b11061274e2b94bfe593a..0d9f28a777161ee33226bc0e51214b840d509a69 100644 (file)
@@ -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 <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
index 3dac4a87d1f7052a9d07c886d92ee80df2ff06a8..617e815867a4a4637ef6a96d6ae4f4458271379d 100644 (file)
--- 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.