Пример #1
0
    def queryProxy(self, query):
        """Get the QNetworkProxies for a query.

        Args:
            query: The QNetworkProxyQuery to get a proxy for.

        Return:
            A list of QNetworkProxy objects in order of preference.
        """
        proxy = config.val.content.proxy
        if proxy is configtypes.SYSTEM_PROXY:
            # On Linux, use "export http_proxy=socks5://host:port" to manually
            # set system proxy.
            # ref. http://doc.qt.io/qt-5/qnetworkproxyfactory.html#systemProxyForQuery
            proxies = QNetworkProxyFactory.systemProxyForQuery(query)
        elif isinstance(proxy, pac.PACFetcher):
            if objects.backend == usertypes.Backend.QtWebEngine:
                # Looks like query.url() is always invalid on QtWebEngine...
                proxies = [urlutils.proxy_from_url(QUrl('direct://'))]
            else:
                proxies = proxy.resolve(query)
        else:
            proxies = [proxy]
        for p in proxies:
            if p.type() != QNetworkProxy.NoProxy:
                capabilities = p.capabilities()
                lookup_cap = QNetworkProxy.HostNameLookupCapability
                if config.val.content.proxy_dns_requests:
                    capabilities |= lookup_cap  # type: ignore
                else:
                    capabilities &= ~lookup_cap  # type: ignore
                p.setCapabilities(capabilities)
        return proxies
Пример #2
0
    def queryProxy(self, query):
        """Get the QNetworkProxies for a query.

        Args:
            query: The QNetworkProxyQuery to get a proxy for.

        Return:
            A list of QNetworkProxy objects in order of preference.
        """
        proxy = config.val.content.proxy
        if proxy is configtypes.SYSTEM_PROXY:
            # On Linux, use "export http_proxy=socks5://host:port" to manually
            # set system proxy.
            # ref. https://doc.qt.io/qt-5/qnetworkproxyfactory.html#systemProxyForQuery
            proxies = QNetworkProxyFactory.systemProxyForQuery(query)
        elif isinstance(proxy, pac.PACFetcher):
            if objects.backend == usertypes.Backend.QtWebEngine:
                # Looks like query.url() is always invalid on QtWebEngine...
                proxy = urlutils.proxy_from_url(QUrl('direct://'))
                assert not isinstance(proxy, pac.PACFetcher)
                proxies = [proxy]
            elif objects.backend == usertypes.Backend.QtWebKit:
                proxies = proxy.resolve(query)
            else:
                raise utils.Unreachable(objects.backend)
        else:
            proxies = [proxy]
        for proxy in proxies:
            self._set_capabilities(proxy)
        return proxies
Пример #3
0
    def queryProxy(self, query):
        """Get the QNetworkProxies for a query.

        Args:
            query: The QNetworkProxyQuery to get a proxy for.

        Return:
            A list of QNetworkProxy objects in order of preference.
        """
        proxy = config.val.content.proxy
        if proxy is configtypes.SYSTEM_PROXY:
            # On Linux, use "export http_proxy=socks5://host:port" to manually
            # set system proxy.
            # ref. http://doc.qt.io/qt-5/qnetworkproxyfactory.html#systemProxyForQuery
            proxies = QNetworkProxyFactory.systemProxyForQuery(query)
        elif isinstance(proxy, pac.PACFetcher):
            if objects.backend == usertypes.Backend.QtWebEngine:
                # Looks like query.url() is always invalid on QtWebEngine...
                proxies = [urlutils.proxy_from_url(QUrl('direct://'))]
            else:
                proxies = proxy.resolve(query)
        else:
            proxies = [proxy]
        for p in proxies:
            if p.type() != QNetworkProxy.NoProxy:
                capabilities = p.capabilities()
                if config.val.content.proxy_dns_requests:
                    capabilities |= QNetworkProxy.HostNameLookupCapability
                else:
                    capabilities &= ~QNetworkProxy.HostNameLookupCapability
                p.setCapabilities(capabilities)
        return proxies
Пример #4
0
    def transform(self, value):
        from qutebrowser.utils import urlutils
        if not value:
            return None
        elif value == 'system':
            return SYSTEM_PROXY

        if value == 'none':
            url = QUrl('direct://')
        else:
            url = QUrl(value)
        return urlutils.proxy_from_url(url)
Пример #5
0
    def transform(self, value):
        from qutebrowser.utils import urlutils
        if not value:
            return None
        elif value == 'system':
            return SYSTEM_PROXY

        if value == 'none':
            url = QUrl('direct://')
        else:
            url = QUrl(value)
        return urlutils.proxy_from_url(url)
Пример #6
0
    def to_py(self, value):
        self._basic_py_validation(value, str)
        if not value:
            return None

        try:
            if value == 'system':
                return SYSTEM_PROXY

            if value == 'none':
                url = QUrl('direct://')
            else:
                # If we add a special value to valid_values, we need to handle
                # it here!
                assert value not in self.valid_values, value
                url = QUrl(value)
            return urlutils.proxy_from_url(url)
        except (urlutils.InvalidUrlError, urlutils.InvalidProxyTypeError) as e:
            raise configexc.ValidationError(value, e)
Пример #7
0
    def to_py(self, value):
        self._basic_py_validation(value, str)
        if not value:
            return None

        try:
            if value == 'system':
                return SYSTEM_PROXY

            if value == 'none':
                url = QUrl('direct://')
            else:
                # If we add a special value to valid_values, we need to handle
                # it here!
                assert value not in self.valid_values, value
                url = QUrl(value)
            return urlutils.proxy_from_url(url)
        except (urlutils.InvalidUrlError, urlutils.InvalidProxyTypeError) as e:
            raise configexc.ValidationError(value, e)
Пример #8
0
 def test_invalid(self, url, exception):
     with pytest.raises(exception):
         urlutils.proxy_from_url(QUrl(url))
Пример #9
0
 def test_proxy_from_url_pac(self, scheme, qapp):
     fetcher = urlutils.proxy_from_url(QUrl('{}://foo'.format(scheme)))
     assert isinstance(fetcher, pac.PACFetcher)
Пример #10
0
 def test_proxy_from_url_valid(self, url, expected):
     assert urlutils.proxy_from_url(QUrl(url)) == expected
Пример #11
0
 def test_proxy_from_url_pac(self, scheme):
     fetcher = urlutils.proxy_from_url(QUrl('{}://foo'.format(scheme)))
     assert fetcher is pac.PACFetcher
Пример #12
0
 def test_invalid(self, url, exception):
     with pytest.raises(exception):
         urlutils.proxy_from_url(QUrl(url))
Пример #13
0
 def test_proxy_from_url_pac(self, scheme, qapp):
     fetcher = urlutils.proxy_from_url(QUrl('{}://foo'.format(scheme)))
     assert isinstance(fetcher, pac.PACFetcher)
Пример #14
0
 def test_proxy_from_url_valid(self, url, expected):
     assert urlutils.proxy_from_url(QUrl(url)) == expected