[Python-bugs-list] [ python-Bugs-461073 ] mailbox __iter__ bug
noreply@sourceforge.net
noreply@sourceforge.net
Wed, 12 Sep 2001 17:40:54 -0700
Bugs item #461073, was opened at 2001-09-12 17:40
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=461073&group_id=5470
Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Andrew Dalke (dalke)
Assigned to: Nobody/Anonymous (nobody)
Summary: mailbox __iter__ bug
Initial Comment:
This is with the most recent version code
from CVS (Sept. 12).
The following never stops
infile = open("test.mbox")
for msg in mailbox.PortableUnixMailbox(infile):
pass
More specifically,
>>> import mailbox
>>> for msg in mailbox.PortableUnixMailbox( \
... open("test.mbox")):
... assert msg is not None
...
Traceback (most recent call last):
File "<stdin>", line 2, in ?
AssertionError
>>>
The problem is the iterator in mailbox.py.
It is defined
def __iter__(self):
return self
but needs to be
def __iter__(self):
return iter(self.next, None)
There are a few places that need to be changed.
Context diff of a working version is below. I've
only tested the PortableUnixMailbox code.
Andrew
dalke@dalkescientific.com
Index: mailbox.py
=======================================================
============
RCS
file: /cvsroot/python/python/dist/src/Lib/mailbox.py,v
retrieving revision 1.32
diff -c -r1.32 mailbox.py
*** mailbox.py 2001/08/13 15:37:02 1.32
--- mailbox.py 2001/09/13 00:38:51
***************
*** 15,21 ****
self.factory = factory
def __iter__(self):
! return self
def next(self):
while 1:
--- 15,21 ----
self.factory = factory
def __iter__(self):
! return iter(self.next, None)
def next(self):
while 1:
***************
*** 195,201 ****
self.factory = factory
def __iter__(self):
! return self
def next(self):
if not self.boxes:
--- 195,201 ----
self.factory = factory
def __iter__(self):
! return iter(self.next, None)
def next(self):
if not self.boxes:
***************
*** 226,232 ****
self.boxes = boxes
def __iter__(self):
! return self
def next(self):
if not self.boxes:
--- 226,232 ----
self.boxes = boxes
def __iter__(self):
! return iter(self.next, None)
def next(self):
if not self.boxes:
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=461073&group_id=5470