code: def text(string, encoding='utf8'):
      
      if isinstance(string, six.text_type):
          return string
      elif isinstance(string, six.binary_type):
          return string.decode(encoding)
      else:
          return six.text_type(string)
docs: Make sure string is unicode type, decode with given encoding if it's not.
  
      If parameter is a object, object.__str__ will been called