diff options
Diffstat (limited to 'Lib/re.py')
-rw-r--r-- | Lib/re.py | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -225,11 +225,13 @@ _MAXCACHE = 100 def _compile(*key): # internal: compile pattern - cachekey = (type(key[0]),) + key - p = _cache.get(cachekey) - if p is not None: - return p pattern, flags = key + bypass_cache = flags & DEBUG + if not bypass_cache: + cachekey = (type(key[0]),) + key + p = _cache.get(cachekey) + if p is not None: + return p if isinstance(pattern, _pattern_type): if flags: raise ValueError('Cannot process flags argument with a compiled pattern') @@ -240,9 +242,10 @@ def _compile(*key): p = sre_compile.compile(pattern, flags) except error, v: raise error, v # invalid expression - if len(_cache) >= _MAXCACHE: - _cache.clear() - _cache[cachekey] = p + if not bypass_cache: + if len(_cache) >= _MAXCACHE: + _cache.clear() + _cache[cachekey] = p return p def _compile_repl(*key): |