def xmlescape(data, quote=True):
 if (hasattr(data, 'xml') and callable(data.xml)):
  return to_bytes(data.xml())
 if (not isinstance(data, (text_type, bytes))):
  data = str(data)
 data = to_bytes(data, 'utf8', 'xmlcharrefreplace')
 data = local_html_escape(data, quote)
 return data

def xmlescape ( data , quote = True ) : if ( hasattr ( data , 'xml' ) and callable ( data . xml ) ) : return to_bytes ( data . xml ( ) ) if ( not isinstance ( data , ( text_type , bytes ) ) ) : data = str ( data ) data = to_bytes ( data , 'utf8' , 'xmlcharrefreplace' ) data = local_html_escape ( data , quote ) return data
returns an escaped string of the provided data args: data: the data to be escaped quote: optional .