def get_proxies(self, url): """ Get the proxies that are applicable to a given URL, according to the PAC file. :param str url: The URL for which to find appropriate proxies. :return: All the proxies that apply to the given URL. Can be empty, which means to abort the request. :rtype: list[str] """ hostname = urlparse(url).hostname if hostname is None: # URL has no hostname, and PAC functions don't expect to receive nulls. hostname = "" value_from_js_func = self.pac.find_proxy_for_url(url, hostname) if value_from_js_func in self._cache: return self._cache[value_from_js_func] config_values = parse_pac_value(self.pac.find_proxy_for_url(url, hostname), self.socks_scheme) if self._proxy_auth: config_values = [add_proxy_auth(value, self._proxy_auth) for value in config_values] self._cache[value_from_js_func] = config_values return config_values
def get_proxies(self, url): """ Get the proxies that are applicable to a given URL, according to the PAC file. :param str url: The URL for which to find appropriate proxies. :return: All the proxies that apply to the given URL. Can be empty, which means to abort the request. :rtype: list[str] """ hostname = urlparse(url).hostname if hostname is None: # URL has no hostname, and PAC functions don't expect to receive nulls. hostname = "" value_from_js_func = self.pac.find_proxy_for_url(url, hostname) if value_from_js_func in self._cache: return self._cache[value_from_js_func] config_values = parse_pac_value( self.pac.find_proxy_for_url(url, hostname), self.socks_scheme) if self._proxy_auth: config_values = [ add_proxy_auth(value, self._proxy_auth) for value in config_values ] self._cache[value_from_js_func] = config_values return config_values
def test_empty(self): assert parse_pac_value('') == []
def test_skip_invalid(self, bad_value): with warnings.catch_warnings(): warnings.simplefilter("ignore") retval = 'PROXY foo:8080; {}; DIRECT'.format(bad_value) assert parse_pac_value(retval) == ['http://foo:8080', 'DIRECT']
def test_multiple(self): assert parse_pac_value('PROXY foo:8080; DIRECT') == ['http://foo:8080', 'DIRECT']
def test_parse_single_value(self, pac_value, expected_result): assert parse_pac_value(pac_value) == [expected_result] assert proxy_url(pac_value) == expected_result
def test_multiple(self): assert parse_pac_value("PROXY foo:8080; DIRECT") == [ "http://foo:8080", "DIRECT" ]