示例#1
0
    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
示例#2
0
    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
示例#3
0
 def test_empty(self):
     assert parse_pac_value('') == []
示例#4
0
 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']
示例#5
0
 def test_multiple(self):
     assert parse_pac_value('PROXY foo:8080; DIRECT') == ['http://foo:8080', 'DIRECT']
示例#6
0
 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
示例#7
0
 def test_multiple(self):
     assert parse_pac_value("PROXY foo:8080; DIRECT") == [
         "http://foo:8080", "DIRECT"
     ]
示例#8
0
 def test_empty(self):
     assert parse_pac_value('') == []
示例#9
0
 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']
示例#10
0
 def test_multiple(self):
     assert parse_pac_value('PROXY foo:8080; DIRECT') == ['http://foo:8080', 'DIRECT']
示例#11
0
 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