From 7ffb276e1a3ffffaf3a81126c563d39f9bfe4fe7 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 20 Feb 2023 16:01:58 -0500 Subject: [PATCH] [3.10] gh-101566: Sync with zipp 3.14. (GH-102018). (cherry picked from commit 36854bbb240e417c0df6f0014924fcc899388186) Co-authored-by: Jason R. Coombs --- Lib/test/test_zipfile.py | 11 +++++++++++ Lib/zipfile.py | 11 +++++++++++ .../2023-02-17-20-24-15.gh-issue-101566.FjgWBt.rst | 3 +++ 3 files changed, 25 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2023-02-17-20-24-15.gh-issue-101566.FjgWBt.rst diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index cf40412f85266d..c7371f59859ebc 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -3209,6 +3209,17 @@ def test_inheritance(self, alpharep): 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) + if __name__ == "__main__": unittest.main() diff --git a/Lib/zipfile.py b/Lib/zipfile.py index dc4eb38e3a9025..23e4ee42d4d960 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -2197,6 +2197,17 @@ def resolve_dir(self, name): 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 index 00000000000000..f0c0c249a54bc9 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-02-17-20-24-15.gh-issue-101566.FjgWBt.rst @@ -0,0 +1,3 @@ +In zipfile, apply +fix for extractall on the underlying zipfile after being wrapped in +``Path``.