[Patches] [ python-Patches-1535500 ] writelines() in bz2 module does not raise check for errors

SourceForge.net noreply at sourceforge.net
Mon Aug 14 23:46:13 CEST 2006


Patches item #1535500, was opened at 2006-08-06 19:32
Message generated for change (Comment added) made by gbrandl
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1535500&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Modules
Group: Python 2.5
>Status: Closed
>Resolution: Accepted
Priority: 5
Submitted By: Lawrence Oluyede (rhymes)
Assigned to: Nobody/Anonymous (nobody)
Summary: writelines() in bz2 module does not raise check for errors

Initial Comment:
In the BZ2File object of bz2 module the writelines()
method does not
check its closed state before doing the actual work so
its behavior
it's different from write()'s behavior. See:

>>> from bz2 import BZ2File
>>> f = BZ2File("foo", "w")
>>> f.close()
>>> f.closed
1
>>> f.write("foobar")
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
ValueError: I/O operation on closed file
>>> f.closed
1
>>> f.writelines(["foobar"])
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
IOError: unknown IO error

It also doesn't check if it can write for real:

>>> from bz2 import BZ2File
>>> f = BZ2File("foo", "r")
>>> f.write("foobar")
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
IOError: file is not ready for writing
>>> f.writelines(['foobar'])
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
RuntimeError: wrong sequence of bz2 library commands used

----------------------------------------------------------------------

>Comment By: Georg Brandl (gbrandl)
Date: 2006-08-14 21:46

Message:
Logged In: YES 
user_id=849994

Thanks for the patch, this has been fixed in rev.
51285--51288. (The first example actually segfaulted here!)

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1535500&group_id=5470


More information about the Patches mailing list