def collect_pac_urls(from_os_settings=True, from_dns=True, **kwargs): """ Get all the URLs that potentially yield a PAC file. :param bool from_os_settings: Look for a PAC URL from the OS settings. If a value is found and is a URL, it comes first in the returned list. Doesn't do anything on non-Windows or non-macOS/OSX platforms. :param bool from_dns: Assemble a list of PAC URL candidates using the WPAD protocol. :return: A list of URLs that should be tried in order. :rtype: list[str] """ # Deprecated in 0.8.2 from_registry = kwargs.get('from_registry') if from_registry is not None: import warnings warnings.warn('from_registry is deprecated, use from_os_settings instead.') from_os_settings = from_registry pac_urls = [] if from_os_settings: if ON_WINDOWS: url_or_path = autoconfig_url_from_registry() elif ON_DARWIN: url_or_path = autoconfig_url_from_preferences() else: url_or_path = None if url_or_path and (url_or_path.lower().startswith('http://') or url_or_path.lower().startswith('https://')): pac_urls.append(url_or_path) if from_dns: pac_urls.extend(proxy_urls_from_dns()) return pac_urls
def collect_pac_urls(from_os_settings=True, from_dns=True, **kwargs): """ Get all the URLs that potentially yield a PAC file. :param bool from_os_settings: Look for a PAC URL from the OS settings. If a value is found and is a URL, it comes first in the returned list. Doesn't do anything on non-Windows or non-macOS/OSX platforms. :param bool from_dns: Assemble a list of PAC URL candidates using the WPAD protocol. :return: A list of URLs that should be tried in order. :rtype: list[str] """ # Deprecated in 0.8.2 from_registry = kwargs.get('from_registry') if from_registry is not None: import warnings warnings.warn( 'from_registry is deprecated, use from_os_settings instead.') from_os_settings = from_registry pac_urls = [] if from_os_settings: if ON_WINDOWS: url_or_path = autoconfig_url_from_registry() elif ON_DARWIN: url_or_path = autoconfig_url_from_preferences() else: url_or_path = None if url_or_path and (url_or_path.lower().startswith('http://') or url_or_path.lower().startswith('https://')): pac_urls.append(url_or_path) if from_dns: pac_urls.extend(proxy_urls_from_dns()) return pac_urls
def test_this_host(): with patch("socket.getfqdn", return_value="foo.example.local"): search_urls = proxy_urls_from_dns() assert len(search_urls) == 2 for url in search_urls: assert url.startswith("http://wpad.") assert url.endswith("/wpad.dat")
def test_this_host(): with patch('socket.getfqdn', return_value='foo.example.local'): search_urls = proxy_urls_from_dns() assert len(search_urls) == 2 for url in search_urls: assert url.startswith('http://wpad.') assert url.endswith('/wpad.dat')
def collect_pac_urls(from_registry=True, from_dns=True): """ Get all the URLs that potentially yield a PAC file. :param bool from_registry: Look for a PAC URL from the Windows Registry. If a value is found and is a URL, it comes first in the returned list. Doesn't do anything on non-Windows platforms. :param bool from_dns: Assemble a list of PAC URL candidates using the WPAD protocol. :return: A list of URLs that should be tried in order. :rtype: list[str] """ pac_urls = [] if from_registry and ON_WINDOWS: url_or_path = autoconfig_url_from_registry() if url_or_path and (url_or_path.lower().startswith('http://') or url_or_path.lower().startswith('https://')): pac_urls.append(url_or_path) if from_dns: pac_urls.extend(proxy_urls_from_dns()) return pac_urls
def test_host_fqdn(host_fqdn, expected_wpad, description): print(description) assert proxy_urls_from_dns(host_fqdn) == expected_wpad
def test_bad_host(bad_host): assert proxy_urls_from_dns(bad_host) == []
def test_bad_host(bad_host): assert proxy_urls_from_dns(bad_host) == []
def test_host_fqdn(host_fqdn, expected_wpad, description): print(description) assert proxy_urls_from_dns(host_fqdn) == expected_wpad