Index: Python/import.c =================================================================== --- Python/import.c (revision 58883) +++ Python/import.c (working copy) @@ -2918,6 +2918,11 @@ PyObject_HEAD } NullImporter; +#ifdef MS_WINDOWS +/* Cached os.path import for NullImporter_init() */ +static PyObject *nullimporter_ospath = NULL; +#endif + static int NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds) { @@ -2936,8 +2941,36 @@ } else { struct stat statbuf; int rv; +#ifdef MS_WINDOWS + /* normalize the path on Windows. Windows's stat doesn't like trailing + * slashes and backslashes. I'm leaking one reference of os.path to + * avoid an import dead lock. + */ + PyObject *r; + char *mangled; + if (nullimporter_ospath == NULL) { + nullimporter_ospath = PyImport_ImportModule("os.path"); + if (nullimporter_ospath == NULL) { + return -1; + } + } + + r = PyObject_CallMethod(nullimporter_ospath, "normpath", "s", path); + if (r == NULL) { + return -1; + } + + mangled = PyString_AsString(r); + if (mangled == NULL) { + return -1; + } + + rv = stat(mangled, &statbuf); + Py_DECREF(r); +#else rv = stat(path, &statbuf); +#endif if (rv == 0) { /* it exists */ if (S_ISDIR(statbuf.st_mode)) {