]> granicus.if.org Git - python/commitdiff
avoid eval() like the plague
authorGuido van Rossum <guido@python.org>
Tue, 28 May 1996 23:01:28 +0000 (23:01 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 28 May 1996 23:01:28 +0000 (23:01 +0000)
Lib/regsub.py

index 7eb175b60ec5ca25a39d44a41fc3a1d93ce2f079..507e542882ff2a628627294bd408a95a094881fe 100644 (file)
@@ -107,6 +107,7 @@ def expand(repl, regs, str):
                return repl
        new = ''
        i = 0
+       ord0 = ord('0')
        while i < len(repl):
                c = repl[i]; i = i+1
                if c <> '\\' or i >= len(repl):
@@ -114,7 +115,7 @@ def expand(repl, regs, str):
                else:
                        c = repl[i]; i = i+1
                        if '0' <= c <= '9':
-                               a, b = regs[eval(c)]
+                               a, b = regs[ord(c)-ord0]
                                new = new + str[a:b]
                        elif c == '\\':
                                new = new + c