Python fnmatch 模块,_MAXCACHE 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用fnmatch._MAXCACHE

项目:oil    作者:oilshell    | 项目源码 | 文件源码
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)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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)
项目:vsi_common    作者:VisionSystemsInc    | 项目源码 | 文件源码
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
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
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)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
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)