summaryrefslogtreecommitdiffstats
path: root/Modules/zipimport.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-10-18 21:21:02 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-10-18 21:21:02 (GMT)
commit8c8ed0a799b41636327bc2950ed8c00d741be97d (patch)
tree281fe3d0731d7beb5eb10eaf068c48f881aec4ed /Modules/zipimport.c
parent9a90900da59816b4d376c47b94b5513b849db070 (diff)
downloadcpython-8c8ed0a799b41636327bc2950ed8c00d741be97d.zip
cpython-8c8ed0a799b41636327bc2950ed8c00d741be97d.tar.gz
cpython-8c8ed0a799b41636327bc2950ed8c00d741be97d.tar.bz2
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.
Diffstat (limited to 'Modules/zipimport.c')
-rw-r--r--Modules/zipimport.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index c943a41..b59fd50 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -399,6 +399,20 @@ zipimporter_get_filename(PyObject *obj, PyObject *args)
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 @@ zipimporter_is_package(PyObject *obj, PyObject *args)
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 @@ zipimporter_get_source(PyObject *obj, PyObject *args)
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;
}