<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _build_base_url(self, host, port):
 """Return the API base URL string based on ``host`` and ``port``. It returns a valid URL when ``host`` isn't. The endling slash is always removed so it always need to be added by the consumer. """

        parsed = urlparse(host)
        if not parsed.scheme:
            parsed = parsed._replace(scheme="http")
            parsed = parsed._replace(path="")
            netloc, parts = host, host.partition(":")
            if parts[1] == "" and port is not None:
                netloc = "{}:{}".format(parts[0], port)
            parsed = parsed._replace(netloc=netloc)
        parsed = parsed._replace(path=parsed.path.rstrip("/"))
        return parsed.geturl()