MCPcopy Index your code
hub / github.com/clips/pattern / decode_entities

Function decode_entities

pattern/db/__init__.py:249–265  ·  view source on GitHub ↗

Decodes HTML entities in the given string ("&lt;" => "<").

(string)

Source from the content-addressed store, hash-verified

247 return string
248
249def decode_entities(string):
250 """ Decodes HTML entities in the given string ("&lt;" => "<").
251 """
252 # http://snippets.dzone.com/posts/show/4569
253 def replace_entity(match):
254 hash, hex, name = match.group(1), match.group(2), match.group(3)
255 if hash == "#" or name.isdigit():
256 if hex == '' :
257 return unichr(int(name)) # "&#38;" => "&"
258 if hex in ("x","X"):
259 return unichr(int('0x'+name, 16)) # "&#x0026;" = > "&"
260 else:
261 cp = htmlentitydefs.name2codepoint.get(name) # "&amp;" => "&"
262 return cp and unichr(cp) or match.group() # "&foo;" => "&foo;"
263 if isinstance(string, (str, unicode)):
264 return RE_UNICODE.subn(replace_entity, string)[0]
265 return string
266
267class _Binary:
268 """ A wrapper for BLOB data with engine-specific encoding.

Callers 1

parse_tokenMethod · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…