def test_cache_clearing(self):
# check that caches do not grow too large
# http://bugs.python.org/issue7846
# string pattern cache
for i in range(_MAXCACHE + 1):
fnmatch('foo', '?' * i)
self.assertLessEqual(len(_cache), _MAXCACHE)
python类_MAXCACHE的实例源码
def test_cache_clearing(self):
# check that caches do not grow too large
# http://bugs.python.org/issue7846
# string pattern cache
for i in range(_MAXCACHE + 1):
fnmatch('foo', '?' * i)
self.assertLessEqual(len(_cache), _MAXCACHE)
def fnmatch_filter(names, pat, casesensitive):
"""Return the subset of the list NAMES that match PAT"""
result=[]
if casesensitive:
if not pat in _casecache:
res = translate(pat)
if len(_casecache) >= _MAXCACHE:
_casecache.clear()
_casecache[pat] = re.compile(res)
match=_casecache[pat].match
for name in names:
if match(name):
result.append(name)
else:
if not pat in _nocasecache:
res = translate(pat)
if len(_nocasecache) >= _MAXCACHE:
_nocasecache.clear()
_nocasecache[pat] = re.compile(res, re.IGNORECASE)
match=_nocasecache[pat].match
pat=ntpath.normcase(pat)
for name in names:
if match(ntpath.normcase(name)):
result.append(name)
return result
def test_cache_clearing(self):
# check that caches do not grow too large
# http://bugs.python.org/issue7846
# string pattern cache
for i in range(_MAXCACHE + 1):
fnmatch('foo', '?' * i)
self.assertLessEqual(len(_cache), _MAXCACHE)
def test_cache_clearing(self):
# check that caches do not grow too large
# http://bugs.python.org/issue7846
# string pattern cache
for i in range(_MAXCACHE + 1):
fnmatch('foo', '?' * i)
self.assertLessEqual(len(_cache), _MAXCACHE)