diff options
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 |