From: Nadeem Vawda Date: Sun, 30 Sep 2012 21:58:01 +0000 (+0200) Subject: Issue #16304: Further performance improvements for BZ2File. X-Git-Tag: v3.4.0a1~2432^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b7a0bfe912f203468e67f0541a365a4cc41a7cb2;p=python Issue #16304: Further performance improvements for BZ2File. Optimizations suggested by Serhiy Storchaka. --- diff --git a/Lib/bz2.py b/Lib/bz2.py index fe4118f9a7..37918a8b53 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():