def unicode_string(string):
 if isinstance(string, six.text_type):
  return string
 try:
  return string.decode('utf8')
 except UnicodeDecodeError:
  return (('[BASE64-DATA]' + base64.b64encode(string)) + '[/BASE64-DATA]')

def unicode_string ( string ) : if isinstance ( string , six . text_type ) : return string try : return string . decode ( 'utf8' ) except UnicodeDecodeError : return ( ( '[BASE64-DATA]' + base64 . b64encode ( string ) ) + '[/BASE64-DATA]' )
make sure string is unicode .