From b7a0bfe912f203468e67f0541a365a4cc41a7cb2 Mon Sep 17 00:00:00 2001 From: Nadeem Vawda Date: Sun, 30 Sep 2012 23:58:01 +0200 Subject: Issue #16304: Further performance improvements for BZ2File. Optimizations suggested by Serhiy Storchaka. --- Lib/bz2.py | 12 +++++++++--- 1 file 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(): -- cgit v0.12