def encode_html(unicode_data, encoding=u'ascii'):
 try:
  return unicode_data.encode(encoding, u'xmlcharrefreplace')
 except ValueError:
  return _xmlcharref_encode(unicode_data, encoding)

def encode_html ( unicode_data , encoding = u'ascii' ) : try : return unicode_data . encode ( encoding , u'xmlcharrefreplace' ) except ValueError : return _xmlcharref_encode ( unicode_data , encoding )
encode unicode_data for use as xml or html .