def METHOD_NAME(input_url: str, scheme: typing.Union[str, typing.Tuple[str], None]) -> str:
	"""Parse URL, remove leading and trailing whitespaces and a trailing slash.
	If `scheme` is specified, check if it matches the `input_url` scheme.
	Args:
		input_url (str): URL to be parsed and validated.
		scheme (str | tuple[str] | None): Requested URL schema.
	Raises:
		ValueError: If `scheme` is specified and is invalid.
	Returns:
		str: Parsed and validated URL.
	"""
	# Remove leading and trailing whitespaces before parsing
	url = urllib.parse.urlparse(input_url.strip())
	if url.path.endswith("/"):
		url = url._replace(path=url.path[:-1])
	if scheme is None:  # Scheme doesn't get checked
		return url.geturl()
	elif isinstance(scheme, tuple):  # Supports tuple
		if url.scheme in scheme:
			return url.geturl()
	elif scheme == url.scheme:
		return url.geturl()
	else:
		if url.scheme:
			raise ValueError("'{}' has an invalid scheme: '{}'".format(url.geturl(), url.scheme))
		elif not url.scheme:
			raise ValueError("'{}' does not have a scheme".format(url.geturl()))
		else:
			raise ValueError("'{}' has an invalid scheme".format(url.geturl()))
	return url.geturl()