def htmldecode(text, use_repr=False):
 def entitydecode(match):
  entity = match.group(1)
  try:
   if entity.startswith('#x'):
    return unichr(int(entity[2:], 16))
   elif entity.startswith('#'):
    return unichr(int(entity[1:]))
   elif (entity in name2codepoint):
    return unichr(name2codepoint[entity])
   else:
    return match.group(0)
  except:
   return match.group(0)
 if (not isinstance(text, unicode)):
  text = text.decode(DEFAULT_ENCODING, errors=HTML_ENCODE)
 return CHAR_REF_PATT.sub(entitydecode, text)

def htmldecode ( text , use_repr = False ) : def entitydecode ( match ) : entity = match . group ( 1 ) try : if entity . startswith ( '#x' ) : return unichr ( int ( entity [ 2 : ] , 16 ) ) elif entity . startswith ( '#' ) : return unichr ( int ( entity [ 1 : ] ) ) elif ( entity in name2codepoint ) : return unichr ( name2codepoint [ entity ] ) else : return match . group ( 0 ) except : return match . group ( 0 ) if ( not isinstance ( text , unicode ) ) : text = text . decode ( DEFAULT_ENCODING , errors = HTML_ENCODE ) return CHAR_REF_PATT . sub ( entitydecode , text )
decode html entities in the given text .