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')
Brian Hooper
Randall Hopper
Nadav Horesh
+Jan Hosang
Ken Howard
Brad Howes
Chih-Hao Huang
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.
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;
}
}