[Python-checkins] r68016 - in python/trunk: Lib/test/test_fileio.py Misc/NEWS Modules/_fileio.c

benjamin.peterson python-checkins at python.org
Mon Dec 29 18:56:58 CET 2008


Author: benjamin.peterson
Date: Mon Dec 29 18:56:58 2008
New Revision: 68016

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

Modified:
   python/trunk/Lib/test/test_fileio.py
   python/trunk/Misc/NEWS
   python/trunk/Modules/_fileio.c

Modified: python/trunk/Lib/test/test_fileio.py
==============================================================================
--- python/trunk/Lib/test/test_fileio.py	(original)
+++ python/trunk/Lib/test/test_fileio.py	Mon Dec 29 18:56:58 2008
@@ -109,6 +109,7 @@
             _fileio._FileIO('.', 'r')
         except IOError as e:
             self.assertNotEqual(e.errno, 0)
+            self.assertEqual(e.filename, ".")
         else:
             self.fail("Should have raised IOError")
 

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Mon Dec 29 18:56:58 2008
@@ -12,6 +12,9 @@
 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.
 

Modified: python/trunk/Modules/_fileio.c
==============================================================================
--- python/trunk/Modules/_fileio.c	(original)
+++ python/trunk/Modules/_fileio.c	Mon Dec 29 18:56:58 2008
@@ -98,7 +98,7 @@
    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 @@
 		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 @@
 #endif
 			goto error;
 		}
-		if(dircheck(self) < 0)
+		if(dircheck(self, name) < 0)
 			goto error;
 	}
 


More information about the Python-checkins mailing list