code: def ensure_text(str_or_bytes, encoding='utf-8'):
      
      if not isinstance(str_or_bytes, six.text_type):
          return str_or_bytes.decode(encoding)
      return str_or_bytes
docs: Ensures an input is a string, decoding if it is bytes.