[Python-checkins] cpython (merge 3.3 -> default): Merge: #16304: Further performance improvements for BZ2File.

nadeem.vawda python-checkins at python.org
Mon Oct 1 00:05:34 CEST 2012


http://hg.python.org/cpython/rev/abb5c5bde872
changeset:   79350:abb5c5bde872
parent:      79348:5876a24b613a
parent:      79349:4258248a44c7
user:        Nadeem Vawda <nadeem.vawda at gmail.com>
date:        Mon Oct 01 00:04:46 2012 +0200
summary:
  Merge: #16304: Further performance improvements for BZ2File.

Optimizations suggested by Serhiy Storchaka.

files:
  Lib/bz2.py |  12 +++++++++---
  1 files changed, 9 insertions(+), 3 deletions(-)


diff --git a/Lib/bz2.py b/Lib/bz2.py
--- a/Lib/bz2.py
+++ b/Lib/bz2.py
@@ -159,15 +159,21 @@
             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():

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list