[Python-checkins] r83032 - in python/branches/release26-maint: Lib/test/test_array.py Misc/ACKS Misc/NEWS Modules/arraymodule.c

antoine.pitrou python-checkins at python.org
Wed Jul 21 18:50:53 CEST 2010


Author: antoine.pitrou
Date: Wed Jul 21 18:50:52 2010
New Revision: 83032

Log:
Merged revisions 83031 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/release27-maint

................
  r83031 | antoine.pitrou | 2010-07-21 18:47:28 +0200 (mer., 21 juil. 2010) | 11 lines
  
  Merged revisions 83030 via svnmerge from 
  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)
  ........
................


Modified:
   python/branches/release26-maint/   (props changed)
   python/branches/release26-maint/Lib/test/test_array.py
   python/branches/release26-maint/Misc/ACKS
   python/branches/release26-maint/Misc/NEWS
   python/branches/release26-maint/Modules/arraymodule.c

Modified: python/branches/release26-maint/Lib/test/test_array.py
==============================================================================
--- python/branches/release26-maint/Lib/test/test_array.py	(original)
+++ python/branches/release26-maint/Lib/test/test_array.py	Wed Jul 21 18:50:52 2010
@@ -188,6 +188,17 @@
                 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_tofromlist(self):
         a = array.array(self.typecode, 2*self.example)
         b = array.array(self.typecode)

Modified: python/branches/release26-maint/Misc/ACKS
==============================================================================
--- python/branches/release26-maint/Misc/ACKS	(original)
+++ python/branches/release26-maint/Misc/ACKS	Wed Jul 21 18:50:52 2010
@@ -328,6 +328,7 @@
 Brian Hooper
 Randall Hopper
 Nadav Horesh
+Jan Hosang
 Ken Howard
 Brad Howes
 Chih-Hao Huang

Modified: python/branches/release26-maint/Misc/NEWS
==============================================================================
--- python/branches/release26-maint/Misc/NEWS	(original)
+++ python/branches/release26-maint/Misc/NEWS	Wed Jul 21 18:50:52 2010
@@ -81,6 +81,10 @@
 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 #1555570: email no longer inserts extra blank lines when a \r\n
   combo crosses an 8192 byte boundary.
 

Modified: python/branches/release26-maint/Modules/arraymodule.c
==============================================================================
--- python/branches/release26-maint/Modules/arraymodule.c	(original)
+++ python/branches/release26-maint/Modules/arraymodule.c	Wed Jul 21 18:50:52 2010
@@ -1262,8 +1262,14 @@
             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;
         }
     }


More information about the Python-checkins mailing list