Commit db848035 authored by Raymond Hettinger's avatar Raymond Hettinger

Simplify calls in fnmatch.

parent cd9fdfd6
...@@ -35,9 +35,9 @@ def fnmatch(name, pat): ...@@ -35,9 +35,9 @@ def fnmatch(name, pat):
pat = os.path.normcase(pat) pat = os.path.normcase(pat)
return fnmatchcase(name, pat) return fnmatchcase(name, pat)
@functools.lru_cache(maxsize=250) @functools.lru_cache(maxsize=250, typed=True)
def _compile_pattern(pat, is_bytes=False): def _compile_pattern(pat):
if is_bytes: if isinstance(pat, bytes):
pat_str = str(pat, 'ISO-8859-1') pat_str = str(pat, 'ISO-8859-1')
res_str = translate(pat_str) res_str = translate(pat_str)
res = bytes(res_str, 'ISO-8859-1') res = bytes(res_str, 'ISO-8859-1')
...@@ -49,7 +49,7 @@ def filter(names, pat): ...@@ -49,7 +49,7 @@ def filter(names, pat):
"""Return the subset of the list NAMES that match PAT.""" """Return the subset of the list NAMES that match PAT."""
result = [] result = []
pat = os.path.normcase(pat) pat = os.path.normcase(pat)
match = _compile_pattern(pat, isinstance(pat, bytes)) match = _compile_pattern(pat)
if os.path is posixpath: if os.path is posixpath:
# normcase on posix is NOP. Optimize it away from the loop. # normcase on posix is NOP. Optimize it away from the loop.
for name in names: for name in names:
...@@ -67,7 +67,7 @@ def fnmatchcase(name, pat): ...@@ -67,7 +67,7 @@ def fnmatchcase(name, pat):
This is a version of fnmatch() which doesn't case-normalize This is a version of fnmatch() which doesn't case-normalize
its arguments. its arguments.
""" """
match = _compile_pattern(pat, isinstance(pat, bytes)) match = _compile_pattern(pat)
return match(name) is not None return match(name) is not None
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment