def ensure_str(s, encoding='<STR_LIT:utf-8>', errors='<STR_LIT:strict>'):
if not isinstance(s, (text_type, binary_type)):<EOL><INDENT>raise TypeError("<STR_LIT>" % type(s))<EOL><DEDENT>if PY2 and isinstance(s, text_type):<EOL><INDENT>s = s.encode(encoding, errors)<EOL><DEDENT>elif PY3 and isinstance(s, binary_type):<EOL><INDENT>s = s.decode(encoding, errors)<EOL><DEDENT>return s<EOL>
Coerce *s* to `str`.

    For Python 2:
      - `unicode` -> encoded to `str`
      - `str` -> `str`

    For Python 3:
      - `str` -> `str`
      - `bytes` -> decoded to `str`