summaryrefslogtreecommitdiffstats
path: root/Lib/bz2.py
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2012-09-30 21:58:01 (GMT)
committerNadeem Vawda <nadeem.vawda@gmail.com>2012-09-30 21:58:01 (GMT)
commitb7a0bfe912f203468e67f0541a365a4cc41a7cb2 (patch)
tree03311b58e9ec75237a34d02685d6ae9ae2848db9 /Lib/bz2.py
parentd2489cf4d0616c51fc70789d5eb2df94c9e5a94a (diff)
downloadcpython-b7a0bfe912f203468e67f0541a365a4cc41a7cb2.zip
cpython-b7a0bfe912f203468e67f0541a365a4cc41a7cb2.tar.gz
cpython-b7a0bfe912f203468e67f0541a365a4cc41a7cb2.tar.bz2
Issue #16304: Further performance improvements for BZ2File.
Optimizations suggested by Serhiy Storchaka.
Diffstat (limited to 'Lib/bz2.py')
-rw-r--r--Lib/bz2.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/Lib/bz2.py b/Lib/bz2.py
index fe4118f..37918a8 100644
--- a/Lib/bz2.py
+++ b/Lib/bz2.py
@@ -159,15 +159,21 @@ class BZ2File(io.BufferedIOBase):
raise ValueError("I/O operation on closed file")
def _check_can_read(self):
- if not self.readable():
+ if self.closed:
+ raise ValueError("I/O operation on closed file")
+ if self._mode not in (_MODE_READ, _MODE_READ_EOF):
raise io.UnsupportedOperation("File not open for reading")
def _check_can_write(self):
- if not self.writable():
+ if self.closed:
+ raise ValueError("I/O operation on closed file")
+ if self._mode != _MODE_WRITE:
raise io.UnsupportedOperation("File not open for writing")
def _check_can_seek(self):
- if not self.readable():
+ if self.closed:
+ raise ValueError("I/O operation on closed file")
+ if self._mode not in (_MODE_READ, _MODE_READ_EOF):
raise io.UnsupportedOperation("Seeking is only supported "
"on files open for reading")
if not self._fp.seekable():