Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
a bit of PEP-8
  • Loading branch information
picnixz committed Apr 7, 2025
commit 4e3ec142dac7bbb194ec1f6d0b8330edecabc21d
9 changes: 8 additions & 1 deletion Lib/fnmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import posixpath
import re

__all__ = ["filter", "fnmatch", "fnmatchcase", "translate"]
__all__ = ["filter", "filterfalse", "fnmatch", "fnmatchcase", "translate"]


def fnmatch(name, pat):
"""Test whether FILENAME matches PATTERN.
Expand All @@ -37,6 +38,7 @@ def fnmatch(name, pat):
pat = os.path.normcase(pat)
return fnmatchcase(name, pat)


@functools.lru_cache(maxsize=32768, typed=True)
def _compile_pattern(pat):
if isinstance(pat, bytes):
Expand All @@ -47,6 +49,7 @@ def _compile_pattern(pat):
res = translate(pat)
return re.compile(res).match


def filter(names, pat):
"""Construct a list from those elements of the iterable NAMES that match PAT."""
result = []
Expand All @@ -63,6 +66,7 @@ def filter(names, pat):
result.append(name)
return result


def filterfalse(names, pat):
"""Construct a list from those elements of the iterable NAMES that do not match PAT."""
pat = os.path.normcase(pat)
Expand All @@ -77,6 +81,7 @@ def filterfalse(names, pat):
result.append(name)
return result


def fnmatchcase(name, pat):
"""Test whether FILENAME matches PATTERN, including case.

Expand All @@ -96,9 +101,11 @@ def translate(pat):
parts, star_indices = _translate(pat, '*', '.')
return _join_translated_parts(parts, star_indices)


_re_setops_sub = re.compile(r'([&~|])').sub
_re_escape = functools.lru_cache(maxsize=512)(re.escape)


def _translate(pat, star, question_mark):
res = []
add = res.append
Expand Down
Loading