gh-122903: Honor directories in zipfile.Path.glob. (#122908)

This commit is contained in:
Jason R. Coombs 2024-08-11 20:33:33 -04:00 committed by GitHub
parent 9cd0326310
commit 6aa35f3002
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 40 additions and 9 deletions

View file

@ -250,7 +250,10 @@ def _extract_text_encoding(encoding=None, *args, **kwargs):
class Path:
"""
A pathlib-compatible interface for zip files.
A :class:`importlib.resources.abc.Traversable` interface for zip files.
Implements many of the features users enjoy from
:class:`pathlib.Path`.
Consider a zip file with this structure::
@ -466,8 +469,7 @@ class Path:
prefix = re.escape(self.at)
tr = Translator(seps='/')
matches = re.compile(prefix + tr.translate(pattern)).fullmatch
names = (data.filename for data in self.root.filelist)
return map(self._next, filter(matches, names))
return map(self._next, filter(matches, self.root.namelist()))
def rglob(self, pattern):
return self.glob(f'**/{pattern}')