/apps/lib/html.py
Python | 15 lines | 10 code | 4 blank | 1 comment | 2 complexity | a96393838ae5ae7a96c40beb206aa7a1 MD5 | raw file
Possible License(s): BSD-3-Clause
- import htmlentitydefs
- import re
- pattern = re.compile("&(\w+?);")
- def descape_entity(m, defs=htmlentitydefs.name2codepoint):
- # callback: translate one entity to its ISO Latin value
- try:
- return unichr(defs[m.group(1)])
- except KeyError:
- return m.group(0) # use as is
- def descape(string):
- return pattern.sub(descape_entity, string)