def escape4xml(value):
 if isinstance(value, int):
  value = str(value)
 value = _re_amp.sub('&amp;', value)
 value = value.replace('"', '&quot;').replace("'", '&apos;')
 value = value.replace('<', '&lt;').replace('>', '&gt;')
 if isinstance(value, unicode):
  value = value.encode('ascii', 'xmlcharrefreplace')
 return value

def escape4xml ( value ) : if isinstance ( value , int ) : value = str ( value ) value = _re_amp . sub ( '&amp;' , value ) value = value . replace ( '"' , '&quot;' ) . replace ( "'" , '&apos;' ) value = value . replace ( '<' , '&lt;' ) . replace ( '>' , '&gt;' ) if isinstance ( value , unicode ) : value = value . encode ( 'ascii' , 'xmlcharrefreplace' ) return value
escape some chars that cant be present in a xml value .