]> granicus.if.org Git - python/commitdiff
Merged revisions 83030 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Wed, 21 Jul 2010 16:47:28 +0000 (16:47 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Wed, 21 Jul 2010 16:47:28 +0000 (16:47 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r83030 | antoine.pitrou | 2010-07-21 18:41:31 +0200 (mer., 21 juil. 2010) | 5 lines

  Issue #5395: check that array.fromfile() re-raises an IOError instead of replacing it
  with EOFError.
  (this is only an added test, but 2.x will get a fix too)
........

Lib/test/test_array.py
Misc/ACKS
Misc/NEWS
Modules/arraymodule.c

index 6a573e1000b9a44c7105bbe73097558437b1c5b8..a4aeccf695ce0315376b962b87ae762ba28acd3a 100755 (executable)
@@ -188,6 +188,17 @@ class BaseTest(unittest.TestCase):
                 f.close()
             test_support.unlink(test_support.TESTFN)
 
+    def test_fromfile_ioerror(self):
+        # Issue #5395: Check if fromfile raises a proper IOError
+        # instead of EOFError.
+        a = array.array(self.typecode)
+        f = open(test_support.TESTFN, 'wb')
+        try:
+            self.assertRaises(IOError, a.fromfile, f, len(self.example))
+        finally:
+            f.close()
+            test_support.unlink(test_support.TESTFN)
+
     def test_filewrite(self):
         a = array.array(self.typecode, 2*self.example)
         f = open(test_support.TESTFN, 'wb')
index a302c91a597a665ce5bba57271822e7ea78f493b..bd2fb9802a4b3ae5fab494ac95717063c23abab1 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -355,6 +355,7 @@ Michiel de Hoon
 Brian Hooper
 Randall Hopper
 Nadav Horesh
+Jan Hosang
 Ken Howard
 Brad Howes
 Chih-Hao Huang
index 45f81c39ca761ed70c7119c2df54e6a67605200b..979d35ab9acc7d6d2ae8af61ecac876647db86d4 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -18,6 +18,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #5395: array.fromfile() would raise a spurious EOFError when an
+  I/O error occurred.  Now an IOError is raised instead.  Patch by chuck
+  (Jan Hosang).
+
 - Issue 1712522: urllib.quote supports Unicode String with encoding and errors
   parameter. The encoding parameter defaults to utf-8 and errors to strict.
   Patch by Matt Giuca.
index 403f646cfa354f70bb3e64d0e0621279fcbe2c88..5b37896a14fc122deb0a3ce26fa74d33f5185a84 100644 (file)
@@ -1228,8 +1228,14 @@ array_fromfile(arrayobject *self, PyObject *args)
             PyMem_RESIZE(item, char, Py_SIZE(self)*itemsize);
             self->ob_item = item;
             self->allocated = Py_SIZE(self);
-            PyErr_SetString(PyExc_EOFError,
-                             "not enough items in file");
+            if (ferror(fp)) {
+                PyErr_SetFromErrno(PyExc_IOError);
+                clearerr(fp);
+            }
+            else {
+                PyErr_SetString(PyExc_EOFError,
+                                "not enough items in file");
+            }
             return NULL;
         }
     }