Skip to content

Commit

Permalink
Also match directories in Path.glob.
Browse files Browse the repository at this point in the history
Closes #121
  • Loading branch information
jaraco committed Aug 11, 2024
1 parent 6f900ed commit 5d89a1c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions newsfragments/121.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Also match directories in Path.glob.
3 changes: 1 addition & 2 deletions zipp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,7 @@ def glob(self, pattern):
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}')
Expand Down
10 changes: 9 additions & 1 deletion zipp/glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def translate(self, pattern):
"""
Given a glob pattern, produce a regex that matches it.
"""
return self.extend(self.translate_core(pattern))
return self.extend(self.match_dirs(self.translate_core(pattern)))

def extend(self, pattern):
r"""
Expand All @@ -41,6 +41,14 @@ def extend(self, pattern):
"""
return rf'(?s:{pattern})\Z'

def match_dirs(self, pattern):
"""
Ensure that zipfile.Path directory names are matched.
zipfile.Path directory names always end in a slash.
"""
return rf'{pattern}[/]?'

def translate_core(self, pattern):
r"""
Given a glob pattern, produce a regex that matches it.
Expand Down

0 comments on commit 5d89a1c

Please sign in to comment.