mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
7846: limit fnmatch pattern cache to _MAXCACHE=100 entries.
Patch by Andrew Clegg.
This commit is contained in:
parent
facb0e9a76
commit
ea340a317a
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