mirror of https://github.com/python/cpython.git
avoid eval() like the plague
This commit is contained in:
parent
dc42b8aa3d
commit
9e6aa9d55b
|
@ -107,6 +107,7 @@ def expand(repl, regs, str):
|
||||||
return repl
|
return repl
|
||||||
new = ''
|
new = ''
|
||||||
i = 0
|
i = 0
|
||||||
|
ord0 = ord('0')
|
||||||
while i < len(repl):
|
while i < len(repl):
|
||||||
c = repl[i]; i = i+1
|
c = repl[i]; i = i+1
|
||||||
if c <> '\\' or i >= len(repl):
|
if c <> '\\' or i >= len(repl):
|
||||||
|
@ -114,7 +115,7 @@ def expand(repl, regs, str):
|
||||||
else:
|
else:
|
||||||
c = repl[i]; i = i+1
|
c = repl[i]; i = i+1
|
||||||
if '0' <= c <= '9':
|
if '0' <= c <= '9':
|
||||||
a, b = regs[eval(c)]
|
a, b = regs[ord(c)-ord0]
|
||||||
new = new + str[a:b]
|
new = new + str[a:b]
|
||||||
elif c == '\\':
|
elif c == '\\':
|
||||||
new = new + c
|
new = new + c
|
||||||
|
|
Loading…
Reference in New Issue