diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2008-12-14 11:50:48 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2008-12-14 11:50:48 (GMT) |
commit | f088e5e6cc0e7ad7991a910be13510ca33e91958 (patch) | |
tree | bc4281856af88400076b08b3e6d4431565017e3e /Modules/zipimport.c | |
parent | 80a0c7f62366235059bd2e5892554fa75c7670ca (diff) | |
download | cpython-f088e5e6cc0e7ad7991a910be13510ca33e91958.zip cpython-f088e5e6cc0e7ad7991a910be13510ca33e91958.tar.gz cpython-f088e5e6cc0e7ad7991a910be13510ca33e91958.tar.bz2 |
Merged revisions 67750-67751 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67750 | nick.coghlan | 2008-12-14 20:54:50 +1000 (Sun, 14 Dec 2008) | 1 line
Fix several issues relating to access to source code inside zipfiles. Initial work by Alexander Belopolsky. See Misc/NEWS in this checkin for details.
........
r67751 | nick.coghlan | 2008-12-14 21:09:40 +1000 (Sun, 14 Dec 2008) | 1 line
Add file that was missed from r67750
........
Diffstat (limited to 'Modules/zipimport.c')
-rw-r--r-- | Modules/zipimport.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Modules/zipimport.c b/Modules/zipimport.c index 000e987..ae11bde 100644 --- a/Modules/zipimport.c +++ b/Modules/zipimport.c @@ -354,6 +354,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 PyUnicode_FromString(modpath); +} + /* Return a bool signifying whether the module is a package or not. */ static PyObject * zipimporter_is_package(PyObject *obj, PyObject *args) @@ -518,6 +541,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}, @@ -529,6 +558,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 */ |