summaryrefslogtreecommitdiffstats
path: root/Modules/zipimport.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-10-18 20:44:08 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-10-18 20:44:08 (GMT)
commit0410656b30df532d18a82e5da201501b76e2b1e3 (patch)
treee9a249c88e617db23aa6806695ea483530a77ff1 /Modules/zipimport.c
parent269aeb7c0d1f092ba0ff20ff44251fd5f4ff87f2 (diff)
downloadcpython-0410656b30df532d18a82e5da201501b76e2b1e3.zip
cpython-0410656b30df532d18a82e5da201501b76e2b1e3.tar.gz
cpython-0410656b30df532d18a82e5da201501b76e2b1e3.tar.bz2
zipimport: find_module(), is_package() and get_source() supports surrogates
Use PyUnicode_FSConverter to support surrogates in the full name.
Diffstat (limited to 'Modules/zipimport.c')
-rw-r--r--Modules/zipimport.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index d58d4fe..c943a41 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -255,13 +255,13 @@ enum zi_module_info {
/* Return some information about a module. */
static enum zi_module_info
-get_module_info(ZipImporter *self, char *fullname)
+get_module_info(ZipImporter *self, PyObject *fullname)
{
char *subname, path[MAXPATHLEN + 1];
int len;
struct st_zip_searchorder *zso;
- subname = get_subname(fullname);
+ subname = get_subname(PyBytes_AS_STRING(fullname));
len = make_filename(self->prefix, subname, path, sizeof(path));
if (len < 0)
@@ -286,14 +286,15 @@ zipimporter_find_module(PyObject *obj, PyObject *args)
{
ZipImporter *self = (ZipImporter *)obj;
PyObject *path = NULL;
- char *fullname;
+ PyObject *fullname;
enum zi_module_info mi;
- if (!PyArg_ParseTuple(args, "s|O:zipimporter.find_module",
- &fullname, &path))
+ if (!PyArg_ParseTuple(args, "O&|O:zipimporter.find_module",
+ PyUnicode_FSConverter, &fullname, &path))
return NULL;
mi = get_module_info(self, fullname);
+ Py_DECREF(fullname);
if (mi == MI_ERROR)
return NULL;
if (mi == MI_NOT_FOUND) {
@@ -403,22 +404,27 @@ static PyObject *
zipimporter_is_package(PyObject *obj, PyObject *args)
{
ZipImporter *self = (ZipImporter *)obj;
- char *fullname;
+ PyObject *fullname;
enum zi_module_info mi;
- if (!PyArg_ParseTuple(args, "s:zipimporter.is_package",
- &fullname))
+ if (!PyArg_ParseTuple(args, "O&:zipimporter.is_package",
+ PyUnicode_FSConverter, &fullname))
return NULL;
mi = get_module_info(self, fullname);
if (mi == MI_ERROR)
- return NULL;
+ goto error;
if (mi == MI_NOT_FOUND) {
- PyErr_Format(ZipImportError, "can't find module '%.200s'",
+ PyErr_Format(ZipImportError, "can't find module '%.200U'",
fullname);
- return NULL;
+ goto error;
}
+ Py_DECREF(fullname);
return PyBool_FromLong(mi == MI_PACKAGE);
+
+error:
+ Py_DECREF(fullname);
+ return NULL;
}
static PyObject *
@@ -490,24 +496,30 @@ zipimporter_get_source(PyObject *obj, PyObject *args)
{
ZipImporter *self = (ZipImporter *)obj;
PyObject *toc_entry;
- char *fullname, *subname, path[MAXPATHLEN+1];
+ PyObject *fullname;
+ char *subname, path[MAXPATHLEN+1];
int len;
enum zi_module_info mi;
- if (!PyArg_ParseTuple(args, "s:zipimporter.get_source", &fullname))
+ if (!PyArg_ParseTuple(args, "O&:zipimporter.get_source",
+ PyUnicode_FSConverter, &fullname))
return NULL;
mi = get_module_info(self, fullname);
- if (mi == MI_ERROR)
+ if (mi == MI_ERROR) {
+ Py_DECREF(fullname);
return NULL;
+ }
if (mi == MI_NOT_FOUND) {
- PyErr_Format(ZipImportError, "can't find module '%.200s'",
+ PyErr_Format(ZipImportError, "can't find module '%.200U'",
fullname);
+ Py_DECREF(fullname);
return NULL;
}
- subname = get_subname(fullname);
+ subname = get_subname(PyBytes_AS_STRING(fullname));
len = make_filename(self->prefix, subname, path, sizeof(path));
+ Py_DECREF(fullname);
if (len < 0)
return NULL;