[Python-checkins] r68014 - in python/trunk: Lib/test/test_file.py Misc/NEWS Objects/fileobject.c

benjamin.peterson python-checkins at python.org
Mon Dec 29 18:47:43 CET 2008


Author: benjamin.peterson
Date: Mon Dec 29 18:47:42 2008
New Revision: 68014

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

Modified:
   python/trunk/Lib/test/test_file.py
   python/trunk/Misc/NEWS
   python/trunk/Objects/fileobject.c

Modified: python/trunk/Lib/test/test_file.py
==============================================================================
--- python/trunk/Lib/test/test_file.py	(original)
+++ python/trunk/Lib/test/test_file.py	Mon Dec 29 18:47:42 2008
@@ -125,6 +125,19 @@
 
 class OtherFileTests(unittest.TestCase):
 
+    def testOpenDir(self):
+        this_dir = os.path.dirname(__file__)
+        for mode in (None, "w"):
+            try:
+                if mode:
+                    f = open(this_dir, mode)
+                else:
+                    f = open(this_dir)
+            except IOError as e:
+                self.assertEqual(e.filename, this_dir)
+            else:
+                self.fail("opening a directory didn't raise an IOError")
+
     def testModeStrings(self):
         # check invalid mode strings
         for mode in ("", "aU", "wU+"):

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Mon Dec 29 18:47:42 2008
@@ -12,6 +12,9 @@
 Core and Builtins
 -----------------
 
+- Issue #4764: IOError.filename is set when trying to open a directory on POSIX
+  systems.
+
 - Issue #4759: None is now allowed as the first argument of
   bytearray.translate().  It was always allowed for bytes.translate().
 

Modified: python/trunk/Objects/fileobject.c
==============================================================================
--- python/trunk/Objects/fileobject.c	(original)
+++ python/trunk/Objects/fileobject.c	Mon Dec 29 18:47:42 2008
@@ -132,8 +132,8 @@
 	if (fstat(fileno(f->f_fp), &buf) == 0 &&
 	    S_ISDIR(buf.st_mode)) {
 		char *msg = strerror(EISDIR);
-		PyObject *exc = PyObject_CallFunction(PyExc_IOError, "(is)",
-						      EISDIR, msg);
+		PyObject *exc = PyObject_CallFunction(PyExc_IOError, "(isO)",
+						      EISDIR, msg, f->f_name);
 		PyErr_SetObject(PyExc_IOError, exc);
 		Py_XDECREF(exc);
 		return NULL;


More information about the Python-checkins mailing list