Christian Heimes added the comment:

Another patch that uses os.path.normpath.

Added file: http://bugs.python.org/file8704/trailing_slash3.patch

__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1293>
__________________________________
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)) {
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to