[Python-checkins] CVS: python/dist/src/Lib sre.py,1.37,1.38 sre_parse.py,1.47,1.48
Fredrik Lundh
effbot@users.sourceforge.net
Tue, 18 Sep 2001 13:55:27 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv30223/Lib
Modified Files:
sre.py sre_parse.py
Log Message:
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)
Index: sre.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre.py,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** sre.py 2001/09/18 18:47:09 1.37
--- sre.py 2001/09/18 20:55:24 1.38
***************
*** 252,260 ****
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
def filter(match, template=template):
return sre_parse.expand_template(template, match)
--- 252,262 ----
template = _compile_repl(template, pattern)
literals = template[1]
! 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)
Index: sre_parse.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre_parse.py,v
retrieving revision 1.47
retrieving revision 1.48
diff -C2 -d -r1.47 -r1.48
*** sre_parse.py 2001/09/04 19:10:20 1.47
--- sre_parse.py 2001/09/18 20:55:24 1.48
***************
*** 648,654 ****
sep = source[:0]
if type(sep) is type(""):
! char = chr
else:
! char = unichr
while 1:
this = s.get()
--- 648,654 ----
sep = source[:0]
if type(sep) is type(""):
! makechar = chr
else:
! makechar = unichr
while 1:
this = s.get()
***************
*** 694,698 ****
if not code:
this = this[1:]
! code = LITERAL, char(atoi(this[-6:], 8) & 0xff)
if code[0] is LITERAL:
literal(code[1])
--- 694,698 ----
if not code:
this = this[1:]
! code = LITERAL, makechar(atoi(this[-6:], 8) & 0xff)
if code[0] is LITERAL:
literal(code[1])
***************
*** 701,705 ****
else:
try:
! this = char(ESCAPES[this][1])
except KeyError:
pass
--- 701,705 ----
else:
try:
! this = makechar(ESCAPES[this][1])
except KeyError:
pass