cpython: 4d1948689ee1 (original) (raw)

--- a/Doc/library/zipfile.rst +++ b/Doc/library/zipfile.rst @@ -242,6 +242,16 @@ ZipFile Objects .. versionadded:: 2.6

+ .. method:: ZipFile.read(name[, pwd])

--- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -26,7 +26,7 @@ FIXEDTEST_SIZE = 1000 SMALL_TEST_DATA = [('_ziptest1', '1q2w3e4r5t'), ('ziptest2dir/_ziptest2', 'qawsedrftg'),

@@ -391,10 +391,7 @@ class TestsWithSourceFile(unittest.TestC writtenfile = zipfp.extract(fpath) # make sure it was written to the right place

self.assertEqual(writtenfile, correctfile) @@ -414,10 +411,7 @@ class TestsWithSourceFile(unittest.TestC with zipfile.ZipFile(TESTFN2, "r") as zipfp: zipfp.extractall() for fpath, fdata in SMALL_TEST_DATA:

self.assertEqual(fdata, open(outfile, "rb").read()) os.remove(outfile) @@ -425,6 +419,80 @@ class TestsWithSourceFile(unittest.TestC # remove the test file subdirectories shutil.rmtree(os.path.join(os.getcwd(), 'ziptest2dir'))

+

+

+

+

+

+

+

+

+

+ def test_writestr_compression(self): zipfp = zipfile.ZipFile(TESTFN2, "w") zipfp.writestr("a.txt", "hello world", compress_type=zipfile.ZIP_STORED)

--- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -1040,17 +1040,22 @@ class ZipFile(object): """ # build the destination pathname, replacing # forward slashes to platform specific separators.

# Create all upper directories if necessary.

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -202,6 +202,9 @@ Core and Builtins Library ------- +- Issue #6972: The zipfile module no longer overwrites files outside of