]> granicus.if.org Git - python/commitdiff
Issue #16304: Another performance optimization for BZ2File.
authorNadeem Vawda <nadeem.vawda@gmail.com>
Mon, 1 Oct 2012 21:02:50 +0000 (23:02 +0200)
committerNadeem Vawda <nadeem.vawda@gmail.com>
Mon, 1 Oct 2012 21:02:50 +0000 (23:02 +0200)
Patch by Serhiy Storchaka.

Lib/bz2.py

index 37918a8b536760560b1c1e88967f10d47706eef5..87bed214d0a7bd500a2e1d51fc4230a3b3c6072c 100644 (file)
@@ -159,21 +159,18 @@ class BZ2File(io.BufferedIOBase):
             raise ValueError("I/O operation on closed file")
 
     def _check_can_read(self):
-        if self.closed:
-            raise ValueError("I/O operation on closed file")
         if self._mode not in (_MODE_READ, _MODE_READ_EOF):
+            self._check_not_closed()
             raise io.UnsupportedOperation("File not open for reading")
 
     def _check_can_write(self):
-        if self.closed:
-            raise ValueError("I/O operation on closed file")
         if self._mode != _MODE_WRITE:
+            self._check_not_closed()
             raise io.UnsupportedOperation("File not open for writing")
 
     def _check_can_seek(self):
-        if self.closed:
-            raise ValueError("I/O operation on closed file")
         if self._mode not in (_MODE_READ, _MODE_READ_EOF):
+            self._check_not_closed()
             raise io.UnsupportedOperation("Seeking is only supported "
                                           "on files open for reading")
         if not self._fp.seekable():