Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ce96d8b

Browse files
committed
Bug #1030125: rfc822 __iter__ problem
Add iteration support to the Message class.
1 parent c6646c0 commit ce96d8b

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

Lib/rfc822.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,9 @@ def __contains__(self, name):
444444
"""Determine whether a message contains the named header."""
445445
return name.lower() in self.dict
446446

447+
def __iter__(self):
448+
return iter(self.dict)
449+
447450
def keys(self):
448451
"""Get all of a message's header field names."""
449452
return self.dict.keys()

Lib/test/test_rfc822.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,17 @@ def test_addr_ipquad(self):
176176
'foo',
177177
[('', 'guido@[132.151.1.21]')])
178178

179+
def test_iter(self):
180+
m = rfc822.Message(StringIO(
181+
'Date: Wed, 13 Jan 1999 23:57:35 -0500\n'
182+
'From: Guido van Rossum <[email protected]>\n'
183+
'To: "Guido van\n'
184+
'\t : Rossum" <[email protected]>\n'
185+
'Subject: test2\n'
186+
'\n'
187+
'test2\n' ))
188+
self.assertEqual(sorted(m), ['date', 'from', 'subject', 'to'])
189+
179190
def test_rfc2822_phrases(self):
180191
# RFC 2822 (the update to RFC 822) specifies that dots in phrases are
181192
# obsolete syntax, which conforming programs MUST recognize but NEVER

Misc/NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Extension modules
2121

2222
Library
2323
-------
24+
- rfc822 Messages now support iteration.
2425

2526
- The (undocumented) tarfile.Tarfile.membernames has been removed;
2627
applications should use the getmember function.

0 commit comments

Comments
 (0)