cpython: 8dbf8edb7128 (original) (raw)

--- a/Lib/test/test_zipimport.py +++ b/Lib/test/test_zipimport.py @@ -1,3 +1,4 @@ +import io import sys import os import marshal @@ -55,6 +56,27 @@ TESTPACK2 = "ziptestpackage2" TEMP_ZIP = os.path.abspath("junk95142" + os.extsep + "zip") +def _write_zip_package(zipname, files,

+

+

+ + class UncompressedZipImportTestCase(ImportHooksBaseTestCase): compression = ZIP_STORED @@ -67,26 +89,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(), @@ -101,7 +106,6 @@ class UncompressedZipImportTestCase(Impo self.assertEqual(file, os.path.join(TEMP_ZIP, *modules) + expected_ext) finally:

def testAFakeZlib(self): @@ -387,6 +391,64 @@ class CompressedZipImportTestCase(Uncomp compression = ZIP_DEFLATED +class ZipFileModifiedAfterImportTestCase(ImportHooksBaseTestCase):

+

+

+

+

+

+

+ + class BadFileZipImportTestCase(unittest.TestCase): def assertZipFailure(self, filename): self.assertRaises(zipimport.ZipImportError, @@ -464,6 +526,7 @@ def test_main(): UncompressedZipImportTestCase, CompressedZipImportTestCase, BadFileZipImportTestCase,

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

@@ -126,12 +132,38 @@ zipimporter_init(ZipImporter *self, PyOb PyObject *files; files = PyDict_GetItemString(zip_directory_cache, path); if (files == NULL) {

+

+

@@ -419,11 +451,12 @@ static PyObject * zipimporter_get_data(PyObject *obj, PyObject *args) { ZipImporter *self = (ZipImporter *)obj;

#ifdef ALTSEP char *p, buf[MAXPATHLEN + 1]; #endif

+ toc_entry = PyDict_GetItemString(self->files, path); if (toc_entry == NULL) { PyErr_SetFromErrnoWithFilename(PyExc_IOError, path);

} static PyObject * @@ -473,7 +513,8 @@ zipimporter_get_source(PyObject *obj, Py { ZipImporter *self = (ZipImporter *)obj; PyObject *toc_entry;

+ toc_entry = PyDict_GetItemString(self->files, path);

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

} PyDoc_STRVAR(doc_find_module, @@ -662,7 +710,139 @@ get_long(unsigned char buf) { } /

+

+

+

+} + +/* 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) +{

+} + +/*

+

+

+

+

+

+} + +/*

@@ -703,28 +883,18 @@ read_directory(char *archive) } strcpy(path, archive);

- if (fseek(fp, -22, SEEK_END) == -1) {

@@ -793,18 +963,15 @@ read_directory(char *archive) goto error; count++; }

@@ -841,14 +1008,13 @@ get_decompress_func(void) return decompress; } -/* 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(char *archive, PyObject *toc_entry) +get_data(FILE *fp, char *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) {

@@ -1107,17 +1260,13 @@ get_mtime_of_source(ZipImporter self, c / 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(char *archive, FILE *fp, int ispackage,

{ PyObject *data, *code; char *modpath;

-

@@ -1152,12 +1301,19 @@ get_module_code(ZipImporter *self, char for (zso = zip_searchorder; *zso->suffix; zso++) { PyObject *code = NULL;

strcpy(path + len, zso->suffix); if (Py_VerboseFlag > 1) PySys_WriteStderr("# trying %s%c%s\n", PyString_AsString(self->archive), SEP, path); +

+ toc_entry = PyDict_GetItemString(self->files, path); if (toc_entry != NULL) { time_t mtime = 0; @@ -1168,9 +1324,10 @@ get_module_code(ZipImporter *self, char mtime = get_mtime_of_source(self, path); if (p_ispackage != NULL) *p_ispackage = ispackage;

@@ -1182,6 +1339,7 @@ get_module_code(ZipImporter *self, char PyTuple_GetItem(toc_entry, 0)); return code; }

@@ -1254,4 +1415,31 @@ initzipimport(void) if (PyModule_AddObject(mod, "_zip_directory_cache", zip_directory_cache) < 0) return; +

+

}