本文整理汇总了Python中fnmatch._cache方法的典型用法代码示例。如果您正苦于以下问题:Python fnmatch._cache方法的具体用法?Python fnmatch._cache怎么用?Python fnmatch._cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fnmatch
的用法示例。
在下文中一共展示了fnmatch._cache方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: filter
# 需要导入模块: import fnmatch [as 别名]
# 或者: from fnmatch import _cache [as 别名]
def filter(names, pat):
"""Return the subset of the list NAMES that match PAT"""
import os,posixpath
result=[]
pat = os.path.normcase(pat)
if pat not in fnmatch._cache:
import re
res = fnmatch.translate(pat)
fnmatch._cache[pat] = re.compile(res)
match = fnmatch._cache[pat].match
if os.path is posixpath:
# normcase on posix is NOP. Optimize it away from the loop.
for name in names:
if match(name):
result.append(name)
else:
for name in names:
if match(os.path.normcase(name)):
result.append(name)
return result
示例2: test_cache_clearing
# 需要导入模块: import fnmatch [as 别名]
# 或者: from fnmatch import _cache [as 别名]
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)