xml转义字符
from xml.sax.saxutils import escape
def xmlescape(data):
if data is None:
data = ''
elif not isinstance(data, str):
data = str(data)
return escape(data, entities={"'": "'", '"': """})
html转义字符
def html_escape(s):
htmlcodes = (
('&', '&'),
("'", '''),
('"', '"'),
('>', '>'),
('<', '<'),
)
for code in htmlcodes:
s = s.replace(code[0], code[1])
return s