def _replXMLRef(match):
 ref = match.group(1)
 value = entcharrefsget(ref)
 if (value is None):
  if (ref[0] == '#'):
   ref_code = ref[1:]
   if (ref_code in ('34', '38', '60', '62', '39')):
    return match.group(0)
   elif (ref_code[0].lower() == 'x'):
    return unichr(int(ref[2:], 16))
   else:
    return unichr(int(ref[1:]))
  else:
   return ref
 return value

def _replXMLRef ( match ) : ref = match . group ( 1 ) value = entcharrefsget ( ref ) if ( value is None ) : if ( ref [ 0 ] == '#' ) : ref_code = ref [ 1 : ] if ( ref_code in ( '34' , '38' , '60' , '62' , '39' ) ) : return match . group ( 0 ) elif ( ref_code [ 0 ] . lower ( ) == 'x' ) : return unichr ( int ( ref [ 2 : ] , 16 ) ) else : return unichr ( int ( ref [ 1 : ] ) ) else : return ref return value
replace the matched xml/html entities and references; replace everything except sgml entities like &lt; .