summaryrefslogtreecommitdiffstats
path: root/Lib/re.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-02-03 20:01:35 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-02-03 20:01:35 (GMT)
commitc49672f25ec86926ed88fd73b3b746674332c797 (patch)
tree5806f2067e8f114a331c88b50f05dd59627a684d /Lib/re.py
parentb74cf63a0895ff6bd1af82edf623a75e8ea787ee (diff)
parentd2cc743ca448866197b4ac0bcb918591827f4552 (diff)
downloadcpython-c49672f25ec86926ed88fd73b3b746674332c797.zip
cpython-c49672f25ec86926ed88fd73b3b746674332c797.tar.gz
cpython-c49672f25ec86926ed88fd73b3b746674332c797.tar.bz2
Issue #20426: When passing the re.DEBUG flag, re.compile() displays the debug output every time it is called, regardless of the compilation cache.
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 77f5e3f..2e4d87c 100644
--- a/Lib/re.py
+++ b/Lib/re.py
@@ -272,10 +272,12 @@ _pattern_type = type(sre_compile.compile("", 0))
_MAXCACHE = 512
def _compile(pattern, flags):
# internal: compile pattern
- try:
- return _cache[type(pattern), pattern, flags]
- except KeyError:
- pass
+ bypass_cache = flags & DEBUG
+ if not bypass_cache:
+ try:
+ return _cache[type(pattern), pattern, flags]
+ except KeyError:
+ pass
if isinstance(pattern, _pattern_type):
if flags:
raise ValueError(
@@ -284,9 +286,10 @@ def _compile(pattern, flags):
if not sre_compile.isstring(pattern):
raise TypeError("first argument must be string or compiled pattern")
p = sre_compile.compile(pattern, flags)
- if len(_cache) >= _MAXCACHE:
- _cache.clear()
- _cache[type(pattern), pattern, flags] = p
+ if not bypass_cache:
+ if len(_cache) >= _MAXCACHE:
+ _cache.clear()
+ _cache[type(pattern), pattern, flags] = p
return p
def _compile_repl(repl, pattern):