(url, no_proxy)
return False
Returns whether we should bypass proxies or not.

    :rtype: bool
Returns whether we should bypass proxies or not.
Returns whether we should bypass proxies or not .
def should_bypass_proxies(url, no_proxy):
    """
    Returns whether we should bypass proxies or not.

    :rtype: bool
    """
    # Prioritize lowercase environment variables over uppercase
    # to keep a consistent behaviour with other http projects (curl, wget).
    get_proxy = lambda k: os.environ.get(k) or os.environ.get(k.upper())

    # First check whether no_proxy is defined. If it is, check that the URL
    # we're getting isn't in the no_proxy list.
    no_proxy_arg = no_proxy
    if no_proxy is None:
        no_proxy = get_proxy('no_proxy')
    parsed = urlparse(url)

    if parsed.hostname is None:
        # URLs don't always have hostnames, e.g. file:/// urls.
        return True

    if no_proxy:
        # We need to check whether we match here. We need to see if we match
        # the end of the hostname, both with and without the port.
        no_proxy = (
            host for host in no_proxy.replace(' ', '').split(',') if host
        )

        if is_ipv4_address(parsed.hostname):
            for proxy_ip in no_proxy:
                if is_valid_cidr(proxy_ip):
                    if address_in_network(parsed.hostname, proxy_ip):
                        return True
                elif parsed.hostname == proxy_ip:
                    # If no_proxy ip was defined in plain IP notation instead of cidr notation &
                    # matches the IP of the index
                    return True
        else:
            host_with_port = parsed.hostname
            if parsed.port:
                host_with_port += ':{}'.format(parsed.port)

            for host in no_proxy:
                if parsed.hostname.endswith(host) or host_with_port.endswith(host):
                    # The URL does match something in no_proxy, so we don't want
                    # to apply the proxies on this URL.
                    return True

    with set_environ('no_proxy', no_proxy_arg):
        # parsed.hostname can be `None` in cases such as a file URI.
        try:
            bypass = proxy_bypass(parsed.hostname)
        except (TypeError, socket.gaierror):
            bypass = False

    if bypass:
        return True

    return False
def should_bypass_proxies ( url , no_proxy ) : # Prioritize lowercase environment variables over uppercase # to keep a consistent behaviour with other http projects (curl, wget). get_proxy = lambda k : os . environ . get ( k ) or os . environ . get ( k . upper ( ) ) # First check whether no_proxy is defined. If it is, check that the URL # we're getting isn't in the no_proxy list. no_proxy_arg = no_proxy if no_proxy is None : no_proxy = get_proxy ( 'no_proxy' ) parsed = urlparse ( url ) if parsed . hostname is None : # URLs don't always have hostnames, e.g. file:/// urls. return True if no_proxy : # We need to check whether we match here. We need to see if we match # the end of the hostname, both with and without the port. no_proxy = ( host for host in no_proxy . replace ( ' ' , '' ) . split ( ',' ) if host ) if is_ipv4_address ( parsed . hostname ) : for proxy_ip in no_proxy : if is_valid_cidr ( proxy_ip ) : if address_in_network ( parsed . hostname , proxy_ip ) : return True elif parsed . hostname == proxy_ip : # If no_proxy ip was defined in plain IP notation instead of cidr notation & # matches the IP of the index return True else : host_with_port = parsed . hostname if parsed . port : host_with_port += ':{}' . format ( parsed . port ) for host in no_proxy : if parsed . hostname . endswith ( host ) or host_with_port . endswith ( host ) : # The URL does match something in no_proxy, so we don't want # to apply the proxies on this URL. return True with set_environ ( 'no_proxy' , no_proxy_arg ) : # parsed.hostname can be `None` in cases such as a file URI. try : bypass = proxy_bypass ( parsed . hostname ) except ( TypeError , socket . gaierror ) : bypass = False if bypass : return True return False