def convert_to_unicode(s, encoding_list):
 if isinstance(s, bytearray):
  s = bytes(s)
 if isinstance(s, six.text_type):
  return (u'utf-8', s)
 elif isinstance(s, six.string_types):
  try:
   enc = u'utf-8'
   return (enc, six.text_type(s, enc))
  except UnicodeError:
   for e in encoding_list:
    try:
     return (e, six.text_type(s, e))
    except (UnicodeError, LookupError):
     pass
   try:
    enc = u'utf-8'
    return (enc, six.text_type(s, enc, errors=u'replace'))
   except UnicodeError:
    raise Exception((_(u"Diff content couldn't be converted to unicode using the following encodings: %s") % ([u'utf-8'] + encoding_list)))
 else:
  raise TypeError(u'Value to convert is unexpected type %s', type(s))

def convert_to_unicode ( s , encoding_list ) : if isinstance ( s , bytearray ) : s = bytes ( s ) if isinstance ( s , six . text_type ) : return ( u'utf-8' , s ) elif isinstance ( s , six . string_types ) : try : enc = u'utf-8' return ( enc , six . text_type ( s , enc ) ) except UnicodeError : for e in encoding_list : try : return ( e , six . text_type ( s , e ) ) except ( UnicodeError , LookupError ) : pass try : enc = u'utf-8' return ( enc , six . text_type ( s , enc , errors = u'replace' ) ) except UnicodeError : raise Exception ( ( _ ( u"Diff content couldn't be converted to unicode using the following encodings: %s" ) % ( [ u'utf-8' ] + encoding_list ) ) ) else : raise TypeError ( u'Value to convert is unexpected type %s' , type ( s ) )
returns the passed string as a unicode object .