import six


def to_bytes(str_bytes_or_unicode):
  """Converts any type of (str, bytes, or unicode) to bytes."""
  if isinstance(str_bytes_or_unicode, six.binary_type):  # Remain binary type.
    return str_bytes_or_unicode
  elif isinstance(str_bytes_or_unicode, six.text_type):  # Text to binary.
    return str_bytes_or_unicode.encode("utf-8")
  raise ValueError("Not supported: %s" % str_bytes_or_unicode)