code: def ensure_str(s, encoding="utf-8", errors="strict"):
      """Coerce *s* to `str`.
  
      For Python 2:
        - `unicode` -> encoded to `str`
        - `str` -> `str`
  
      For Python 3:
        - `str` -> `str`
        - `bytes` -> decoded to `str`
      """
      # Optimization: Fast return for the common case.
      if type(s) is str:
          return s
      if PY2 and isinstance(s, text_type):
          return s.encode(encoding, errors)
      elif PY3 and isinstance(s, binary_type):
          return s.decode(encoding, errors)
      elif not isinstance(s, (text_type, binary_type)):
          raise TypeError("not expecting type '%s'" % type(s))
      return s
  
imports: from __future__ import absolute_import
  import functools
  import itertools
  import operator
  import sys
  import types
label_desc: Use image node_id 12 for calling a global function with example usage: ensure_str(s, encoding, errors) and returns: s, s, s, s