Kaydet (Commit) 43cfd824 authored tarafından Brett Cannon's avatar Brett Cannon

Merge for issue #17633

This diff is collapsed.
...@@ -324,17 +324,14 @@ get_module_info(ZipImporter *self, PyObject *fullname) ...@@ -324,17 +324,14 @@ get_module_info(ZipImporter *self, PyObject *fullname)
} }
typedef enum { typedef enum {
FL_ERROR, FL_ERROR = -1, /* error */
FL_NOT_FOUND, FL_NOT_FOUND, /* no loader or namespace portions found */
FL_MODULE_FOUND, FL_MODULE_FOUND, /* module/package found */
FL_NS_FOUND FL_NS_FOUND /* namespace portion found: */
/* *namespace_portion will point to the name */
} find_loader_result; } find_loader_result;
/* The guts of "find_loader" and "find_module". Return values: /* The guts of "find_loader" and "find_module".
-1: error
0: no loader or namespace portions found
1: module/package found
2: namespace portion found: *namespace_portion will point to the name
*/ */
static find_loader_result static find_loader_result
find_loader(ZipImporter *self, PyObject *fullname, PyObject **namespace_portion) find_loader(ZipImporter *self, PyObject *fullname, PyObject **namespace_portion)
...@@ -349,21 +346,34 @@ find_loader(ZipImporter *self, PyObject *fullname, PyObject **namespace_portion) ...@@ -349,21 +346,34 @@ find_loader(ZipImporter *self, PyObject *fullname, PyObject **namespace_portion)
if (mi == MI_NOT_FOUND) { if (mi == MI_NOT_FOUND) {
/* Not a module or regular package. See if this is a directory, and /* Not a module or regular package. See if this is a directory, and
therefore possibly a portion of a namespace package. */ therefore possibly a portion of a namespace package. */
int is_dir = check_is_directory(self, self->prefix, fullname); find_loader_result result = FL_NOT_FOUND;
PyObject *subname;
int is_dir;
/* We're only interested in the last path component of fullname;
earlier components are recorded in self->prefix. */
subname = get_subname(fullname);
if (subname == NULL) {
return FL_ERROR;
}
is_dir = check_is_directory(self, self->prefix, subname);
if (is_dir < 0) if (is_dir < 0)
return -1; result = FL_ERROR;
if (is_dir) { else if (is_dir) {
/* This is possibly a portion of a namespace /* This is possibly a portion of a namespace
package. Return the string representing its path, package. Return the string representing its path,
without a trailing separator. */ without a trailing separator. */
*namespace_portion = PyUnicode_FromFormat("%U%c%U%U", *namespace_portion = PyUnicode_FromFormat("%U%c%U%U",
self->archive, SEP, self->archive, SEP,
self->prefix, fullname); self->prefix, subname);
if (*namespace_portion == NULL) if (*namespace_portion == NULL)
return FL_ERROR; result = FL_ERROR;
return FL_NS_FOUND; else
result = FL_NS_FOUND;
} }
return FL_NOT_FOUND; Py_DECREF(subname);
return result;
} }
/* This is a module or package. */ /* This is a module or package. */
return FL_MODULE_FOUND; return FL_MODULE_FOUND;
...@@ -397,6 +407,9 @@ zipimporter_find_module(PyObject *obj, PyObject *args) ...@@ -397,6 +407,9 @@ zipimporter_find_module(PyObject *obj, PyObject *args)
case FL_MODULE_FOUND: case FL_MODULE_FOUND:
result = (PyObject *)self; result = (PyObject *)self;
break; break;
default:
PyErr_BadInternalCall();
return NULL;
} }
Py_INCREF(result); Py_INCREF(result);
return result; return result;
...@@ -433,6 +446,9 @@ zipimporter_find_loader(PyObject *obj, PyObject *args) ...@@ -433,6 +446,9 @@ zipimporter_find_loader(PyObject *obj, PyObject *args)
result = Py_BuildValue("O[O]", Py_None, namespace_portion); result = Py_BuildValue("O[O]", Py_None, namespace_portion);
Py_DECREF(namespace_portion); Py_DECREF(namespace_portion);
return result; return result;
default:
PyErr_BadInternalCall();
return NULL;
} }
return result; return result;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment