summaryrefslogtreecommitdiffstats
path: root/Modules/zipimport.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-10-18 11:44:21 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-10-18 11:44:21 (GMT)
commit72f767e601651f3cedb169491ab3b141eb559d53 (patch)
tree25b78dba5ebb75ddf40ee109ce4eac9973ff032f /Modules/zipimport.c
parent353349caebeb64b7773d494227c53553a9e7444f (diff)
downloadcpython-72f767e601651f3cedb169491ab3b141eb559d53.zip
cpython-72f767e601651f3cedb169491ab3b141eb559d53.tar.gz
cpython-72f767e601651f3cedb169491ab3b141eb559d53.tar.bz2
zipimport: encode the prefix to the fileystem encoding
Diffstat (limited to 'Modules/zipimport.c')
-rw-r--r--Modules/zipimport.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index 0a0a778..64dbdbc 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -36,7 +36,8 @@ typedef struct _zipimporter ZipImporter;
struct _zipimporter {
PyObject_HEAD
PyObject *archive; /* pathname of the Zip archive */
- PyObject *prefix; /* file prefix: "a/sub/directory/" */
+ PyObject *prefix; /* file prefix: "a/sub/directory/",
+ encoded to the filesystem encoding */
PyObject *files; /* dict with file info {path: toc_entry} */
};
@@ -215,20 +216,26 @@ get_subname(char *fullname)
archive (without extension) to the path buffer. Return the
length of the resulting string. */
static int
-make_filename(char *prefix, char *name, char *path)
+make_filename(PyObject *prefix_obj, char *name, char *path)
{
size_t len;
char *p;
+ PyObject *prefix;
- len = strlen(prefix);
+ prefix = PyUnicode_EncodeFSDefault(prefix_obj);
+ if (prefix == NULL)
+ return -1;
+ len = PyBytes_GET_SIZE(prefix);
/* self.prefix + name [+ SEP + "__init__"] + ".py[co]" */
if (len + strlen(name) + 13 >= MAXPATHLEN) {
PyErr_SetString(ZipImportError, "path too long");
+ Py_DECREF(prefix);
return -1;
}
- strcpy(path, prefix);
+ strcpy(path, PyBytes_AS_STRING(prefix));
+ Py_DECREF(prefix);
strcpy(path + len, name);
for (p = path + len; *p; p++) {
if (*p == '.')
@@ -256,7 +263,7 @@ get_module_info(ZipImporter *self, char *fullname)
subname = get_subname(fullname);
- len = make_filename(_PyUnicode_AsString(self->prefix), subname, path);
+ len = make_filename(self->prefix, subname, path);
if (len < 0)
return MI_ERROR;
@@ -491,7 +498,7 @@ zipimporter_get_source(PyObject *obj, PyObject *args)
}
subname = get_subname(fullname);
- len = make_filename(_PyUnicode_AsString(self->prefix), subname, path);
+ len = make_filename(self->prefix, subname, path);
if (len < 0)
return NULL;
@@ -1148,7 +1155,7 @@ get_module_code(ZipImporter *self, char *fullname,
subname = get_subname(fullname);
- len = make_filename(_PyUnicode_AsString(self->prefix), subname, path);
+ len = make_filename(self->prefix, subname, path);
if (len < 0)
return NULL;
@@ -1158,7 +1165,7 @@ get_module_code(ZipImporter *self, char *fullname,
strcpy(path + len, zso->suffix);
if (Py_VerboseFlag > 1)
PySys_FormatStderr("# trying %U%c%s\n",
- self->archive, (int)SEP, path);
+ self->archive, (int)SEP, path);
toc_entry = PyDict_GetItemString(self->files, path);
if (toc_entry != NULL) {
time_t mtime = 0;