summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-01-27 09:40:51 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-01-27 09:40:51 (GMT)
commit3ce465ab56568d5d53b1985cbb3ebe5961bfbf18 (patch)
tree9d7345161968ca60669840a1c50e950a3d155b90
parentc328d11ef184e706e42149d740d99044d7d8981a (diff)
downloadcpython-3ce465ab56568d5d53b1985cbb3ebe5961bfbf18.zip
cpython-3ce465ab56568d5d53b1985cbb3ebe5961bfbf18.tar.gz
cpython-3ce465ab56568d5d53b1985cbb3ebe5961bfbf18.tar.bz2
Issue #23191: fnmatch functions that use caching are now threadsafe.
-rw-r--r--Lib/fnmatch.py16
-rw-r--r--Misc/NEWS2
2 files changed, 12 insertions, 6 deletions
diff --git a/Lib/fnmatch.py b/Lib/fnmatch.py
index ffe99b5..99002e6 100644
--- a/Lib/fnmatch.py
+++ b/Lib/fnmatch.py
@@ -47,12 +47,14 @@ def filter(names, pat):
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:
@@ -71,12 +73,14 @@ def fnmatchcase(name, pat):
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.
diff --git a/Misc/NEWS b/Misc/NEWS
index 6e466e4..593b70b 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,8 @@ Core and Builtins
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").