diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-09-23 18:59:08 +0200 |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-09-23 18:59:08 +0200 |
commit | 8a0b746bdeb8eaff8f47949c6f72811936d8ea5f (patch) | |
tree | c7a1a9ae5452641319f6e85f57bf26ea04e298ee /Python | |
parent | 91a90f1cdf9caf1bb5f5c47e41821c2bd6a07350 (diff) | |
parent | bec278946d5b2e0b0b2ea661cbfdaf86fc996f9c (diff) | |
download | cpython-8a0b746bdeb8eaff8f47949c6f72811936d8ea5f.tar.gz |
Merge 3.2: 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.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/import.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Python/import.c b/Python/import.c index adfd2cc5df..24df985d46 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1892,6 +1892,8 @@ find_module_path_list(PyObject *fullname, PyObject *name, } for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) { + struct stat statbuf; + filemode = fdp->mode; if (filemode[0] == 'U') filemode = "r" PY_STDIOTEXTMODE; @@ -1905,6 +1907,13 @@ find_module_path_list(PyObject *fullname, PyObject *name, if (Py_VerboseFlag > 1) PySys_FormatStderr("# trying %R\n", filename); + if (_Py_stat(filename, &statbuf) == 0 && /* it exists */ + S_ISDIR(statbuf.st_mode)) /* it's a directory */ + { + Py_DECREF(filename); + continue; + } + fp = _Py_fopen(filename, filemode); if (fp == NULL) { Py_DECREF(filename); |