Commit 53ffdc53 authored by Victor Stinner's avatar Victor Stinner

Issue #7732: Don't open a directory as a file anymore while importing a

module. Ignore the direcotry if its name matchs the module name (e.g.
"__init__.py") and raise a ImportError instead.
parent da6eb530
...@@ -139,6 +139,15 @@ class ImportTests(unittest.TestCase): ...@@ -139,6 +139,15 @@ class ImportTests(unittest.TestCase):
self.assertIs(orig_path, new_os.path) self.assertIs(orig_path, new_os.path)
self.assertIsNot(orig_getenv, new_os.getenv) self.assertIsNot(orig_getenv, new_os.getenv)
def test_bug7732(self):
source = TESTFN + '.py'
os.mkdir(source)
try:
self.assertRaisesRegex(ImportError, '^No module',
imp.find_module, TESTFN, ["."])
finally:
os.rmdir(source)
def test_module_with_large_stack(self, module='longlist'): def test_module_with_large_stack(self, module='longlist'):
# Regression test for http://bugs.python.org/issue561858. # Regression test for http://bugs.python.org/issue561858.
filename = module + '.py' filename = module + '.py'
......
...@@ -10,6 +10,10 @@ What's New in Python 3.2.3? ...@@ -10,6 +10,10 @@ What's New in Python 3.2.3?
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #7732: Don't open a directory as a file anymore while importing a
module. Ignore the direcotry if its name matchs the module name (e.g.
"__init__.py") and raise a ImportError instead.
- Issue #13021: Missing decref on an error path. Thanks to Suman Saha for - Issue #13021: Missing decref on an error path. Thanks to Suman Saha for
finding the bug and providing a patch. finding the bug and providing a patch.
...@@ -77,7 +81,7 @@ Tests ...@@ -77,7 +81,7 @@ Tests
Extension Modules Extension Modules
----------------- -----------------
- Issue #13022: Fix: _multiprocessing.recvfd() doesn't check that - Issue #13022: Fix: _multiprocessing.recvfd() doesn't check that
file descriptor was actually received. file descriptor was actually received.
......
...@@ -1763,6 +1763,7 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf, ...@@ -1763,6 +1763,7 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
saved_namelen = namelen; saved_namelen = namelen;
#endif /* PYOS_OS2 */ #endif /* PYOS_OS2 */
for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) { for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) {
struct stat statbuf;
#if defined(PYOS_OS2) && defined(HAVE_DYNAMIC_LOADING) #if defined(PYOS_OS2) && defined(HAVE_DYNAMIC_LOADING)
/* OS/2 limits DLLs to 8 character names (w/o /* OS/2 limits DLLs to 8 character names (w/o
extension) extension)
...@@ -1791,10 +1792,16 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf, ...@@ -1791,10 +1792,16 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
strcpy(buf+len, fdp->suffix); strcpy(buf+len, fdp->suffix);
if (Py_VerboseFlag > 1) if (Py_VerboseFlag > 1)
PySys_WriteStderr("# trying %s\n", buf); PySys_WriteStderr("# trying %s\n", buf);
filemode = fdp->mode; filemode = fdp->mode;
if (filemode[0] == 'U') if (filemode[0] == 'U')
filemode = "r" PY_STDIOTEXTMODE; filemode = "r" PY_STDIOTEXTMODE;
fp = fopen(buf, filemode);
if (stat(buf, &statbuf) == 0 && S_ISDIR(statbuf.st_mode))
/* it's a directory */
fp = NULL;
else
fp = fopen(buf, filemode);
if (fp != NULL) { if (fp != NULL) {
if (case_ok(buf, len, namelen, name)) if (case_ok(buf, len, namelen, name))
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment