diff options
author | R. David Murray <rdmurray@bitdance.com> | 2010-07-09 12:23:21 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2010-07-09 12:23:21 (GMT) |
commit | ea340a317a412148333c4c48807efc3af18ae4b4 (patch) | |
tree | d55f9db8eaa857d0d76df7f97baf849c1c47d06d /Lib/fnmatch.py | |
parent | facb0e9a764679d9a1bb76246a9c06d6f136602c (diff) | |
download | cpython-ea340a317a412148333c4c48807efc3af18ae4b4.zip cpython-ea340a317a412148333c4c48807efc3af18ae4b4.tar.gz cpython-ea340a317a412148333c4c48807efc3af18ae4b4.tar.bz2 |
7846: limit fnmatch pattern cache to _MAXCACHE=100 entries.
Patch by Andrew Clegg.
Diffstat (limited to 'Lib/fnmatch.py')
-rw-r--r-- | Lib/fnmatch.py | 3 |
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 |