PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/apps/lib/html.py

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