mirror of
https://github.com/python/cpython.git
synced 2025-09-03 15:31:08 +00:00
Merged revisions 82730-82731 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ 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. ........ r82731 | r.david.murray | 2010-07-09 09:14:03 -0400 (Fri, 09 Jul 2010) | 2 lines Fix sort order mistake in Misc/ACKS. ........
This commit is contained in:
parent
921d30d261
commit
ead883a366
4 changed files with 22 additions and 1 deletions
|
@ -16,6 +16,7 @@ __all__ = ["filter", "fnmatch","fnmatchcase","translate"]
|
|||
|
||||
_cache = {} # Maps text patterns to compiled regexen.
|
||||
_cacheb = {} # Ditto for bytes patterns.
|
||||
_MAXCACHE = 100 # Maximum size of caches
|
||||
|
||||
def fnmatch(name, pat):
|
||||
"""Test whether FILENAME matches PATTERN.
|
||||
|
@ -48,6 +49,8 @@ def _compile_pattern(pat):
|
|||
res = bytes(res_str, 'ISO-8859-1')
|
||||
else:
|
||||
res = translate(pat)
|
||||
if len(cache) >= _MAXCACHE:
|
||||
cache.clear()
|
||||
cache[pat] = regex = re.compile(res)
|
||||
return regex.match
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue