Index: Modules/zipimport.c =================================================================== --- Modules/zipimport.c (revision 67511) +++ Modules/zipimport.c (working copy) @@ -487,6 +487,42 @@ return Py_None; } +static PyObject * +zipimporter_get_filename(PyObject *obj, PyObject *args) +{ + ZipImporter *self = (ZipImporter *)obj; + PyObject *toc_entry; + char *fullname, *subname, path[MAXPATHLEN+1]; + int len; + enum zi_module_info mi; + + if (!PyArg_ParseTuple(args, "s:zipimporter.get_filename", &fullname)) + return NULL; + + mi = get_module_info(self, fullname); + if (mi == MI_ERROR) + return NULL; + if (mi == MI_NOT_FOUND) { + PyErr_Format(ZipImportError, "can't find module '%.200s'", + fullname); + return NULL; + } + subname = get_subname(fullname); + + len = make_filename(PyString_AsString(self->prefix), subname, path); + if (len < 0) + return NULL; + + if (mi == MI_PACKAGE) { + path[len] = SEP; + strcpy(path + len + 1, "__init__.py"); + } + else + strcpy(path + len, ".py"); + return PyString_FromFormat("%s%c%s", PyString_AsString(self->archive), + SEP, path); +} + PyDoc_STRVAR(doc_find_module, "find_module(fullname, path=None) -> self or None.\n\ \n\ @@ -528,6 +564,12 @@ 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 +581,8 @@ 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 */ Index: Lib/test/test_zipimport.py =================================================================== --- Lib/test/test_zipimport.py (revision 67511) +++ Lib/test/test_zipimport.py (working copy) @@ -224,6 +224,8 @@ mod = __import__(module_path_to_dotted_name(mod_name)) self.assertEquals(zi.get_source(TESTPACK), None) self.assertEquals(zi.get_source(mod_name), None) + path = os.path.join(TEMP_ZIP, mod_name + '.py') + self.assertEquals(zi.get_filename(mod_name), path) # test prefix and archivepath members zi2 = zipimport.zipimporter(TEMP_ZIP + os.sep + TESTPACK)