Beispiel #1
0
    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)
Beispiel #2
0
    def proxyAuthentication(self, proxyHost, auth, parent=None):
        '''
        @param: proxyHost QString
        @param: auth QAuthenticator
        '''
        proxy = QNetworkProxy.applicationProxy()
        if proxy.user() and proxy.password():
            auth.setUser(proxy.user())
            auth.setPassword(proxy.password())
            return

        dialog = QDialog(parent)
        dialog.setWindowTitle(_('Proxy authorization required'))

        formLa = QFormLayout(dialog)

        label = QLabel(dialog)
        userLab = QLabel(dialog)
        passLab = QLabel(dialog)
        userLab.setText(_('Username: '******'Password: '******'A username and password are being requested by proxy %s. ') %
            proxyHost)
        formLa.addRow(label)
        formLa.addRow(userLab, user)
        formLa.addRow(passLab, pass_)
        formLa.addWidget(box)

        if dialog.exec_() != QDialog.Accepted:
            auth = QAuthenticator
            del dialog
            return auth  # TODO: C++ return, but should assign auth, try return auth in python, to be check

        auth.setUser(user.text())
        auth.setPassword(pass_.text())

        del dialog
Beispiel #3
0
    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)
Beispiel #4
0
    def __init__(self, *args):
        QWebView.__init__(self, *args)
        self.gui = None
        self.tags = ''
        self.create_browser = None

        self._page = NPWebPage()
        self.setPage(self._page)
        self.cookie_jar = QNetworkCookieJar()
        self.page().networkAccessManager().setCookieJar(self.cookie_jar)

        http_proxy = get_proxies().get('http', None)
        if http_proxy:
            proxy_parts = urlparse(http_proxy)
            proxy = QNetworkProxy()
            proxy.setType(QNetworkProxy.HttpProxy)
            if proxy_parts.username:
                proxy.setUser(proxy_parts.username)
            if proxy_parts.password:
                proxy.setPassword(proxy_parts.password)
            if proxy_parts.hostname:
                proxy.setHostName(proxy_parts.hostname)
            if proxy_parts.port:
                proxy.setPort(proxy_parts.port)
            self.page().networkAccessManager().setProxy(proxy)

        self.page().setForwardUnsupportedContent(True)
        self.page().unsupportedContent.connect(self.start_download)
        self.page().downloadRequested.connect(self.start_download)
        self.page().networkAccessManager().sslErrors.connect(self.ignore_ssl_errors)
Beispiel #5
0
    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()