summaryrefslogtreecommitdiffstats
path: root/Lib/re.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-02-03 19:59:59 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-02-03 19:59:59 (GMT)
commitd2cc743ca448866197b4ac0bcb918591827f4552 (patch)
tree65eb723dff7cff862368a72fb572e0d62d6c8f58 /Lib/re.py
parentb3de1a720a7dffcf86bf7e7301263590b5972186 (diff)
downloadcpython-d2cc743ca448866197b4ac0bcb918591827f4552.zip
cpython-d2cc743ca448866197b4ac0bcb918591827f4552.tar.gz
cpython-d2cc743ca448866197b4ac0bcb918591827f4552.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 fcea190..a46ecc8 100644
--- a/Lib/re.py
+++ b/Lib/re.py
@@ -267,10 +267,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(
@@ -279,9 +281,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):