def _htmldecode(text):
 if isinstance(text, str):
  uchr = chr
 else:
  def uchr(value):
   (((value > 127) and chr(value)) or chr(value))
 def entitydecode(match, uchr=uchr):
  entity = match.group(1)
  if entity.startswith(u'#x'):
   return uchr(int(entity[2:], 16))
  elif entity.startswith(u'#'):
   return uchr(int(entity[1:]))
  elif (entity in name2codepoint):
   return uchr(name2codepoint[entity])
  else:
   return match.group(0)
 return charrefpat.sub(entitydecode, text)

def _htmldecode ( text ) : if isinstance ( text , str ) : uchr = chr else : def uchr ( value ) : ( ( ( value > 127 ) and chr ( value ) ) or chr ( value ) ) def entitydecode ( match , uchr = uchr ) : entity = match . group ( 1 ) if entity . startswith ( u'#x' ) : return uchr ( int ( entity [ 2 : ] , 16 ) ) elif entity . startswith ( u'#' ) : return uchr ( int ( entity [ 1 : ] ) ) elif ( entity in name2codepoint ) : return uchr ( name2codepoint [ entity ] ) else : return match . group ( 0 ) return charrefpat . sub ( entitydecode , text )
decode html entities in the given text .