A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-August/068005.html below:

[Python-Dev] BZ2File.writelines should raise more meaningful exceptions

[Python-Dev] BZ2File.writelines should raise more meaningful exceptionsLawrence Oluyede l.oluyede at gmail.com
Sun Aug 6 10:41:39 CEST 2006
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
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: bz2module.diff.txt
Url: http://mail.python.org/pipermail/python-dev/attachments/20060806/bd63dc42/attachment.txt 
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4