Skip to content

Commit

Permalink
Provide rudimentary glob to regex translation. Fixes jaraco#98
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jul 13, 2023
1 parent 9fb56c5 commit 43fd698
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions zipp/__init__.py
Expand Up @@ -5,14 +5,20 @@
import contextlib
import pathlib
import re
import fnmatch

from .py310compat import text_encoding


__all__ = ['Path']


def _translate(pattern):
"""
Given a glob pattern, produce a regex that matches it.
"""
return pattern.replace('**', r'.*').replace('*', r'[^/]*')


def _parents(path):
"""
Given a path with elements separated by
Expand Down Expand Up @@ -367,7 +373,7 @@ def glob(self, pattern):
if not pattern:
raise ValueError(f"Unacceptable pattern: {pattern!r}")

matches = re.compile(fnmatch.translate(pattern)).fullmatch
matches = re.compile(_translate(pattern)).fullmatch
return (
child
for child in self._descendants()
Expand Down

0 comments on commit 43fd698

Please sign in to comment.