cpython: 2807a5f011e4 (original) (raw)

--- a/Lib/test/test_zipimport.py +++ b/Lib/test/test_zipimport.py @@ -46,6 +46,27 @@ pyc_file = imp.cache_from_source(TESTMOD pyc_ext = ('.pyc' if debug else '.pyo') +def _write_zip_package(zipname, files,

+

+

+ + class UncompressedZipImportTestCase(ImportHooksBaseTestCase): compression = ZIP_STORED @@ -58,23 +79,9 @@ class UncompressedZipImportTestCase(Impo ImportHooksBaseTestCase.setUp(self) def doTest(self, expected_ext, files, *modules, **kw):

-

- sys.path.insert(0, TEMP_ZIP) mod = import(".".join(modules), globals(), locals(), @@ -89,7 +96,8 @@ class UncompressedZipImportTestCase(Impo self.assertEqual(file, os.path.join(TEMP_ZIP, *modules) + expected_ext) finally:

def testAFakeZlib(self): @@ -395,10 +403,67 @@ class CompressedZipImportTestCase(Uncomp compression = ZIP_DEFLATED +class ZipFileModifiedAfterImportTestCase(ImportHooksBaseTestCase):

+

+

+

+

+

+

+ + class BadFileZipImportTestCase(unittest.TestCase): def assertZipFailure(self, filename):

def testNoFile(self): self.assertZipFailure('AdfjdkFJKDFJjdklfjs') @@ -472,6 +537,7 @@ def test_main(): UncompressedZipImportTestCase, CompressedZipImportTestCase, BadFileZipImportTestCase,

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,11 @@ What's New in Python 3.3.4 release candi Core and Builtins ----------------- +- Issue #19081: When a zipimport .zip file in sys.path being imported from

--- a/Modules/zipimport.c +++ b/Modules/zipimport.c @@ -45,10 +45,16 @@ struct _zipimporter { static PyObject ZipImportError; / read_directory() cache */ static PyObject *zip_directory_cache = NULL; +static PyObject zip_stat_cache = NULL; +/ posix.fstat or nt.fstat function. Used due to posixmodule.c's

@@ -128,11 +134,39 @@ zipimporter_init(ZipImporter *self, PyOb files = PyDict_GetItem(zip_directory_cache, filename); if (files == NULL) {

+

+

+

@@ -554,10 +588,11 @@ zipimporter_get_data(PyObject *obj, PyOb { ZipImporter *self = (ZipImporter *)obj; PyObject *path, *key;

#ifdef ALTSEP _Py_IDENTIFIER(replace); #endif

+

+ toc_entry = PyDict_GetItem(self->files, key); if (toc_entry == NULL) { PyErr_SetFromErrnoWithFilenameObject(PyExc_IOError, key); Py_DECREF(key);

error: Py_DECREF(path); return NULL; @@ -618,6 +661,7 @@ zipimporter_get_source(PyObject *obj, Py PyObject *toc_entry; PyObject *fullname, *subname, *path, *fullpath; enum zi_module_info mi;

if (!PyArg_ParseTuple(args, "U:zipimporter.get_source", &fullname)) return NULL; @@ -647,11 +691,18 @@ zipimporter_get_source(PyObject *obj, Py if (fullpath == NULL) return NULL;

+ toc_entry = PyDict_GetItem(self->files, fullpath); Py_DECREF(fullpath); if (toc_entry != NULL) { PyObject *res, *bytes;

@@ -659,10 +710,10 @@ zipimporter_get_source(PyObject *obj, Py Py_DECREF(bytes); return res; }

/* we have the module, but no source */

} PyDoc_STRVAR(doc_find_module, @@ -828,10 +879,135 @@ get_long(unsigned char buf) { return x; } +/ Return 1 if objects a and b fail a Py_EQ test for an attr. */ +static int +compare_obj_attr_strings(PyObject *obj_a, PyObject *obj_b, char *attr_name) +{

+} + /*

+

+

+

+} + +/*

+

+

+

+} + +/*

-

-/* Given a path to a Zip file and a toc_entry, return the (uncompressed) +/* Given a FILE* to a Zip file and a toc_entry, return the (uncompressed) data as a new reference. */ static PyObject * -get_data(PyObject *archive, PyObject *toc_entry) +get_data(FILE *fp, PyObject *archive, PyObject *toc_entry) { PyObject *raw_data, *data = NULL, *decompress; char *buf;

- /* Check to make sure the local file header is correct */ if (fseek(fp, file_offset, 0) == -1) {

@@ -1329,12 +1477,12 @@ get_mtime_of_source(ZipImporter self, P / Return the code object for the module named by 'fullname' from the Zip archive as a new reference. */ static PyObject * -get_code_from_data(ZipImporter *self, int ispackage, int isbytecode, +get_code_from_data(ZipImporter *self, FILE *fp, int ispackage, int isbytecode, time_t mtime, PyObject *toc_entry) { PyObject *data, *modpath, *code;

@@ -1356,6 +1504,7 @@ get_module_code(ZipImporter *self, PyObj PyObject *code = NULL, *toc_entry, *subname; PyObject *path, *fullpath = NULL; struct st_zip_searchorder *zso;

subname = get_subname(fullname); if (subname == NULL) @@ -1366,6 +1515,12 @@ get_module_code(ZipImporter *self, PyObj if (path == NULL) return NULL;

+ for (zso = zip_searchorder; *zso->suffix; zso++) { code = NULL; @@ -1376,6 +1531,7 @@ get_module_code(ZipImporter *self, PyObj if (Py_VerboseFlag > 1) PySys_FormatStderr("# trying %U%c%U\n", self->archive, (int)SEP, fullpath); + toc_entry = PyDict_GetItem(self->files, fullpath); if (toc_entry != NULL) { time_t mtime = 0; @@ -1391,7 +1547,7 @@ get_module_code(ZipImporter *self, PyObj Py_CLEAR(fullpath); if (p_ispackage != NULL) *p_ispackage = ispackage;

@@ -1411,6 +1567,7 @@ get_module_code(ZipImporter *self, PyObj } PyErr_Format(ZipImportError, "can't find module %R", fullname); exit:

@@ -1494,5 +1654,36 @@ PyInit_zipimport(void) if (PyModule_AddObject(mod, "_zip_directory_cache", zip_directory_cache) < 0) return NULL; +

+

+ return mod; }