diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-09-23 16:59:08 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-09-23 16:59:08 (GMT) |
commit | a1fe1f8dcfd43059c38b1493ec67af06fd2afe7f (patch) | |
tree | e6998aa6681a95508a4f4f6dafd9aef6f9d43ec3 /Python | |
parent | 92c144ee72d4ab488ec0a9d50cb78dc739c68069 (diff) | |
parent | 53ffdc53bf0500e402682d1459a9a8d06573664c (diff) | |
download | cpython-a1fe1f8dcfd43059c38b1493ec67af06fd2afe7f.zip cpython-a1fe1f8dcfd43059c38b1493ec67af06fd2afe7f.tar.gz cpython-a1fe1f8dcfd43059c38b1493ec67af06fd2afe7f.tar.bz2 |
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 adfd2cc..24df985 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); |