code: def ensure_bytes(str_or_bytes, encoding='utf-8', errors='strict'):
      
      if isinstance(str_or_bytes, six.text_type):
          return str_or_bytes.encode(encoding, errors)
      return str_or_bytes
docs: Ensures an input is bytes, encoding if it is a string.