本文整理匯總了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)