def unescape_xml(text):
 def fixup(m):
  txt = m.group(0)
  if (txt[:2] == '&#'):
   try:
    if (txt[:3] == '&#x'):
     return chr(int(txt[3:(-1)], 16))
    else:
     return chr(int(txt[2:(-1)]))
   except ValueError:
    pass
  else:
   try:
    txt = chr(entities.name2codepoint[txt[1:(-1)]])
   except KeyError:
    pass
  return txt
 return re.sub('&#?\\w+;', fixup, text)

def unescape_xml ( text ) : def fixup ( m ) : txt = m . group ( 0 ) if ( txt [ : 2 ] == '&#' ) : try : if ( txt [ : 3 ] == '&#x' ) : return chr ( int ( txt [ 3 : ( - 1 ) ] , 16 ) ) else : return chr ( int ( txt [ 2 : ( - 1 ) ] ) ) except ValueError : pass else : try : txt = chr ( entities . name2codepoint [ txt [ 1 : ( - 1 ) ] ] ) except KeyError : pass return txt return re . sub ( '&#?\\w+;' , fixup , text )
removes html or xml character references and entities from a text string .