mirror of
https://github.com/python/cpython.git
synced 2025-10-28 01:00:34 +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.
|
_cache = {} # Maps text patterns to compiled regexen.
|
||||||
_cacheb = {} # Ditto for bytes patterns.
|
_cacheb = {} # Ditto for bytes patterns.
|
||||||
|
_MAXCACHE = 100 # Maximum size of caches
|
||||||
|
|
||||||
def fnmatch(name, pat):
|
def fnmatch(name, pat):
|
||||||
"""Test whether FILENAME matches PATTERN.
|
"""Test whether FILENAME matches PATTERN.
|
||||||
|
|
@ -48,6 +49,8 @@ def _compile_pattern(pat):
|
||||||
res = bytes(res_str, 'ISO-8859-1')
|
res = bytes(res_str, 'ISO-8859-1')
|
||||||
else:
|
else:
|
||||||
res = translate(pat)
|
res = translate(pat)
|
||||||
|
if len(cache) >= _MAXCACHE:
|
||||||
|
cache.clear()
|
||||||
cache[pat] = regex = re.compile(res)
|
cache[pat] = regex = re.compile(res)
|
||||||
return regex.match
|
return regex.match
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
from test import support
|
from test import support
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from fnmatch import fnmatch, fnmatchcase
|
from fnmatch import fnmatch, fnmatchcase, _MAXCACHE, _cache, _cacheb
|
||||||
|
|
||||||
|
|
||||||
class FnmatchTestCase(unittest.TestCase):
|
class FnmatchTestCase(unittest.TestCase):
|
||||||
|
|
@ -55,6 +55,21 @@ class FnmatchTestCase(unittest.TestCase):
|
||||||
self.check_match(b'test\xff', b'te*\xff')
|
self.check_match(b'test\xff', b'te*\xff')
|
||||||
self.check_match(b'foo\nbar', b'foo*')
|
self.check_match(b'foo\nbar', b'foo*')
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
# bytes pattern cache
|
||||||
|
for i in range(_MAXCACHE + 1):
|
||||||
|
fnmatch(b'foo', b'?' * i)
|
||||||
|
self.assertLessEqual(len(_cacheb), _MAXCACHE)
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
support.run_unittest(FnmatchTestCase)
|
support.run_unittest(FnmatchTestCase)
|
||||||
|
|
|
||||||
|
|
@ -137,6 +137,7 @@ Tom Christiansen
|
||||||
Vadim Chugunov
|
Vadim Chugunov
|
||||||
David Cinege
|
David Cinege
|
||||||
Mike Clarkson
|
Mike Clarkson
|
||||||
|
Andrew Clegg
|
||||||
Brad Clements
|
Brad Clements
|
||||||
Steve Clift
|
Steve Clift
|
||||||
Nick Coghlan
|
Nick Coghlan
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,8 @@ C-API
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #7646: The fnmatch pattern cache no longer grows without bound.
|
||||||
|
|
||||||
- Issue #9136: Fix 'dictionary changed size during iteration'
|
- Issue #9136: Fix 'dictionary changed size during iteration'
|
||||||
RuntimeError produced when profiling the decimal module. This was
|
RuntimeError produced when profiling the decimal module. This was
|
||||||
due to a dangerous iteration over 'locals()' in Context.__init__.
|
due to a dangerous iteration over 'locals()' in Context.__init__.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue