summaryrefslogtreecommitdiffstats
path: root/Lib/re.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/re.py')
-rw-r--r--Lib/re.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/Lib/re.py b/Lib/re.py
index aab5d37..9b01f3e 100644
--- a/Lib/re.py
+++ b/Lib/re.py
@@ -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):