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

def str_to_unicode ( s , encoding = None ) : if ( not ( type ( s ) == str ) ) : return s if ( not encoding ) : encoding = ENCODING for c in [ encoding , 'utf-8' , 'latin-1' ] : try : return s . decode ( c ) except UnicodeDecodeError : pass return s . decode ( encoding , 'replace' )
attempts to convert a string of unknown character set to a unicode string .