summaryrefslogtreecommitdiffstats
path: root/Modules/zipimport.c
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2008-12-14 10:54:50 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2008-12-14 10:54:50 (GMT)
commita2053475bb8a908e1cc80c765e02c98a6f354b19 (patch)
tree8449947a38952aaf7e64a7320c58fedf85fa07db /Modules/zipimport.c
parent3e16f3dd7f9219a19e5802b721b19fde93fc56a5 (diff)
downloadcpython-a2053475bb8a908e1cc80c765e02c98a6f354b19.zip
cpython-a2053475bb8a908e1cc80c765e02c98a6f354b19.tar.gz
cpython-a2053475bb8a908e1cc80c765e02c98a6f354b19.tar.bz2
Fix several issues relating to access to source code inside zipfiles. Initial work by Alexander Belopolsky. See Misc/NEWS in this checkin for details.
Diffstat (limited to 'Modules/zipimport.c')
-rw-r--r--Modules/zipimport.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index d3cd4ad..e320dd9 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -369,6 +369,29 @@ error:
return NULL;
}
+/* Return a string matching __file__ for the named module */
+static PyObject *
+zipimporter_get_filename(PyObject *obj, PyObject *args)
+{
+ ZipImporter *self = (ZipImporter *)obj;
+ PyObject *code;
+ char *fullname, *modpath;
+ int ispackage;
+
+ if (!PyArg_ParseTuple(args, "s:zipimporter._get_filename",
+ &fullname))
+ return NULL;
+
+ /* Deciding the filename requires working out where the code
+ would come from if the module was actually loaded */
+ code = get_module_code(self, fullname, &ispackage, &modpath);
+ if (code == NULL)
+ return NULL;
+ Py_DECREF(code); /* Only need the path info */
+
+ return PyString_FromString(modpath);
+}
+
/* Return a bool signifying whether the module is a package or not. */
static PyObject *
zipimporter_is_package(PyObject *obj, PyObject *args)
@@ -528,6 +551,12 @@ Return the source code for the specified module. Raise ZipImportError\n\
is the module couldn't be found, return None if the archive does\n\
contain the module, but has no source for it.");
+
+PyDoc_STRVAR(doc_get_filename,
+"_get_filename(fullname) -> filename string.\n\
+\n\
+Return the filename for the specified module.");
+
static PyMethodDef zipimporter_methods[] = {
{"find_module", zipimporter_find_module, METH_VARARGS,
doc_find_module},
@@ -539,6 +568,8 @@ static PyMethodDef zipimporter_methods[] = {
doc_get_code},
{"get_source", zipimporter_get_source, METH_VARARGS,
doc_get_source},
+ {"_get_filename", zipimporter_get_filename, METH_VARARGS,
+ doc_get_filename},
{"is_package", zipimporter_is_package, METH_VARARGS,
doc_is_package},
{NULL, NULL} /* sentinel */