]> granicus.if.org Git - python/commitdiff
Issue #12175: FileIO.readall() now raises a ValueError instead of an IOError if
authorVictor Stinner <victor.stinner@haypocalc.com>
Wed, 25 May 2011 20:15:36 +0000 (22:15 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Wed, 25 May 2011 20:15:36 +0000 (22:15 +0200)
the file is closed.

Lib/test/test_io.py
Misc/NEWS
Modules/_io/fileio.c

index 8af8a6462247e96f3cffb2f3685aae61f088663b..9b18b70488f7bd1487d2febfe17c0ed832316f09 100644 (file)
@@ -2468,6 +2468,8 @@ class MiscIOTest(unittest.TestCase):
             self.assertRaises(ValueError, f.read)
             if hasattr(f, "read1"):
                 self.assertRaises(ValueError, f.read1, 1024)
+            if hasattr(f, "readall"):
+                self.assertRaises(ValueError, f.readall)
             if hasattr(f, "readinto"):
                 self.assertRaises(ValueError, f.readinto, bytearray(1024))
             self.assertRaises(ValueError, f.readline)
index 6801fd7084a2a8e7430da1d3e9a26fcf49c2d84a..e6fdfa4e15516084c6d9b4cfc9a8ee89a583fd3b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -83,6 +83,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #12175: FileIO.readall() now raises a ValueError instead of an IOError
+  if the file is closed.
+
 - Issue #1441530: In imaplib, use makefile() to wrap the SSL socket to avoid
   heap fragmentation and MemoryError with some malloc implementations.
 
index 83921eaae780e5d2e69de210a362d962e9a22f6e..25a0c27914d6ff5900939ba5cb851b532b18ba0b 100644 (file)
@@ -539,6 +539,8 @@ fileio_readall(fileio *self)
     Py_ssize_t total = 0;
     int n;
 
+    if (self->fd < 0)
+        return err_closed();
     if (!_PyVerify_fd(self->fd))
         return PyErr_SetFromErrno(PyExc_IOError);