#4764 in io.open, set IOError.filename when trying to open a directory on POSIX platforms

This commit is contained in:
Benjamin Peterson 2008-12-29 17:56:58 +00:00
parent fe231b07e4
commit 7af65568ff
3 changed files with 8 additions and 4 deletions

View File

@ -109,6 +109,7 @@ class AutoFileTests(unittest.TestCase):
_fileio._FileIO('.', 'r') _fileio._FileIO('.', 'r')
except IOError as e: except IOError as e:
self.assertNotEqual(e.errno, 0) self.assertNotEqual(e.errno, 0)
self.assertEqual(e.filename, ".")
else: else:
self.fail("Should have raised IOError") self.fail("Should have raised IOError")

View File

@ -12,6 +12,9 @@ What's New in Python 2.7 alpha 1
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #4764: With io.open, IOError.filename is set when trying to open a
directory on POSIX systems.
- Issue #4764: IOError.filename is set when trying to open a directory on POSIX - Issue #4764: IOError.filename is set when trying to open a directory on POSIX
systems. systems.

View File

@ -98,7 +98,7 @@ fileio_new(PyTypeObject *type, PyObject *args, PyObject *kews)
directories, so we need a check. */ directories, so we need a check. */
static int static int
dircheck(PyFileIOObject* self) dircheck(PyFileIOObject* self, char *name)
{ {
#if defined(HAVE_FSTAT) && defined(S_IFDIR) && defined(EISDIR) #if defined(HAVE_FSTAT) && defined(S_IFDIR) && defined(EISDIR)
struct stat buf; struct stat buf;
@ -109,8 +109,8 @@ dircheck(PyFileIOObject* self)
PyObject *exc; PyObject *exc;
internal_close(self); internal_close(self);
exc = PyObject_CallFunction(PyExc_IOError, "(is)", exc = PyObject_CallFunction(PyExc_IOError, "(iss)",
EISDIR, msg); EISDIR, msg, name);
PyErr_SetObject(PyExc_IOError, exc); PyErr_SetObject(PyExc_IOError, exc);
Py_XDECREF(exc); Py_XDECREF(exc);
return -1; return -1;
@ -271,7 +271,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
#endif #endif
goto error; goto error;
} }
if(dircheck(self) < 0) if(dircheck(self, name) < 0)
goto error; goto error;
} }