'Construct the URL defined by request.application_url, replacing any
of the default scheme, host, or port portions with user-supplied
variants.
If ``scheme`` is passed as ``https``, and the ``port`` is *not*
passed, the ``port`` value is assumed to ``443``.  Likewise, if
``scheme`` is passed as ``http`` and ``port`` is not passed, the
``port`` value is assumed to be ``80``.'

def _partial_application_url(self, scheme=None, host=None, port=None):

    e = self.environ
    if (scheme is None):
        scheme = e['wsgi.url_scheme']
    else:
        if (scheme == 'https'):
            if (port is None):
                port = '443'
        if (scheme == 'http'):
            if (port is None):
                port = '80'
    if (host is None):
        host = e.get('HTTP_HOST')
        if (host is None):
            host = e['SERVER_NAME']
    if (port is None):
        if (':' in host):
            (host, port) = host.split(':', 1)
        else:
            port = e['SERVER_PORT']
    else:
        port = str(port)
        if (':' in host):
            (host, _) = host.split(':', 1)
    if (scheme == 'https'):
        if (port == '443'):
            port = None
    elif (scheme == 'http'):
        if (port == '80'):
            port = None
    url = ((scheme + '://') + host)
    if port:
        url += (':%s' % port)
    url_encoding = getattr(self, 'url_encoding', 'utf-8')
    bscript_name = bytes_(self.script_name, url_encoding)
    return (url + url_quote(bscript_name, PATH_SAFE))
