summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-12-29 17:47:42 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-12-29 17:47:42 (GMT)
commitfe231b07e41e8cfba8fb79e8440580c37e85183e (patch)
treef853a3113cab0f98737ca323007d75cce9bda8d6
parent732479f50b46d4df153e178f844ad876e7f63bd8 (diff)
downloadcpython-fe231b07e41e8cfba8fb79e8440580c37e85183e.zip
cpython-fe231b07e41e8cfba8fb79e8440580c37e85183e.tar.gz
cpython-fe231b07e41e8cfba8fb79e8440580c37e85183e.tar.bz2
#4764 set IOError.filename when trying to open a directory on POSIX platforms
-rw-r--r--Lib/test/test_file.py13
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/fileobject.c4
3 files changed, 18 insertions, 2 deletions
diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py
index 96f6da2..b4f494b 100644
--- a/Lib/test/test_file.py
+++ b/Lib/test/test_file.py
@@ -125,6 +125,19 @@ class AutoFileTests(unittest.TestCase):
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+"):
diff --git a/Misc/NEWS b/Misc/NEWS
index a5b3d2d..c315af0 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.7 alpha 1
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().
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index b2051d7..e01f38e 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -132,8 +132,8 @@ dircheck(PyFileObject* f)
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;