def unicode_to_str(s, encoding=None):
 if (not (type(s) == unicode)):
  return s
 if (not encoding):
  encoding = ENCODING
 for c in [encoding, 'utf-8', 'latin-1']:
  try:
   return s.encode(c)
  except UnicodeDecodeError:
   pass
 return s.encode(encoding, 'replace')

def unicode_to_str ( s , encoding = None ) : if ( not ( type ( s ) == unicode ) ) : return s if ( not encoding ) : encoding = ENCODING for c in [ encoding , 'utf-8' , 'latin-1' ] : try : return s . encode ( c ) except UnicodeDecodeError : pass return s . encode ( encoding , 'replace' )
return the str representation of text in the given encoding .