<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_host(environ, trusted_hosts=None):
 """Return the host for the given WSGI environment. This first checks the ``Host`` header. If it's not present, then ``SERVER_NAME`` and ``SERVER_PORT`` are used. The host will only contain the port if it is different than the standard port for the protocol. Optionally, verify that the host is trusted using :func:`host_is_trusted` and raise a :exc:`~werkzeug.exceptions.SecurityError` if it is not. :param environ: The WSGI environment to get the host from. :param trusted_hosts: A list of trusted hosts. :return: Host, with port if necessary. :raise ~werkzeug.exceptions.SecurityError: If the host is not trusted. """

    if "HTTP_HOST" in environ:
        rv = environ["HTTP_HOST"]
        if environ["wsgi.url_scheme"] == "http" and rv.endswith(":80"):
            rv = rv[:-3]
        elif environ["wsgi.url_scheme"] == "https" and rv.endswith(":443"):
            rv = rv[:-4]
    else:
        rv = environ["SERVER_NAME"]
        if (environ["wsgi.url_scheme"], environ["SERVER_PORT"]) not in (
            ("https", "443"),
            ("http", "80"),
        ):
            rv += ":" + environ["SERVER_PORT"]
    if trusted_hosts is not None:
        if not host_is_trusted(rv, trusted_hosts):
            from .exceptions import SecurityError

            raise SecurityError('Host "%s" is not trusted' % rv)
    return rv