def encode_for_xml(ustr, encoding='ascii'):
 if isinstance(ustr, unicode):
  pass
 elif isinstance(ustr, str):
  ustr = ustr.decode(codepage, 'replace')
 else:
  ustr = unicode(str(ustr))
 return ustr.encode(encoding, 'xmlcharrefreplace')

def encode_for_xml ( ustr , encoding = 'ascii' ) : if isinstance ( ustr , unicode ) : pass elif isinstance ( ustr , str ) : ustr = ustr . decode ( codepage , 'replace' ) else : ustr = unicode ( str ( ustr ) ) return ustr . encode ( encoding , 'xmlcharrefreplace' )
encode unicode_data for use as xml or html .