[Python-checkins] r85701 - python/branches/py3k/Modules/zipimport.c

victor.stinner python-checkins at python.org
Mon Oct 18 23:21:02 CEST 2010


Author: victor.stinner
Date: Mon Oct 18 23:21:02 2010
New Revision: 85701

Log:
zipimport: fix "can't find module ..." error message

I cannot use %U: fullname is a bytes object, not an unicode object. %A format
cannot be used, it adds 'b' (bytes) prefix. So create cant_find_module()
function to decode the filename and raise the error message.


Modified:
   python/branches/py3k/Modules/zipimport.c

Modified: python/branches/py3k/Modules/zipimport.c
==============================================================================
--- python/branches/py3k/Modules/zipimport.c	(original)
+++ python/branches/py3k/Modules/zipimport.c	Mon Oct 18 23:21:02 2010
@@ -399,6 +399,20 @@
     return modpath;
 }
 
+static void
+cant_find_module(PyObject *bytes)
+{
+    PyObject *unicode = PyUnicode_DecodeFSDefaultAndSize(
+        PyBytes_AS_STRING(bytes), PyBytes_GET_SIZE(bytes));
+    if (unicode != NULL) {
+        PyErr_Format(ZipImportError, "can't find module %U",
+                     unicode);
+        Py_DECREF(unicode);
+    }
+    else
+        PyErr_Format(ZipImportError, "can't find module");
+}
+
 /* Return a bool signifying whether the module is a package or not. */
 static PyObject *
 zipimporter_is_package(PyObject *obj, PyObject *args)
@@ -415,8 +429,7 @@
     if (mi == MI_ERROR)
         goto error;
     if (mi == MI_NOT_FOUND) {
-        PyErr_Format(ZipImportError, "can't find module '%.200U'",
-                     fullname);
+        cant_find_module(fullname);
         goto error;
     }
     Py_DECREF(fullname);
@@ -511,8 +524,7 @@
         return NULL;
     }
     if (mi == MI_NOT_FOUND) {
-        PyErr_Format(ZipImportError, "can't find module '%.200U'",
-                     fullname);
+        cant_find_module(fullname);
         Py_DECREF(fullname);
         return NULL;
     }


More information about the Python-checkins mailing list