]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-101566: Sync with zipp 3.14. (GH-102018). (GH-102090)
authorJason R. Coombs <jaraco@jaraco.com>
Mon, 20 Feb 2023 23:22:03 +0000 (18:22 -0500)
committerGitHub <noreply@github.com>
Mon, 20 Feb 2023 23:22:03 +0000 (15:22 -0800)
(cherry picked from commit 36854bbb240e417c0df6f0014924fcc899388186)

Backport of bugfix only.

Automerge-Triggered-By: GH:jaraco
Lib/test/test_zipfile.py
Lib/zipfile.py
Misc/NEWS.d/next/Library/2023-02-17-20-24-15.gh-issue-101566.FjgWBt.rst [new file with mode: 0644]

index da4ddb916f8c2b5a7fe6d7316a5d9d54156a2211..ffb954659e420bb14dc022f5397b00ccb5bfde22 100644 (file)
@@ -3339,6 +3339,17 @@ with zipfile.ZipFile(io.BytesIO(), "w") as zf:
             file = cls(alpharep).joinpath('some dir').parent
             assert isinstance(file, cls)
 
+    @pass_alpharep
+    def test_extract_orig_with_implied_dirs(self, alpharep):
+        """
+        A zip file wrapped in a Path should extract even with implied dirs.
+        """
+        source_path = self.zipfile_ondisk(alpharep)
+        zf = zipfile.ZipFile(source_path)
+        # wrap the zipfile for its side effect
+        zipfile.Path(zf)
+        zf.extractall(source_path.parent)
+
 
 class EncodedMetadataTests(unittest.TestCase):
     file_names = ['\u4e00', '\u4e8c', '\u4e09']  # Han 'one', 'two', 'three'
index a0b29e25a3cc03e75615596e7efb542a67f704ab..f14a638d40c5a3bbf079ee6d2b0994d12141b047 100644 (file)
@@ -2250,6 +2250,17 @@ class CompleteDirs(ZipFile):
         dir_match = name not in names and dirname in names
         return dirname if dir_match else name
 
+    def getinfo(self, name):
+        """
+        Supplement getinfo for implied dirs.
+        """
+        try:
+            return super().getinfo(name)
+        except KeyError:
+            if not name.endswith('/') or name not in self._name_set():
+                raise
+            return ZipInfo(filename=name)
+
     @classmethod
     def make(cls, source):
         """
diff --git a/Misc/NEWS.d/next/Library/2023-02-17-20-24-15.gh-issue-101566.FjgWBt.rst b/Misc/NEWS.d/next/Library/2023-02-17-20-24-15.gh-issue-101566.FjgWBt.rst
new file mode 100644 (file)
index 0000000..f0c0c24
--- /dev/null
@@ -0,0 +1,3 @@
+In zipfile, apply
+fix for extractall on the underlying zipfile after being wrapped in
+``Path``.