blob: 515f8c39afd28a46f0fe8ca0ebe1e17cf2a1d459 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
def escape(data, entities={}):
assert not entities
return data.replace("&", "&").replace(">", ">").replace("<", "<")
def unescape(data, entities={}):
assert not entities
return data.replace("<", "<").replace(">", ">").replace("&", "&")
def quoteattr(data, entities={}):
assert not entities
data = escape(data).replace("\n", " ").replace("\r", " ").replace("\t", "	")
if '"' in data:
if "'" in data:
return '"' + data.replace('"', """) + '"'
else:
return "'" + data + "'"
else:
return '"' + data + '"'
|