Is it a bug (or a feature)?

Paul McGuire ptmcg at austin.rr._bogus_.com
Wed Aug 25 14:43:00 CEST 2004


"Roman Suzi" <rnd at onego.ru> wrote in message
news:mailman.2348.1093434827.5135.python-list at 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'
>
> However items() does work:
>
> >>> for i in em.items():
> ...   print i
> ...
> ('Date', '24 Aug 2004 16:06:01 +0400')
> ('From', 'Mail System Internal Data <MAILER-DAEMON at mydomain.ru>')
> ('Subject', "DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA")
> ('Message-ID', '<1095549161 at mydomain.ru>')
> ('X-IMAP', '1095527634 0000000005')
> ('Status', 'RO')
>
> I can probably guess why this happens ('cause multiple fields with the
> same names are possible), but .items() is broken by this... It needn't
> be!
>
>
> Sincerely yours, Roman A.Suzi
> -- 
>  - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru -
>

Looks like a bug to me.  Message.__getitem__() makes a call to
Message.get(), assuming that the argument passed in is a key name (such as
'Date', 'From', etc. from your example).  __getitem__ should first check to
see if the input argument (named 'name', further indication that this method
was written to expect only strings) is an integer or slice, and if so, just
return self._headers[name].

-- Paul





More information about the Python-list mailing list