Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/lib64/python2..../lib2to3/pgen2
File: literals.py
# Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved.
[0] Fix | Delete
# Licensed to PSF under a Contributor Agreement.
[1] Fix | Delete
[2] Fix | Delete
"""Safely evaluate Python string literals without using eval()."""
[3] Fix | Delete
[4] Fix | Delete
import re
[5] Fix | Delete
[6] Fix | Delete
simple_escapes = {"a": "\a",
[7] Fix | Delete
"b": "\b",
[8] Fix | Delete
"f": "\f",
[9] Fix | Delete
"n": "\n",
[10] Fix | Delete
"r": "\r",
[11] Fix | Delete
"t": "\t",
[12] Fix | Delete
"v": "\v",
[13] Fix | Delete
"'": "'",
[14] Fix | Delete
'"': '"',
[15] Fix | Delete
"\\": "\\"}
[16] Fix | Delete
[17] Fix | Delete
def escape(m):
[18] Fix | Delete
all, tail = m.group(0, 1)
[19] Fix | Delete
assert all.startswith("\\")
[20] Fix | Delete
esc = simple_escapes.get(tail)
[21] Fix | Delete
if esc is not None:
[22] Fix | Delete
return esc
[23] Fix | Delete
if tail.startswith("x"):
[24] Fix | Delete
hexes = tail[1:]
[25] Fix | Delete
if len(hexes) < 2:
[26] Fix | Delete
raise ValueError("invalid hex string escape ('\\%s')" % tail)
[27] Fix | Delete
try:
[28] Fix | Delete
i = int(hexes, 16)
[29] Fix | Delete
except ValueError:
[30] Fix | Delete
raise ValueError("invalid hex string escape ('\\%s')" % tail)
[31] Fix | Delete
else:
[32] Fix | Delete
try:
[33] Fix | Delete
i = int(tail, 8)
[34] Fix | Delete
except ValueError:
[35] Fix | Delete
raise ValueError("invalid octal string escape ('\\%s')" % tail)
[36] Fix | Delete
return chr(i)
[37] Fix | Delete
[38] Fix | Delete
def evalString(s):
[39] Fix | Delete
assert s.startswith("'") or s.startswith('"'), repr(s[:1])
[40] Fix | Delete
q = s[0]
[41] Fix | Delete
if s[:3] == q*3:
[42] Fix | Delete
q = q*3
[43] Fix | Delete
assert s.endswith(q), repr(s[-len(q):])
[44] Fix | Delete
assert len(s) >= 2*len(q)
[45] Fix | Delete
s = s[len(q):-len(q)]
[46] Fix | Delete
return re.sub(r"\\(\'|\"|\\|[abfnrtv]|x.{0,2}|[0-7]{1,3})", escape, s)
[47] Fix | Delete
[48] Fix | Delete
def test():
[49] Fix | Delete
for i in range(256):
[50] Fix | Delete
c = chr(i)
[51] Fix | Delete
s = repr(c)
[52] Fix | Delete
e = evalString(s)
[53] Fix | Delete
if e != c:
[54] Fix | Delete
print i, c, s, e
[55] Fix | Delete
[56] Fix | Delete
[57] Fix | Delete
if __name__ == "__main__":
[58] Fix | Delete
test()
[59] Fix | Delete
[60] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function