Example #1
0
    def set_proxy(self, type_, host='localhost', port=8888, user='',
            password=''):
        """Set up proxy for FURTHER connections.

        :param type_: proxy type to use: \
            none/default/socks5/https/http.
        :param host: proxy server ip or host name.
        :param port: proxy port.
        """
        _types = {
            'default': QNetworkProxy.DefaultProxy,
            'none': QNetworkProxy.NoProxy,
            'socks5': QNetworkProxy.Socks5Proxy,
            'https': QNetworkProxy.HttpProxy,
            'http': QNetworkProxy.HttpCachingProxy
        }

        if type_ is None:
            type_ = 'none'
        type_ = type_.lower()
        if type_ in ['none', 'default']:
            self.manager.setProxy(QNetworkProxy(_types[type_]))
            return
        elif type_ in _types:
            proxy = QNetworkProxy(_types[type_], hostName=host, port=port,
                user=user, password=password)
            self.manager.setProxy(proxy)
        else:
            raise ValueError('Unsupported proxy type:' + type_ \
            + '\nsupported types are: none/socks5/http/https/default')
Example #2
0
 def updateProxy(self):
     config = self.__parentWindow.config()
     if config.getProxyHost():
         proxy = QNetworkProxy(QNetworkProxy.HttpProxy,
                               config.getProxyHost(), config.getProxyPort())
     else:
         proxy = QNetworkProxy()
     self.__webNote.page().networkAccessManager().setProxy(proxy)