This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: writelines() in bz2 module does not raise check for errors
Type: Stage:
Components: Extension Modules Versions: Python 2.5
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, rhymes
Priority: normal Keywords: patch

Created on 2006-08-06 19:32 by rhymes, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bz2module_writelines.diff rhymes, 2006-08-06 19:32
Messages (2)
msg50835 - (view) Author: Lawrence Oluyede (rhymes) Date: 2006-08-06 19:32
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
msg50836 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-08-14 21:46
Logged In: YES 
user_id=849994

Thanks for the patch, this has been fixed in rev.
51285--51288. (The first example actually segfaulted here!)
History
Date User Action Args
2022-04-11 14:56:19adminsetgithub: 43785
2006-08-06 19:32:28rhymescreate