SHARE
TWEET

Untitled

a guest Feb 23rd, 2013 232 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
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top