def select_proxy(scheme, host, port, proxies):
    """Select a proxy for the url, if applicable.

    :param scheme, host, port: The url being for the request
    :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs
    """
    proxies = proxies or {}
    if host is None:
        return proxies.get(scheme, proxies.get('all'))
    proxy_keys = [scheme + '://' + host, scheme, 'all://' + host, 'all']
    proxy = None
    for proxy_key in proxy_keys:
        if proxy_key in proxies:
            proxy = proxies[proxy_key]
            break
    return proxy
