code: def cast_bytes(s, encoding='utf8', errors='strict'):
      
      if isinstance(s, bytes):
          return s
      elif isinstance(s, str):
          return s.encode(encoding, errors)
      else:
          raise TypeError("Expected unicode or bytes, got %r" % s)
docs: cast str or bytes to bytes