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

Function unescape

easygraph/readwrite/gml.py:70–92  ·  view source on GitHub ↗

Replace XML character references with the referenced characters

(text)

Source from the content-addressed store, hash-verified

68
69
70def unescape(text):
71 """Replace XML character references with the referenced characters"""
72
73 def fixup(m):
74 text = m.group(0)
75 if text[1] == "#":
76 # Character reference
77 if text[2] == "x":
78 code = int(text[3:-1], 16)
79 else:
80 code = int(text[2:-1])
81 else:
82 # Named entity
83 try:
84 code = htmlentitydefs.name2codepoint[text[1:-1]]
85 except KeyError:
86 return text # leave unchanged
87 try:
88 return chr(code)
89 except (ValueError, OverflowError):
90 return text # leave unchanged
91
92 return re.sub("&(?:[0-9A-Za-z]+|#(?:[0-9]+|x[0-9A-Fa-f]+));", fixup, text)
93
94
95def literal_destringizer(rep):

Callers 1

parse_kvFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected