Skip to content

Commit 5d89a1c

Browse files
committed
Also match directories in Path.glob.
Closes #121
1 parent 6f900ed commit 5d89a1c

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

newsfragments/121.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Also match directories in Path.glob.

zipp/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,7 @@ def glob(self, pattern):
470470
prefix = re.escape(self.at)
471471
tr = Translator(seps='/')
472472
matches = re.compile(prefix + tr.translate(pattern)).fullmatch
473-
names = (data.filename for data in self.root.filelist)
474-
return map(self._next, filter(matches, names))
473+
return map(self._next, filter(matches, self.root.namelist()))
475474

476475
def rglob(self, pattern):
477476
return self.glob(f'**/{pattern}')

zipp/glob.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def translate(self, pattern):
2828
"""
2929
Given a glob pattern, produce a regex that matches it.
3030
"""
31-
return self.extend(self.translate_core(pattern))
31+
return self.extend(self.match_dirs(self.translate_core(pattern)))
3232

3333
def extend(self, pattern):
3434
r"""
@@ -41,6 +41,14 @@ def extend(self, pattern):
4141
"""
4242
return rf'(?s:{pattern})\Z'
4343

44+
def match_dirs(self, pattern):
45+
"""
46+
Ensure that zipfile.Path directory names are matched.
47+
48+
zipfile.Path directory names always end in a slash.
49+
"""
50+
return rf'{pattern}[/]?'
51+
4452
def translate_core(self, pattern):
4553
r"""
4654
Given a glob pattern, produce a regex that matches it.

0 commit comments

Comments
 (0)