mirror of https://github.com/python/cpython
Issue #4512 closeout: Make ZipImport.get_filename() a public method
This commit is contained in:
parent
c3623b1849
commit
0194f5bc98
|
@ -94,6 +94,15 @@ zipimporter Objects
|
|||
file wasn't found.
|
||||
|
||||
|
||||
.. method:: get_filename(fullname)
|
||||
|
||||
Return the value ``__file__`` would be set to if the specified module
|
||||
was imported. Raise :exc:`ZipImportError` if the module couldn't be
|
||||
found.
|
||||
|
||||
.. versionadded:: 2.7
|
||||
|
||||
|
||||
.. method:: get_source(fullname)
|
||||
|
||||
Return the source code for the specified module. Raise
|
||||
|
|
|
@ -215,7 +215,7 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
|
|||
self.assertEquals(zi.archive, TEMP_ZIP)
|
||||
self.assertEquals(zi.is_package(TESTPACK), True)
|
||||
mod = zi.load_module(TESTPACK)
|
||||
self.assertEquals(zi._get_filename(TESTPACK), mod.__file__)
|
||||
self.assertEquals(zi.get_filename(TESTPACK), mod.__file__)
|
||||
|
||||
self.assertEquals(zi.is_package(packdir + '__init__'), False)
|
||||
self.assertEquals(zi.is_package(packdir + TESTPACK2), True)
|
||||
|
@ -227,11 +227,11 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
|
|||
mod = sys.modules[mod_name]
|
||||
self.assertEquals(zi.get_source(TESTPACK), None)
|
||||
self.assertEquals(zi.get_source(mod_path), None)
|
||||
self.assertEquals(zi._get_filename(mod_path), mod.__file__)
|
||||
self.assertEquals(zi.get_filename(mod_path), mod.__file__)
|
||||
# To pass in the module name instead of the path, we must use the right importer
|
||||
loader = mod.__loader__
|
||||
self.assertEquals(loader.get_source(mod_name), None)
|
||||
self.assertEquals(loader._get_filename(mod_name), mod.__file__)
|
||||
self.assertEquals(loader.get_filename(mod_name), mod.__file__)
|
||||
|
||||
# test prefix and archivepath members
|
||||
zi2 = zipimport.zipimporter(TEMP_ZIP + os.sep + TESTPACK)
|
||||
|
@ -260,7 +260,7 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
|
|||
self.assertEquals(zi.prefix, packdir)
|
||||
self.assertEquals(zi.is_package(TESTPACK2), True)
|
||||
mod = zi.load_module(TESTPACK2)
|
||||
self.assertEquals(zi._get_filename(TESTPACK2), mod.__file__)
|
||||
self.assertEquals(zi.get_filename(TESTPACK2), mod.__file__)
|
||||
|
||||
self.assertEquals(zi.is_package(TESTPACK2 + os.sep + '__init__'), False)
|
||||
self.assertEquals(zi.is_package(TESTPACK2 + os.sep + TESTMOD), False)
|
||||
|
@ -271,11 +271,11 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
|
|||
mod = sys.modules[mod_name]
|
||||
self.assertEquals(zi.get_source(TESTPACK2), None)
|
||||
self.assertEquals(zi.get_source(mod_path), None)
|
||||
self.assertEquals(zi._get_filename(mod_path), mod.__file__)
|
||||
self.assertEquals(zi.get_filename(mod_path), mod.__file__)
|
||||
# To pass in the module name instead of the path, we must use the right importer
|
||||
loader = mod.__loader__
|
||||
self.assertEquals(loader.get_source(mod_name), None)
|
||||
self.assertEquals(loader._get_filename(mod_name), mod.__file__)
|
||||
self.assertEquals(loader.get_filename(mod_name), mod.__file__)
|
||||
finally:
|
||||
z.close()
|
||||
os.remove(TEMP_ZIP)
|
||||
|
|
|
@ -149,6 +149,9 @@ Core and Builtins
|
|||
Library
|
||||
-------
|
||||
|
||||
- Issue #4512 (part 2): Promote ``ZipImporter._get_filename()`` to be a
|
||||
public documented method ``ZipImporter.get_filename()``.
|
||||
|
||||
- Issue #4195: The ``runpy`` module (and the ``-m`` switch) now support
|
||||
the execution of packages by looking for and executing a ``__main__``
|
||||
submodule when a package name is supplied. Initial patch by Andi
|
||||
|
|
|
@ -378,7 +378,7 @@ zipimporter_get_filename(PyObject *obj, PyObject *args)
|
|||
char *fullname, *modpath;
|
||||
int ispackage;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s:zipimporter._get_filename",
|
||||
if (!PyArg_ParseTuple(args, "s:zipimporter.get_filename",
|
||||
&fullname))
|
||||
return NULL;
|
||||
|
||||
|
@ -553,7 +553,7 @@ contain the module, but has no source for it.");
|
|||
|
||||
|
||||
PyDoc_STRVAR(doc_get_filename,
|
||||
"_get_filename(fullname) -> filename string.\n\
|
||||
"get_filename(fullname) -> filename string.\n\
|
||||
\n\
|
||||
Return the filename for the specified module.");
|
||||
|
||||
|
@ -568,7 +568,7 @@ static PyMethodDef zipimporter_methods[] = {
|
|||
doc_get_code},
|
||||
{"get_source", zipimporter_get_source, METH_VARARGS,
|
||||
doc_get_source},
|
||||
{"_get_filename", zipimporter_get_filename, METH_VARARGS,
|
||||
{"get_filename", zipimporter_get_filename, METH_VARARGS,
|
||||
doc_get_filename},
|
||||
{"is_package", zipimporter_is_package, METH_VARARGS,
|
||||
doc_is_package},
|
||||
|
|
Loading…
Reference in New Issue