def ensure_str(s, encoding='utf-8', errors='strict'):
    """Coerce *s* to `str`.
    For Python 3:
      - `str` -> `str`
      - `bytes or bytearray` -> decoded to `str`
    """
    if not isinstance(s, (str, bytes, bytearray)):
        raise TypeError("not expecting type '%s'" % type(s))
    if isinstance(s, (bytes, bytearray)):
        s = s.decode(encoding, errors)
    return s