cpython: 20b77ff040b6 (original) (raw)

--- a/Lib/test/test_zipimport.py +++ b/Lib/test/test_zipimport.py @@ -71,6 +71,27 @@ class ImportHooksBaseTestCase(unittest.T support.modules_cleanup(*self.modules_before) +def _write_zip_package(zipname, files,

+

+

+ + class UncompressedZipImportTestCase(ImportHooksBaseTestCase): compression = ZIP_STORED @@ -83,23 +104,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(), @@ -114,7 +121,8 @@ class UncompressedZipImportTestCase(Impo self.assertEqual(file, os.path.join(TEMP_ZIP, *modules) + expected_ext) finally:

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

+

+

+

+

+

+

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

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

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,11 @@ Release date: 2014-01-19 Core and Builtins ----------------- +- Issue #19081: When a zipimport .zip file in sys.path being imported from

--- a/Modules/zipimport.c +++ b/Modules/zipimport.c @@ -49,10 +49,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

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

+

+

+

@@ -560,7 +594,8 @@ zipimporter_get_data(PyObject *obj, PyOb { ZipImporter *self = (ZipImporter *)obj; PyObject *path, *key;

+

+ 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; @@ -621,6 +664,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; @@ -650,11 +694,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;

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

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

} PyDoc_STRVAR(doc_find_module, @@ -831,10 +882,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) {

@@ -1351,12 +1498,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;

@@ -1378,6 +1525,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) @@ -1388,6 +1536,12 @@ get_module_code(ZipImporter *self, PyObj if (path == NULL) return NULL;

+ for (zso = zip_searchorder; *zso->suffix; zso++) { code = NULL; @@ -1398,6 +1552,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; @@ -1413,7 +1568,7 @@ get_module_code(ZipImporter *self, PyObj Py_CLEAR(fullpath); if (p_ispackage != NULL) *p_ispackage = ispackage;

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

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

+

+ return mod; }