[Python-checkins] r66097 - in python/trunk: Lib/test/test_fileio.py Misc/NEWS Modules/_fileio.c
benjamin.peterson
python-checkins at python.org
Mon Sep 1 16:13:43 CEST 2008
Author: benjamin.peterson
Date: Mon Sep 1 16:13:43 2008
New Revision: 66097
Log:
#3703 unhelpful _fileio.FileIO error message when trying to open a directory
Reviewer: Gregory P. Smith
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 Sep 1 16:13:43 2008
@@ -101,6 +101,17 @@
# should raise on closed file
self.assertRaises(ValueError, method)
+ def testOpendir(self):
+ # Issue 3703: opening a directory should fill the errno
+ # Windows always returns "[Errno 13]: Permission denied
+ # Unix calls dircheck() and returns "[Errno 21]: Is a directory"
+ try:
+ _fileio._FileIO('.', 'r')
+ except IOError as e:
+ self.assertNotEqual(e.errno, 0)
+ else:
+ self.fail("Should have raised IOError")
+
class OtherFileTests(unittest.TestCase):
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Mon Sep 1 16:13:43 2008
@@ -52,6 +52,9 @@
- Fixed two format strings in the _collections module.
+- #3703 _fileio.FileIO gave unhelpful error message when trying to open a
+ directory.
+
Extension Modules
-----------------
Modified: python/trunk/Modules/_fileio.c
==============================================================================
--- python/trunk/Modules/_fileio.c (original)
+++ python/trunk/Modules/_fileio.c Mon Sep 1 16:13:43 2008
@@ -262,7 +262,7 @@
#endif
self->fd = open(name, flags, 0666);
Py_END_ALLOW_THREADS
- if (self->fd < 0 || dircheck(self) < 0) {
+ if (self->fd < 0) {
#ifdef MS_WINDOWS
PyErr_SetFromErrnoWithUnicodeFilename(PyExc_IOError, widename);
#else
@@ -270,6 +270,8 @@
#endif
goto error;
}
+ if(dircheck(self) < 0)
+ goto error;
}
goto done;
More information about the Python-checkins
mailing list