summaryrefslogtreecommitdiffstats
path: root/Lib/fnmatch.py
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2010-07-09 13:16:00 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2010-07-09 13:16:00 (GMT)
commitabd4553fd46c7385537508f420e83c1793db3cad (patch)
tree8da7ee2e3a7cac811e6baa89e06ceba276b5051c /Lib/fnmatch.py
parent0e6771fd30c7025a09be9e1964ff3b9f9e9d60ec (diff)
downloadcpython-abd4553fd46c7385537508f420e83c1793db3cad.zip
cpython-abd4553fd46c7385537508f420e83c1793db3cad.tar.gz
cpython-abd4553fd46c7385537508f420e83c1793db3cad.tar.bz2
Merged revisions 82730 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k 'merge' in the sense that this is the same fix by the same author. ........ 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. ........
Diffstat (limited to 'Lib/fnmatch.py')
-rw-r--r--Lib/fnmatch.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/Lib/fnmatch.py b/Lib/fnmatch.py
index 4c149eb..b1c37f5 100644
--- a/Lib/fnmatch.py
+++ b/Lib/fnmatch.py
@@ -15,6 +15,7 @@ import re
__all__ = ["filter", "fnmatch","fnmatchcase","translate"]
_cache = {}
+_MAXCACHE = 100
def fnmatch(name, pat):
"""Test whether FILENAME matches PATTERN.
@@ -44,6 +45,8 @@ def filter(names, pat):
pat=os.path.normcase(pat)
if not pat in _cache:
res = translate(pat)
+ if len(_cache) >= _MAXCACHE:
+ _cache.clear()
_cache[pat] = re.compile(res)
match=_cache[pat].match
if os.path is posixpath:
@@ -66,6 +69,8 @@ def fnmatchcase(name, pat):
if not pat in _cache:
res = translate(pat)
+ if len(_cache) >= _MAXCACHE:
+ _cache.clear()
_cache[pat] = re.compile(res)
return _cache[pat].match(name) is not None