Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for KeyError when implied dirs are present. #90

Merged
merged 3 commits into from
Feb 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v3.12.1
=======

* gh-101566: In ``CompleteDirs``, override ``ZipFile.getinfo``
to supply a ``ZipInfo`` for implied dirs.

v3.12.0
=======

Expand Down
11 changes: 11 additions & 0 deletions tests/test_zipp.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,14 @@ def test_pickle(self, alpharep, path_type, subpath):
restored_1 = pickle.loads(saved_1)
first, *rest = restored_1.iterdir()
assert first.read_text().startswith('content of ')

@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
zipp.Path(zf)
zf.extractall(source_path.parent)
11 changes: 11 additions & 0 deletions zipp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down