mirror of
https://github.com/python/cpython.git
synced 2025-10-03 21:55:41 +00:00
zipimport: encode the prefix to the fileystem encoding
This commit is contained in:
parent
353349caeb
commit
72f767e601
1 changed files with 15 additions and 8 deletions
|
@ -36,7 +36,8 @@ typedef struct _zipimporter ZipImporter;
|
||||||
struct _zipimporter {
|
struct _zipimporter {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
PyObject *archive; /* pathname of the Zip archive */
|
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} */
|
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
|
archive (without extension) to the path buffer. Return the
|
||||||
length of the resulting string. */
|
length of the resulting string. */
|
||||||
static int
|
static int
|
||||||
make_filename(char *prefix, char *name, char *path)
|
make_filename(PyObject *prefix_obj, char *name, char *path)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
char *p;
|
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]" */
|
/* self.prefix + name [+ SEP + "__init__"] + ".py[co]" */
|
||||||
if (len + strlen(name) + 13 >= MAXPATHLEN) {
|
if (len + strlen(name) + 13 >= MAXPATHLEN) {
|
||||||
PyErr_SetString(ZipImportError, "path too long");
|
PyErr_SetString(ZipImportError, "path too long");
|
||||||
|
Py_DECREF(prefix);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(path, prefix);
|
strcpy(path, PyBytes_AS_STRING(prefix));
|
||||||
|
Py_DECREF(prefix);
|
||||||
strcpy(path + len, name);
|
strcpy(path + len, name);
|
||||||
for (p = path + len; *p; p++) {
|
for (p = path + len; *p; p++) {
|
||||||
if (*p == '.')
|
if (*p == '.')
|
||||||
|
@ -256,7 +263,7 @@ get_module_info(ZipImporter *self, char *fullname)
|
||||||
|
|
||||||
subname = get_subname(fullname);
|
subname = get_subname(fullname);
|
||||||
|
|
||||||
len = make_filename(_PyUnicode_AsString(self->prefix), subname, path);
|
len = make_filename(self->prefix, subname, path);
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
return MI_ERROR;
|
return MI_ERROR;
|
||||||
|
|
||||||
|
@ -491,7 +498,7 @@ zipimporter_get_source(PyObject *obj, PyObject *args)
|
||||||
}
|
}
|
||||||
subname = get_subname(fullname);
|
subname = get_subname(fullname);
|
||||||
|
|
||||||
len = make_filename(_PyUnicode_AsString(self->prefix), subname, path);
|
len = make_filename(self->prefix, subname, path);
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -1148,7 +1155,7 @@ get_module_code(ZipImporter *self, char *fullname,
|
||||||
|
|
||||||
subname = get_subname(fullname);
|
subname = get_subname(fullname);
|
||||||
|
|
||||||
len = make_filename(_PyUnicode_AsString(self->prefix), subname, path);
|
len = make_filename(self->prefix, subname, path);
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue