summaryrefslogtreecommitdiff
path: root/Modules/zipimport.c
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2018-01-24 15:36:21 -0500
committerGitHub <noreply@github.com>2018-01-24 15:36:21 -0500
commit6f6eb35f9bee18f54945f09664344f2d118ed89f (patch)
treee1e7432ccc9f7755d85da2803181f04504ac3894 /Modules/zipimport.c
parent789e359f51d2b27bea01b8c6c3bf090aaedf8839 (diff)
downloadcpython-git-6f6eb35f9bee18f54945f09664344f2d118ed89f.tar.gz
bpo-32248 - Implement `ResourceReader` and `get_resource_reader()` for zipimport (#5248)
Diffstat (limited to 'Modules/zipimport.c')
-rw-r--r--Modules/zipimport.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index 1d0e0ba913..85013665d1 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -784,6 +784,35 @@ zipimport_zipimporter_get_source_impl(ZipImporter *self, PyObject *fullname)
Py_RETURN_NONE;
}
+/*[clinic input]
+zipimport.zipimporter.get_resource_reader
+
+ fullname: unicode
+ /
+
+Return the ResourceReader for a package in a zip file.
+
+If 'fullname' is a package within the zip file, return the 'ResourceReader'
+object for the package. Otherwise return None.
+
+[clinic start generated code]*/
+
+static PyObject *
+zipimport_zipimporter_get_resource_reader_impl(ZipImporter *self,
+ PyObject *fullname)
+/*[clinic end generated code: output=5e367d431f830726 input=bfab94d736e99151]*/
+{
+ PyObject *module = PyImport_ImportModule("importlib.resources");
+ if (module == NULL) {
+ return NULL;
+ }
+ PyObject *retval = PyObject_CallMethod(
+ module, "_zipimport_get_resource_reader",
+ "OO", (PyObject *)self, fullname);
+ Py_DECREF(module);
+ return retval;
+}
+
static PyMethodDef zipimporter_methods[] = {
ZIPIMPORT_ZIPIMPORTER_FIND_MODULE_METHODDEF
@@ -794,6 +823,7 @@ static PyMethodDef zipimporter_methods[] = {
ZIPIMPORT_ZIPIMPORTER_GET_DATA_METHODDEF
ZIPIMPORT_ZIPIMPORTER_GET_CODE_METHODDEF
ZIPIMPORT_ZIPIMPORTER_GET_SOURCE_METHODDEF
+ ZIPIMPORT_ZIPIMPORTER_GET_RESOURCE_READER_METHODDEF
{NULL, NULL} /* sentinel */
};