]> granicus.if.org Git - python/commitdiff
#4764 in io.open, set IOError.filename when trying to open a directory on POSIX platforms
authorBenjamin Peterson <benjamin@python.org>
Mon, 29 Dec 2008 17:56:58 +0000 (17:56 +0000)
committerBenjamin Peterson <benjamin@python.org>
Mon, 29 Dec 2008 17:56:58 +0000 (17:56 +0000)
Lib/test/test_fileio.py
Misc/NEWS
Modules/_fileio.c

index c9787795e33aafd696e01c7e1d554d410789f07a..d8cf415ed868748cdd85b8b1e19ca32655372e5f 100644 (file)
@@ -109,6 +109,7 @@ class AutoFileTests(unittest.TestCase):
             _fileio._FileIO('.', 'r')
         except IOError as e:
             self.assertNotEqual(e.errno, 0)
+            self.assertEqual(e.filename, ".")
         else:
             self.fail("Should have raised IOError")
 
index c315af0f5e91ccc46eecb57b6e460a16a12a3a7d..78d97808e480da6ffd87645ea88efe897fc32d79 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.7 alpha 1
 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
   systems.
 
index 65cc99d45a8f3aedbb5f72153eb192b58b7042ab..ca12822e1db043aca5f8b9e5aa4210b6d7cfd6ea 100644 (file)
@@ -98,7 +98,7 @@ fileio_new(PyTypeObject *type, PyObject *args, PyObject *kews)
    directories, so we need a check.  */
 
 static int
-dircheck(PyFileIOObject* self)
+dircheck(PyFileIOObject* self, char *name)
 {
 #if defined(HAVE_FSTAT) && defined(S_IFDIR) && defined(EISDIR)
        struct stat buf;
@@ -109,8 +109,8 @@ dircheck(PyFileIOObject* self)
                PyObject *exc;
                internal_close(self);
 
-               exc = PyObject_CallFunction(PyExc_IOError, "(is)",
-                                           EISDIR, msg);
+               exc = PyObject_CallFunction(PyExc_IOError, "(iss)",
+                                           EISDIR, msg, name);
                PyErr_SetObject(PyExc_IOError, exc);
                Py_XDECREF(exc);
                return -1;
@@ -271,7 +271,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
 #endif
                        goto error;
                }
-               if(dircheck(self) < 0)
+               if(dircheck(self, name) < 0)
                        goto error;
        }