code: def to_utf8(string):
      
      if isinstance(string, six.text_type):
          return string.encode('utf8')
      if isinstance(string, six.binary_type):
          return string
      return str(string)
docs: Encode a string as a UTF8 bytestring.  This function could be passed a
      bytestring or unicode string so must distinguish between the two.