summaryrefslogtreecommitdiffstats
path: root/libs/tiny_xml/xml/sax/saxutils.py
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("&", "&amp;").replace(">", "&gt;").replace("<", "&lt;")

def unescape(data, entities={}):
	assert not entities
	return data.replace("&lt;", "<").replace("&gt;", ">").replace("&amp;", "&")

def quoteattr(data, entities={}):
	assert not entities
	data = escape(data).replace("\n", "&#10;").replace("\r", "&#13;").replace("\t", "&#9;")
	if '"' in data:
		if "'" in data:
			return '"' + data.replace('"', "&quot;") + '"'
		else:
			return "'" + data + "'"
	else:
		return '"' + data + '"'
bues.ch cgit interface