Is it a bug (or a feature)?

R

Roman Suzi

In Python2.3.4:
.... 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:
.... print i
....
('Date', '24 Aug 2004 16:06:01 +0400')
('From', 'Mail System Internal Data <[email protected]>')
('Subject', "DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA")
('Message-ID', '<[email protected]>')
('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
 
P

Paul McGuire

Roman Suzi said:
In Python2.3.4:

... 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:

... print i
...
('Date', '24 Aug 2004 16:06:01 +0400')
('From', 'Mail System Internal Data <[email protected]>')
('Subject', "DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA")
('Message-ID', '<[email protected]>')
('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

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
 
P

Paul McGuire

Looking further at Message.py, __delitem__ has this same problem. When
fixing this, should probably also add an __iter__ method, that would return
iter(self._headers).

-- Paul
 
M

Michael Foord

Roman Suzi said:
In Python2.3.4:

... 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:

... print i
...
('Date', '24 Aug 2004 16:06:01 +0400')
('From', 'Mail System Internal Data <[email protected]>')
('Subject', "DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA")
('Message-ID', '<[email protected]>')
('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

It's very similar to a 'feature' in the urllib2 module. (Python 2.3.4)
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'


Regards,


Fuzzy

http://www.voidspace.org.uk/atlantibots/pythonutils.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top