summaryrefslogtreecommitdiffstats
path: root/Lib/bz2.py
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2011-11-30 15:39:30 (GMT)
committerNadeem Vawda <nadeem.vawda@gmail.com>2011-11-30 15:39:30 (GMT)
commit44ae4a2a22e00b1714d7fb6aff335d437cbb48bf (patch)
tree533ed9cf454e3951edcaf5c0814bf66ba2ed9127 /Lib/bz2.py
parent3ff069ebc6884c46c3f99ea61919f7728708c571 (diff)
downloadcpython-44ae4a2a22e00b1714d7fb6aff335d437cbb48bf.zip
cpython-44ae4a2a22e00b1714d7fb6aff335d437cbb48bf.tar.gz
cpython-44ae4a2a22e00b1714d7fb6aff335d437cbb48bf.tar.bz2
Make error handling in BZ2File.{readable,seekable,writable,fileno} consistent with TextIOWrapper.
Also, add tests for these methods.
Diffstat (limited to 'Lib/bz2.py')
-rw-r--r--Lib/bz2.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/Lib/bz2.py b/Lib/bz2.py
index cbf5233..5c59a9e 100644
--- a/Lib/bz2.py
+++ b/Lib/bz2.py
@@ -125,6 +125,7 @@ class BZ2File(io.BufferedIOBase):
def fileno(self):
"""Return the file descriptor for the underlying file."""
+ self._check_not_closed()
return self._fp.fileno()
def seekable(self):
@@ -133,10 +134,12 @@ class BZ2File(io.BufferedIOBase):
def readable(self):
"""Return whether the file was opened for reading."""
+ self._check_not_closed()
return self._mode in (_MODE_READ, _MODE_READ_EOF)
def writable(self):
"""Return whether the file was opened for writing."""
+ self._check_not_closed()
return self._mode == _MODE_WRITE
# Mode-checking helper functions.
@@ -147,17 +150,14 @@ class BZ2File(io.BufferedIOBase):
def _check_can_read(self):
if not self.readable():
- self._check_not_closed()
raise io.UnsupportedOperation("File not open for reading")
def _check_can_write(self):
if not self.writable():
- self._check_not_closed()
raise io.UnsupportedOperation("File not open for writing")
def _check_can_seek(self):
if not self.seekable():
- self._check_not_closed()
raise io.UnsupportedOperation("Seeking is only supported "
"on files open for reading")