diff options
author | Thomas Heller <theller@ctypes.org> | 2003-07-22 18:10:15 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2003-07-22 18:10:15 (GMT) |
commit | 354e3d90d346afdc6c70211b130aa76bb18e19ed (patch) | |
tree | e03da58869310f187315670c86523d4ce4b69763 /Lib | |
parent | fac083d14a94137999559d895a4e6d1d9a2ea74c (diff) | |
download | cpython-354e3d90d346afdc6c70211b130aa76bb18e19ed.zip cpython-354e3d90d346afdc6c70211b130aa76bb18e19ed.tar.gz cpython-354e3d90d346afdc6c70211b130aa76bb18e19ed.tar.bz2 |
Change the zipimport implementation to accept files containing
arbitrary bytes before the actual zip compatible archive. Zipfiles
containing comments at the end of the file are still not supported.
Add a testcase to test_zipimport, and update NEWS.
This closes sf #775637 and sf #669036.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_zipimport.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py index 26a2f1f..86acdd2 100644 --- a/Lib/test/test_zipimport.py +++ b/Lib/test/test_zipimport.py @@ -49,7 +49,7 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase): zipimport._zip_directory_cache.clear() ImportHooksBaseTestCase.setUp(self) - def doTest(self, expected_ext, files, *modules): + def doTest(self, expected_ext, files, *modules, **kw): z = ZipFile(TEMP_ZIP, "w") try: for name, (mtime, data) in files.items(): @@ -57,6 +57,19 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase): zinfo.compress_type = self.compression z.writestr(zinfo, data) z.close() + + stuff = kw.get("stuff", None) + if stuff is not None: + # Prepend 'stuff' to the start of the zipfile + f = open(TEMP_ZIP, "rb") + data = f.read() + f.close() + + f = open(TEMP_ZIP, "wb") + f.write(stuff) + f.write(data) + f.close() + sys.path.insert(0, TEMP_ZIP) mod = __import__(".".join(modules), globals(), locals(), @@ -181,6 +194,12 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase): "some.data": (NOW, "some data")} self.doTest(pyc_ext, files, TESTMOD) + def testImport_WithStuff(self): + # try importing from a zipfile which contains additional + # stuff at the beginning of the file + files = {TESTMOD + ".py": (NOW, test_src)} + self.doTest(".py", files, TESTMOD, + stuff="Some Stuff"*31) class CompressedZipImportTestCase(UncompressedZipImportTestCase): compression = ZIP_DEFLATED |