fixed #449964: sre.sub raises an exception if the template contains a

\g<x> group reference followed by a character escape

(also restructured a few things on the way to fixing #449000)
This commit is contained in:
Fredrik Lundh 2001-09-18 20:55:24 +00:00
parent ab3b0343b8
commit 59b68656f8
4 changed files with 30 additions and 21 deletions

View file

@ -251,11 +251,13 @@ def _subn(pattern, template, text, count=0, sub=0):
else:
template = _compile_repl(template, pattern)
literals = template[1]
sub = 0 # temporarly disabled, see bug #449000
if (sub and not count and pattern._isliteral() and
len(literals) == 1 and literals[0]):
# shortcut: both pattern and string are literals
return string.replace(text, pattern.pattern, literals[0]), 0
if sub and not count:
literal = pattern._getliteral()
if literal and "\\" in literal:
literal = None # may contain untranslated escapes
if literal is not None and len(literals) == 1 and literals[0]:
# shortcut: both pattern and string are literals
return string.replace(text, pattern.pattern, literals[0]), 0
def filter(match, template=template):
return sre_parse.expand_template(template, match)
n = i = 0