BZ2File.writelines should raise more meaningful exceptions
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
The patch is attached. If you think it's ok to fix this I'll post it to the bug tracker -- Lawrence http://www.oluyede.org/blog
On Sun, Aug 06, 2006, Lawrence Oluyede wrote:
The patch is attached. If you think it's ok to fix this I'll post it to the bug tracker
Always post patches -- that way they can't get lost. *THEN* post to python-dev with your analysis and explanation (which you presumably also included with the patch), starting with a link to the patch. -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian W. Kernighan
Always post patches -- that way they can't get lost. *THEN* post to python-dev with your analysis and explanation (which you presumably also included with the patch), starting with a link to the patch.
Thanks for the hint. This is the link: http://sourceforge.net/tracker/index.php?func=detail&aid=1535500&group_id=5470&atid=305470 -- Lawrence http://www.oluyede.org/blog
participants (2)
-
Aahz
-
Lawrence Oluyede