MCPcopy Create free account
hub / github.com/easy-graph/Easy-Graph / escape

Function escape

easygraph/readwrite/gml.py:55–67  ·  view source on GitHub ↗

Use XML character references to escape characters. Use XML character references for unprintable or non-ASCII characters, double quotes and ampersands in a string

(text)

Source from the content-addressed store, hash-verified

53
54
55def escape(text):
56 """Use XML character references to escape characters.
57
58 Use XML character references for unprintable or non-ASCII
59 characters, double quotes and ampersands in a string
60 """
61
62 def fixup(m):
63 ch = m.group(0)
64 return "&#" + str(ord(ch)) + ";"
65
66 text = re.sub('[^ -~]|[&"]', fixup, text)
67 return text if isinstance(text, str) else str(text)
68
69
70def unescape(text):

Callers 1

stringizeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected