import os,posixpath
result=[]
pat=os.path.normcase(pat)
- if not pat in _cache:
+ try:
+ re_pat = _cache[pat]
+ except KeyError:
res = translate(pat)
if len(_cache) >= _MAXCACHE:
_cache.clear()
- _cache[pat] = re.compile(res)
- match=_cache[pat].match
+ _cache[pat] = re_pat = re.compile(res)
+ match = re_pat.match
if os.path is posixpath:
# normcase on posix is NOP. Optimize it away from the loop.
for name in names:
its arguments.
"""
- if not pat in _cache:
+ try:
+ re_pat = _cache[pat]
+ except KeyError:
res = translate(pat)
if len(_cache) >= _MAXCACHE:
_cache.clear()
- _cache[pat] = re.compile(res)
- return _cache[pat].match(name) is not None
+ _cache[pat] = re_pat = re.compile(res)
+ return re_pat.match(name) is not None
def translate(pat):
"""Translate a shell PATTERN to a regular expression.
Library
-------
+- Issue #23191: fnmatch functions that use caching are now threadsafe.
+
- Issue #18518: timeit now rejects statements which can't be compiled outside
a function or a loop (e.g. "return" or "break").