mirror of https://github.com/python/cpython.git
Modest speed improvement to escape() by Piet van Oostrum.
This commit is contained in:
parent
7333c4cafc
commit
3a8d1f5a6b
10
Lib/re.py
10
Lib/re.py
|
@ -64,13 +64,13 @@ def findall(pattern, string):
|
|||
|
||||
def escape(pattern):
|
||||
"Escape all non-alphanumeric characters in pattern."
|
||||
result = []
|
||||
result = list(pattern)
|
||||
alphanum=string.letters+'_'+string.digits
|
||||
for char in pattern:
|
||||
for i in range(len(pattern)):
|
||||
char = pattern[i]
|
||||
if char not in alphanum:
|
||||
if char=='\000': result.append('\\000')
|
||||
else: result.append('\\'+char)
|
||||
else: result.append(char)
|
||||
if char=='\000': result[i] = '\\000'
|
||||
else: result[i] = '\\'+char
|
||||
return string.join(result, '')
|
||||
|
||||
def compile(pattern, flags=0):
|
||||
|
|
Loading…
Reference in New Issue