Guest User

Untitled

a guest
Feb 23rd, 2013
353
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def unescape_charref(data, encoding):
  2.     try:
  3.       name, base = data, 10
  4.       if name.lower().startswith("x"):
  5.           name, base= name[1:], 16
  6.       try:
  7.           result = int(name, base)
  8.       except:
  9.           base = 16
  10.       uc = unichr(int(name, base))
  11.       if encoding is None:
  12.           return uc
  13.       else:
  14.           try:
  15.               repl = uc.encode(encoding)
  16.           except UnicodeError:
  17.               repl = "&#%s;" % data
  18.           return repl
  19.     except:
  20.       return data
RAW Paste Data