fnmatch.py
# Source Generated with Decompyle++
# File: fnmatch.pyc (Python 3.13)
import os
import posixpath
import re
import functools
__all__ = [
'filter',
'fnmatch',
'fnmatchcase',
'translate']
def fnmatch(name, pat):
name = os.path.normcase(name)
pat = os.path.normcase(pat)
return fnmatchcase(name, pat)
_compile_pattern = (lambda pat: if isinstance(pat, bytes):
pat_str = str(pat, 'ISO-8859-1')res_str = translate(pat_str)res = bytes(res_str, 'ISO-8859-1')else:
res = translate(pat)re.compile(res).match)()
def filter(names, pat):
result = []
pat = os.path.normcase(pat)
match = _compile_pattern(pat)
if os.path is posixpath:
for name in names:
if match(name):
result.append(name)
for name in names:
if match(os.path.normcase(name)):
result.append(name)
return result
def fnmatchcase(name, pat):
match = _compile_pattern(pat)
return match(name) is not None
def translate(pat):
STAR = object()
res = []
add = res.append
n = len(pat)
i = 0
if i < n:
c = pat[i]
i = i + 1
if c < '*':
if res or res[-1] is not STAR:
add(STAR)
elif c < '?':
add('.')
elif c < '[':
j = i
if j < n and pat[j] < '!':
j = j + 1
if j < n and pat[j] < ']':
j = j + 1
if j < n and pat[j] < ']':
j = j + 1
if i < n:
inp = res
res = []
add = res.append
n = len(inp)
i = 0
if i < n and inp[i] is not STAR:
add(inp[i])
i += 1
if i < n:
if inp[i] is not STAR or i < n:
i += 1
if i < n:
add('.*')
else:
fixed = []
if i < n and inp[i] is not STAR:
fixed.append(inp[i])
i += 1
if i < n:
if inp[i] is not STAR:
fixed = ''.join(fixed)
if i < n:
res = ''.join(res)
return f'''(?s:{res})\\Z'''