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.

Author ptmcg
Recipients
Date 2004-08-27.02:11:01
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
From comp.lang.python:

"Roman Suzi" <rnd@onego.ru> wrote in message
news:mailman.2348.1093434827.5135.python-
list@python.org...
>
> In Python2.3.4:
>
> >>> em = email.message_from_file(open
('MAILMESSAGE'))
> >>> for i in em:
> ...   print i
> ...
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "/usr/lib/python2.3/email/Message.py",
> line
> 304, in __getitem__
>   File "/usr/lib/python2.3/email/Message.py",
> line
> 370, in get
> AttributeError: 'int' object has no attribute 'lower'

In this example, em is an email.Message object.  The 
Message acts as a pseudo-dictionary, containing a list of 
e-mail fields, organized by name and contents.

The problem occurs because __getitem__ assumes that 
the provided index is a name into a dictionary.  For 
programmer convenience, keys in the Message are case-
insensitive, so __getitem__ starts by calling lower() on 
the provided name.  Apparently, the attempt to iterate 
over Message successively calls __getitem__ with 
integers from 0 to len(em).  Integers don't like having 
lower() called, though.

To fix this problem:
- have __getitem__ use the input arg as a name if it is 
of type string; otherwise, just use the provided arg as 
an index to the underlying self.headers list (arg could 
be either an integer or a slice, so don't just test for 
integer!)
- make a similar change to __delitem__ - it too 
assumes that the incoming arg is a string, naming a 
header field to be deleted; must test first to see if arg is 
an integer or slice
- add __iter__ method, which returns iter(self.headers)

-- Paul
History
Date User Action Args
2007-08-23 14:25:46adminlinkissue1017329 messages
2007-08-23 14:25:46admincreate