This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: rfc822 __iter__ problem
Type: enhancement Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: barry Nosy List: barry, michael.foord, rhettinger
Priority: normal Keywords:

Created on 2004-09-17 22:10 by michael.foord, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
rfc822.diff rhettinger, 2004-09-21 06:03 rfc822.diff
Messages (5)
msg22476 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2004-09-17 22:10
>>> from urllib2 import urlopen
>>> a = urlopen('http://www.voidspace.org.uk')
>>> i = a.info()
>>> for entry in i: print entry
Traceback (most recent call last):
  File "<pyshell#11>", line 1, in -toplevel-
    for entry in i: print entry
  File "D:\PYTHON23\lib\rfc822.py", line 390, in 
__getitem__
    return self.dict[name.lower()]
AttributeError: 'int' object has no attribute 'lower'

Iterating over an rfc822 message (above done from 
urllib2) causes an exception. Could be fixed by returning 
an iter(self.dict) from the __iter__ method.

This bug looks similar to bug 1017329.
msg22477 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-09-21 05:12
Logged In: YES 
user_id=80475

This seems like a reasonable feature request.  Though I
don't know if it makes sense to improve a module that is
slated for deprecation per PEP 4.

If accepted, I would subclass from UserDict.DictMixin to
complete the dictionary iterface including __iter__.  
msg22478 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-09-21 06:03
Logged In: YES 
user_id=80475

See attached patch.
msg22479 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2004-09-22 16:35
Logged In: YES 
user_id=12800

It doesn't seem right to me to inherit from UserDict since a
Message is definitely /not/ a dictionary.  E.g. it may have
multiple occurances of the same header.

I'm fine with adding an __iter__ if you want because even
though rfc822 is slated for deprecation, unfortunately there
are still parts of the stdlib that haven't been rewritten to
use the email package.
msg22480 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-09-22 17:24
Logged In: YES 
user_id=80475

Fixed.
See Lib/rfc822.py 1.78.

Added only the __iter__ method.
History
Date User Action Args
2022-04-11 14:56:07adminsetgithub: 40923
2004-09-17 22:10:53mjfoordcreate