[Python-checkins] cpython (merge default -> default): Merge

antoine.pitrou python-checkins at python.org
Mon Oct 1 23:45:52 CEST 2012


http://hg.python.org/cpython/rev/5dbefa6d6a94
changeset:   79388:5dbefa6d6a94
parent:      79386:9fb0a8fc5d79
parent:      79384:112103a4241a
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Mon Oct 01 23:44:19 2012 +0200
summary:
  Merge

files:
  Lib/bz2.py                       |  24 ++++++++++----------
  Lib/test/test_threaded_import.py |   4 +--
  2 files changed, 13 insertions(+), 15 deletions(-)


diff --git a/Lib/bz2.py b/Lib/bz2.py
--- a/Lib/bz2.py
+++ b/Lib/bz2.py
@@ -159,21 +159,18 @@
             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():
@@ -322,10 +319,12 @@
         non-negative, no more than size bytes will be read (in which
         case the line may be incomplete). Returns b'' if already at EOF.
         """
-        if not hasattr(size, "__index__"):
-            raise TypeError("Integer argument expected")
-        size = size.__index__()
+        if not isinstance(size, int):
+            if not hasattr(size, "__index__"):
+                raise TypeError("Integer argument expected")
+            size = size.__index__()
         with self._lock:
+            self._check_can_read()
             # Shortcut for the common case - the whole line is in the buffer.
             if size < 0:
                 end = self._buffer.find(b"\n", self._buffer_offset) + 1
@@ -343,9 +342,10 @@
         further lines will be read once the total size of the lines read
         so far equals or exceeds size.
         """
-        if not hasattr(size, "__index__"):
-            raise TypeError("Integer argument expected")
-        size = size.__index__()
+        if not isinstance(size, int):
+            if not hasattr(size, "__index__"):
+                raise TypeError("Integer argument expected")
+            size = size.__index__()
         with self._lock:
             return io.BufferedIOBase.readlines(self, size)
 
diff --git a/Lib/test/test_threaded_import.py b/Lib/test/test_threaded_import.py
--- a/Lib/test/test_threaded_import.py
+++ b/Lib/test/test_threaded_import.py
@@ -225,11 +225,9 @@
 @reap_threads
 def test_main():
     old_switchinterval = None
-    # Issue #15599: FreeBSD/KVM cannot handle gil_interval == 1.
-    new_switchinterval = 0.00001 if 'freebsd' in sys.platform else 0.00000001
     try:
         old_switchinterval = sys.getswitchinterval()
-        sys.setswitchinterval(new_switchinterval)
+        sys.setswitchinterval(1e-5)
     except AttributeError:
         pass
     try:

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


More information about the Python-checkins mailing list