summaryrefslogtreecommitdiff
path: root/Lib/fnmatch.py
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2010-07-09 12:23:21 +0000
committerR. David Murray <rdmurray@bitdance.com>2010-07-09 12:23:21 +0000
commitea340a317a412148333c4c48807efc3af18ae4b4 (patch)
treed55f9db8eaa857d0d76df7f97baf849c1c47d06d /Lib/fnmatch.py
parentfacb0e9a764679d9a1bb76246a9c06d6f136602c (diff)
downloadcpython-git-ea340a317a412148333c4c48807efc3af18ae4b4.tar.gz
7846: limit fnmatch pattern cache to _MAXCACHE=100 entries.
Patch by Andrew Clegg.
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 30c0a922f2..26ae4ccb14 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