473,402 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Bug in email package?


I was playing with email package and discovrered this strange kind of
behaviour:
import email.Message
m = email.Message.Message()
m['a'] = '123'
print mFrom nobody Mon Feb 21 00:12:27 2005

a: 123

for i in m: print i

....
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/local/lib/python2.3/email/Message.py", line 304, in __getitem__
return self.get(name)
File "/usr/local/lib/python2.3/email/Message.py", line 370, in get
name = name.lower()
AttributeError: 'int' object has no attribute 'lower'
I think that if any object (from standard library at least) doesn't support
iteration, it should clearly state so.

My guess is that 'for' causes the use of 'm[0]', which is (rightfully) an
error...

Can this behaviour of email be considered a bug?
Is there a good case to iterate over something useful in a message?

P.S. rfc822 has the same behaviour, at least on Python 2.3
Sincerely yours, Roman Suzi
--
rn*@onego.ru =\= My AI powered by GNU/Linux RedHat 7.3
Jul 18 '05 #1
4 1379
Roman Suzi wrote:
I think that if any object (from standard library at least) doesn't support
iteration, it should clearly state so.

My guess is that 'for' causes the use of 'm[0]', which is (rightfully) an
error...

Can this behaviour of email be considered a bug?
Is there a good case to iterate over something useful in a message


Why would it be a bug if the documentation never stated that the object
was iterable?

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
Wyrd has swept all my kin / all the brave chiefs away! / Now I must
follow them! -- Beowulf
Jul 18 '05 #2
Erik Max Francis wrote:
Roman Suzi wrote:
I think that if any object (from standard library at least) doesn't
support
iteration, it should clearly state so.

My guess is that 'for' causes the use of 'm[0]', which is (rightfully)
an error...

Can this behaviour of email be considered a bug?
Is there a good case to iterate over something useful in a message


Why would it be a bug if the documentation never stated that the object
was iterable?


I think the bug is not that an error is produced, but that the _wrong_
error is produced. Trying to iterate over something that is not
iterable should produce a TypeError saying so (not an Attribute error):

py> class C(object):
.... pass
....
py> iter(C())
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: iteration over non-sequence

I've actually seen something like this come up before (I think with
email.Message even...) I say call it a bug and submit a patch. It's
pretty easy to fix -- just add an __iter__ method to Message that raises
a TypeError. That makes it clear that Message doesn't intend to support
the getitem protocol -- it just does so accidentally because it provides
__getitem__.

STeVe
Jul 18 '05 #3
Roman Suzi <rn*@onego.ru> wrote:

I was playing with email package and discovrered this strange kind of
behaviour:
import email.Message
m = email.Message.Message()
m['a'] = '123'
print mFrom nobody Mon Feb 21 00:12:27 2005

a: 123
for i in m: print i

...
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/local/lib/python2.3/email/Message.py", line 304, in __getitem__
return self.get(name)
File "/usr/local/lib/python2.3/email/Message.py", line 370, in get
name = name.lower()
AttributeError: 'int' object has no attribute 'lower'


Intuitively, what did you expect this to do? I don't see why a single
message should be iterable.
I think that if any object (from standard library at least) doesn't support
iteration, it should clearly state so.
That's going a bit far. Iteration is a relatively new addition to Python.
Those classes that DO support iteration generally say so. If it isn't
mentioned, you probaby shouldn't assume it.
Can this behaviour of email be considered a bug?
Not in my opinion, no.
Is there a good case to iterate over something useful in a message?
Well, if you don't have an answer to that question, then why would you
expect it to support iteration?
P.S. rfc822 has the same behaviour, at least on Python 2.3


Again, I'm not sure what, intuitively, it would mean to iterate over an
rfc822 object.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #4
On Sun, 20 Feb 2005, Steven Bethard wrote:
Erik Max Francis wrote:
Roman Suzi wrote:
I think that if any object (from standard library at least) doesn't support
iteration, it should clearly state so.

My guess is that 'for' causes the use of 'm[0]', which is (rightfully) an
error...

Can this behaviour of email be considered a bug?
Is there a good case to iterate over something useful in a message
Why would it be a bug if the documentation never stated that the object was
iterable?


I think the bug is not that an error is produced, but that the _wrong_ error
is produced. Trying to iterate over something that is not iterable should


Well, that was what I meant.
produce a TypeError saying so (not an Attribute error):

py> class C(object):
... pass
...
py> iter(C())
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: iteration over non-sequence

I've actually seen something like this come up before (I think with
email.Message even...) I say call it a bug and submit a patch.
Ok. A bug minute on the next bug day ;-)
It's pretty
easy to fix -- just add an __iter__ method to Message that raises a TypeError.
That makes it clear that Message doesn't intend to support the getitem
protocol -- it just does so accidentally because it provides __getitem__.

STeVe


Sincerely yours, Roman Suzi
--
rn*@onego.ru =\= My AI powered by GNU/Linux RedHat 7.3
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Auction software | last post by:
Free download full version , all products http://netauction8.url4life.com/ Groupawy --------------- Google Groups Email spider. The first email spider for google groups. Millions of valid...
1
by: Adonis | last post by:
Is there a way to retrieve the message body using the email package? or is the email package just for parsing mime formatted messages? or would I have to parse the information retrieved from poplib...
0
by: Barry Warsaw | last post by:
Python 2.4 final will probably be released in a few hours so this seems like a good time to release the standalone email package, version 3.0 final. Unless there's some last second snafu, this...
5
by: Roman Suzi | last post by:
(this is a repost with an addition - probably noone noticed my message first time) Hi! Just to be sure, is email package of Python 2.3 thread-safe or not (to use, for example, in...
2
by: aurora00 | last post by:
Looking at the email package, it seems all the MIMExxx classes takes string but not file object as the payload. I need to handle very large MIME messages say up to 100M. And possibly many of them....
0
by: Auction software | last post by:
Free download full version , all products from Mewsoft dot com http://netauction8.url4life.com/ Groupawy --------------- Google Groups Email spider. The first email spider for google groups....
21
by: Dev | last post by:
Dear All, I have created a website. in the contact us page i want to send all information (Entered by visitor in text boxex) directly to my e-mail address. to do this i have no idea because i am...
1
by: creative1 | last post by:
When I test the application I get follwowing error: could not connect to smtp host: connection timeout error can someone please check if I have rigth settings? Where I am wrong here Is IP and...
0
by: Marcus.CM | last post by:
Hi, Actually i think its the email package that needs to be "redefined", using lazyimporter is a bad decision and a lousy one. Even py2exe could not handle it correctly. Marcus. Wingware...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.