diff options
author | Nadeem Vawda <nadeem.vawda@gmail.com> | 2012-09-30 21:58:01 (GMT) |
---|---|---|
committer | Nadeem Vawda <nadeem.vawda@gmail.com> | 2012-09-30 21:58:01 (GMT) |
commit | b7a0bfe912f203468e67f0541a365a4cc41a7cb2 (patch) | |
tree | 03311b58e9ec75237a34d02685d6ae9ae2848db9 | |
parent | d2489cf4d0616c51fc70789d5eb2df94c9e5a94a (diff) | |
download | cpython-b7a0bfe912f203468e67f0541a365a4cc41a7cb2.zip cpython-b7a0bfe912f203468e67f0541a365a4cc41a7cb2.tar.gz cpython-b7a0bfe912f203468e67f0541a365a4cc41a7cb2.tar.bz2 |
Issue #16304: Further performance improvements for BZ2File.
Optimizations suggested by Serhiy Storchaka.
-rw-r--r-- | Lib/bz2.py | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -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(): |