code: 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]'
docs: Make sure string is unicode, try to default with utf8, or base64 if failed.
  
      can been decode by `decode_unicode_string`