summaryrefslogtreecommitdiffstats
path: root/Lib/fnmatch.py
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2010-07-09 13:16:26 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2010-07-09 13:16:26 (GMT)
commitead883a366b90df45de02c527e88b5200ad04f81 (patch)
tree7cf1ff37b45c33985415eb9c73a1dbaf85270014 /Lib/fnmatch.py
parent921d30d2611c3efb5dd7081d93d02415da5b49ea (diff)
downloadcpython-ead883a366b90df45de02c527e88b5200ad04f81.zip
cpython-ead883a366b90df45de02c527e88b5200ad04f81.tar.gz
cpython-ead883a366b90df45de02c527e88b5200ad04f81.tar.bz2
Merged revisions 82730-82731 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r82730 | r.david.murray | 2010-07-09 08:23:21 -0400 (Fri, 09 Jul 2010) | 4 lines 7846: limit fnmatch pattern cache to _MAXCACHE=100 entries. Patch by Andrew Clegg. ........ r82731 | r.david.murray | 2010-07-09 09:14:03 -0400 (Fri, 09 Jul 2010) | 2 lines Fix sort order mistake in Misc/ACKS. ........
Diffstat (limited to 'Lib/fnmatch.py')
-rw-r--r--Lib/fnmatch.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/Lib/fnmatch.py b/Lib/fnmatch.py
index 30c0a92..26ae4cc 100644
--- a/Lib/fnmatch.py
+++ b/Lib/fnmatch.py
@@ -16,6 +16,7 @@ __all__ = ["filter", "fnmatch","fnmatchcase","translate"]
_cache = {} # Maps text patterns to compiled regexen.
_cacheb = {} # Ditto for bytes patterns.
+_MAXCACHE = 100 # Maximum size of caches
def fnmatch(name, pat):
"""Test whether FILENAME matches PATTERN.
@@ -48,6 +49,8 @@ def _compile_pattern(pat):
res = bytes(res_str, 'ISO-8859-1')
else:
res = translate(pat)
+ if len(cache) >= _MAXCACHE:
+ cache.clear()
cache[pat] = regex = re.compile(res)
return regex.match