def s3_unicode(s, encoding='utf-8'):
 if (type(s) is unicode):
  return s
 try:
  if (not isinstance(s, basestring)):
   if hasattr(s, '__unicode__'):
    s = unicode(s)
   else:
    try:
     s = unicode(str(s), encoding, 'strict')
    except UnicodeEncodeError:
     if (not isinstance(s, Exception)):
      raise
     s = ' '.join([s3_unicode(arg, encoding) for arg in s])
  else:
   s = s.decode(encoding)
 except UnicodeDecodeError:
  if (not isinstance(s, Exception)):
   raise
  s = ' '.join([s3_unicode(arg, encoding) for arg in s])
 return s

def s3_unicode ( s , encoding = 'utf-8' ) : if ( type ( s ) is unicode ) : return s try : if ( not isinstance ( s , basestring ) ) : if hasattr ( s , '__unicode__' ) : s = unicode ( s ) else : try : s = unicode ( str ( s ) , encoding , 'strict' ) except UnicodeEncodeError : if ( not isinstance ( s , Exception ) ) : raise s = ' ' . join ( [ s3_unicode ( arg , encoding ) for arg in s ] ) else : s = s . decode ( encoding ) except UnicodeDecodeError : if ( not isinstance ( s , Exception ) ) : raise s = ' ' . join ( [ s3_unicode ( arg , encoding ) for arg in s ] ) return s
convert an object into an unicode instance .