From 6f8ae4cca3c0f91e768fe3568829dd4854d5b8ea Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 5 Feb 2023 12:37:10 -0500 Subject: [PATCH] Override ZipFile.getinfo to supply a ZipInfo for implied dirs. Fixes python/cpython#101566. --- tests/test_zipp.py | 1 - zipp/__init__.py | 11 +++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/test_zipp.py b/tests/test_zipp.py index 0a705ff..abc96a2 100644 --- a/tests/test_zipp.py +++ b/tests/test_zipp.py @@ -538,7 +538,6 @@ def test_extract_orig_with_implied_dirs(self, alpharep): """ A zip file wrapped in a Path should extract even with implied dirs. """ - self.skipTest("Fails due to python-101566") source_path = self.zipfile_ondisk(alpharep) zf = zipfile.ZipFile(source_path) # wrap the zipfile for its side effect diff --git a/zipp/__init__.py b/zipp/__init__.py index e98f1e1..392d0f7 100644 --- a/zipp/__init__.py +++ b/zipp/__init__.py @@ -113,6 +113,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(CompleteDirs, self).getinfo(name) + except KeyError: + if not name.endswith('/') or name not in self._name_set(): + raise + return zipfile.ZipInfo(filename=name) + @classmethod def make(cls, source): """