def __init__(self, log): QNetworkProxyFactory.__init__(self) proxies = get_proxies() self.proxies = {} for scheme, proxy_string in proxies.iteritems(): scheme = scheme.lower() info = get_proxy_info(scheme, proxy_string) if info is None: continue hn, port = info['hostname'], info['port'] if not hn or not port: continue log.debug('JSBrowser using proxy:', pprint.pformat(info)) pt = { 'socks5': QNetworkProxy.Socks5Proxy }.get(scheme, QNetworkProxy.HttpProxy) proxy = QNetworkProxy(pt, hn, port) un, pw = info['username'], info['password'] if un: proxy.setUser(un) if pw: proxy.setPassword(pw) self.proxies[scheme] = proxy self.default_proxy = QNetworkProxy(QNetworkProxy.DefaultProxy)
def loadSettings(self): settings = Settings() settings.beginGroup('Language') # TODO: #langs = settings.value('acceptLanguage', AcceptLanguage.defaultLanguage(), type=[]) settings.endGroup() # TODO: #gVar.app.webProfile().setHttpAcceptLanguage(AcceptLanguage.generateHeader(langs)) proxy = QNetworkProxy() settings.beginGroup('Web-Proxy') proxyType = settings.value('ProxyType', 2) proxy.setHostName(settings.value('HostName', '')) proxy.setPort(settings.value('Port', 8080)) proxy.setUser(settings.value('Username', '')) proxy.setPassword(settings.value('Password', '')) settings.endGroup() if proxyType == 0: proxy.setType(QNetworkProxy.NoProxy) elif proxyType == 3: proxy.setType(QNetworkProxy.HttpProxy) elif proxyType == 4: proxy.setType(QNetworkProxy.Socks5Proxy) if proxyType == 2: QNetworkProxy.setApplicationProxy(QNetworkProxy()) QNetworkProxyFactory.setUseSystemConfiguration(True) else: QNetworkProxy.setApplicationProxy(proxy) QNetworkProxyFactory.setUseSystemConfiguration(False) self._urlInterceptor.loadSettings()
def __init__(self, log): QNetworkProxyFactory.__init__(self) proxies = get_proxies() self.proxies = {} for scheme, proxy_string in proxies.iteritems(): scheme = scheme.lower() info = get_proxy_info(scheme, proxy_string) if info is None: continue hn, port = info['hostname'], info['port'] if not hn or not port: continue log.debug('JSBrowser using proxy:', pprint.pformat(info)) pt = {'socks5':QNetworkProxy.Socks5Proxy}.get(scheme, QNetworkProxy.HttpProxy) proxy = QNetworkProxy(pt, hn, port) un, pw = info['username'], info['password'] if un: proxy.setUser(un) if pw: proxy.setPassword(pw) self.proxies[scheme] = proxy self.default_proxy = QNetworkProxy(QNetworkProxy.DefaultProxy)