def get_proxy(): """ Get a proxy according to QSettings @return: proxy @rtype: QNetworkProxy """ s = QSettings() if s.value('proxy/proxyEnabled', '') == 'true': proxy_type = s.value('proxy/proxyType', '') proxy_host = s.value('proxy/proxyHost', '') proxy_port = s.value('proxy/proxyPort', '') proxy_user = s.value('proxy/proxyUser', '') proxy_password = s.value('proxy/proxyPassword', '') proxy = QNetworkProxy() if proxy_type == 'DefaultProxy': proxy.setType(QNetworkProxy.DefaultProxy) elif proxy_type == 'Socks5Proxy': proxy.setType(QNetworkProxy.Socks5Proxy) elif proxy_type == 'HttpProxy': proxy.setType(QNetworkProxy.HttpProxy) elif proxy_type == 'HttpCachingProxy': proxy.setType(QNetworkProxy.HttpCachingProxy) elif proxy_type == 'FtpCachingProxy': proxy.setType(QNetworkProxy.FtpCachingProxy) proxy.setHostName(proxy_host) proxy.setPort(int(proxy_port)) proxy.setUser(proxy_user) proxy.setPassword(proxy_password) return proxy else: return None
def get_proxy(): """Adaption by source of Plugin Installer - Version 1.0.10""" settings = QSettings() settings.beginGroup("proxy") if settings.value("/proxyEnabled", False, type=bool): proxy = QNetworkProxy() proxyType = settings.value("/proxyType", 0, type=int) if proxyType in ["1", "Socks5Proxy"]: proxy.setType(QNetworkProxy.Socks5Proxy) elif proxyType in ["2", "NoProxy"]: proxy.setType(QNetworkProxy.NoProxy) elif proxyType in ["3", "HttpProxy"]: proxy.setType(QNetworkProxy.HttpProxy) elif proxyType in ["4", "HttpCachingProxy"] and QT_VERSION >= 0X040400: proxy.setType(QNetworkProxy.HttpCachingProxy) elif proxyType in ["5", "FtpCachingProxy"] and QT_VERSION >= 0X040400: proxy.setType(QNetworkProxy.FtpCachingProxy) else: proxy.setType(QNetworkProxy.DefaultProxy) proxy.setHostName(settings.value("/proxyHost")) proxy.setPort(settings.value("/proxyPort", type=int)) proxy.setUser(settings.value("/proxyUser")) proxy.setPassword(settings.value("/proxyPassword")) settings.endGroup() return proxy
def configureProxy(self, host, port, user=None, password=None): """Add a proxy configuration for the Network Requests. :param host: the proxy host :param port: the proxy port :param user: if the proxy has authentication this param sets the user to be used. It should be None if it's not required to access with a user :param password: if the proxy has authentication this param sets the password to be used. It should be None if it's not required to access with a password """ proxy = QNetworkProxy() proxy.setType(QNetworkProxy.HttpProxy) proxy.setHostName(host) proxy.setPort(port) if user is not None: proxy.setUser(user) if password is not None: proxy.setPassword(password) self._proxyAuth = (user, password) self.setProxy(proxy)
def setUp(self): if len(argv) == 2: site = argv[1] else: site = None options = extract_options(site) if options['cookie_file'] is not None: options['cookie_file'] = ( expanduser("~/.eilat/cookies/") + options['cookie_file']) # Proxy if options['use_proxy']: proxy = QNetworkProxy() proxy.setType(QNetworkProxy.HttpProxy) proxy.setHostName('localhost') proxy.setPort(3128) QNetworkProxy.setApplicationProxy(proxy) self.mainwin = MainWin(clipboard=CLIPBOARD, options=options, parent=None) if site: self.mainwin.add_tab(site) else: self.mainwin.add_tab() self.mainwin.show()
def set_proxy(self, string_proxy): """Set proxy [http|socks5]://username:password@hostname:port""" urlinfo = urlparse.urlparse(string_proxy) proxy = QNetworkProxy() if urlinfo.scheme == 'socks5' : proxy.setType(1) elif urlinfo.scheme == 'http' : proxy.setType(3) else : proxy.setType(2) self.manager.setProxy(proxy) return self.manager.proxy() proxy.setHostName(urlinfo.hostname) proxy.setPort(urlinfo.port) if urlinfo.username != None : proxy.setUser(urlinfo.username) else : proxy.setUser('') if urlinfo.password != None : proxy.setPassword(urlinfo.password) else : proxy.setPassword('') self.manager.setProxy(proxy) return self.manager.proxy()
def setTempProxy(self, host, port=None, username=None, password=None): proxy = QNetworkProxy() proxy.setType(QNetworkProxy.HttpProxy) if username: proxy.setUser(username) if password: proxy.setPassword(password) if port: proxy.setPort(port) proxy.setHostName(host) self.page().networkAccessManager().setProxy(proxy)
def __set_proxy_slot(self, host, port): proxy = QNetworkProxy() if not host: proxy.setType(QNetworkProxy.NoProxy) else: proxy.setType(QNetworkProxy.HttpProxy) proxy.setHostName(host) proxy.setPort(port) self.__web_view.page().networkAccessManager().setProxy(proxy) self.__set_proxy_condition.acquire() self.__set_proxy_condition.notifyAll() self.__set_proxy_condition.release()
def prox(self,mode,user,password,host,port): proxy = QNetworkProxy() if mode == "DefaultProxy": proxy.setType(QNetworkProxy.DefaultProxy) elif mode == "Socks5Proxy": proxy.setType(QNetworkProxy.Socks5Proxy) proxy.setHostName(host) proxy.setPort(int(port)) proxy.setUser(self.usern) proxy.setPassword(self.passw) QNetworkProxy.setApplicationProxy(proxy) elif mode == "HttpProxy": proxy.setType(QNetworkProxy.HttpProxy) proxy.setHostName(host) proxy.setPort(int(port)) proxy.setUser(self.usern) proxy.setPassword(self.passw) QNetworkProxy.setApplicationProxy(proxy) elif mode == "HttpCachingProxy": proxy.setType(QNetworkProxy.HttpCachingProxy) proxy.setHostName(host) proxy.setPort(int(port)) proxy.setUser(self.usern) proxy.setPassword(self.passw) QNetworkProxy.setApplicationProxy(proxy) elif mode == "FtpCachingProxy": proxy.setType(QNetworkProxy.FtpCachingProxy) proxy.setHostName(host) proxy.setPort(int(port)) proxy.setUser(self.usern) proxy.setPassword(self.passw) QNetworkProxy.setApplicationProxy(proxy)
def applySettings(self): if self.feedView.siteServer.session.user != str(self.ffNickname.text()) or self.feedView.siteServer.session.remoteKey != str(self.ffRemoteKey.text()): self.feedView.siteServer.session.user = str(self.ffNickname.text()) self.feedView.siteServer.session.remoteKey = str(self.ffRemoteKey.text()) self.feedView.goHome() proxy = QNetworkProxy() proxyType = self.proxyType.currentIndex() proxy.setType( (proxyType == 2) and QNetworkProxy.Socks5Proxy or ( (proxyType == 1) and QNetworkProxy.HttpProxy or QNetworkProxy.NoProxy ) ) if proxyType: proxy.setHostName(self.proxyHost.text()) proxy.setPort(self.proxyPort.value()) if self.proxyAuth.checkState() == Qt.Checked: proxy.setUser(self.proxyAuthUser.text()) proxy.setPassword(self.proxyAuthPassword.text()) QNetworkProxy.setApplicationProxy(proxy)
def get_proxy(): """Adaption by source of Plugin Installer - Version 1.0.10 :returns: Get proxy that currently used. :rtype: QNetworkProxy """ settings = QSettings() settings.beginGroup('proxy') enabled = settings.value('/proxyEnabled', False, type=bool) if not enabled: return None proxy = QNetworkProxy() try: proxy_type = settings.value('/proxyType', 0, type=int) except TypeError: # Catch for this: # TypeError: unable to convert a QVariant of type 10 to a # QMetaType of type 2 # TODO: can we do anything to handle this more gracefully? TS settings.setValue('/proxyType', 0) return proxy if proxy_type in ['1', 'Socks5Proxy']: proxy.setType(QNetworkProxy.Socks5Proxy) elif proxy_type in ['2', 'NoProxy']: proxy.setType(QNetworkProxy.NoProxy) elif proxy_type in ['3', 'HttpProxy']: proxy.setType(QNetworkProxy.HttpProxy) elif proxy_type in ['4', 'HttpCachingProxy'] and QT_VERSION >= 0X040400: proxy.setType(QNetworkProxy.HttpCachingProxy) elif proxy_type in ['5', 'FtpCachingProxy'] and QT_VERSION >= 0X040400: proxy.setType(QNetworkProxy.FtpCachingProxy) else: proxy.setType(QNetworkProxy.DefaultProxy) proxy.setHostName(settings.value('/proxyHost')) proxy.setPort(settings.value('/proxyPort', type=int)) user = settings.value('/proxyUser', type=str) password = settings.value('/proxyPassword', type=str) if user is not None: proxy.setUser(user) if password is not None and user is not None: proxy.setPassword(password) settings.endGroup() return proxy
def configure_proxy(cls, hostname, port, user=None, password=None, proxy_type=QNetworkProxy.HttpProxy): """ Configure network proxy layer. @param proxy_type: see QNetworkProxy.ProxyType. Default: HttpProxy. @param hostname: Proxy hostname. @param port: Proxy port. @param username: Proxy username (optional). @param passwrod: Proxy password (optional). """ proxy = QNetworkProxy() proxy.setType(proxy_type) proxy.setHostName(hostname) proxy.setPort(port) if user and password is not None: proxy.setUser(user) proxy.setPassword(password) QNetworkProxy.setApplicationProxy(proxy);
def configure_proxy(cls, hostname, port, user=None, password=None, proxy_type=QNetworkProxy.HttpProxy): """ Configure network proxy layer. @param proxy_type: see QNetworkProxy.ProxyType. Default: HttpProxy. @param hostname: Proxy hostname. @param port: Proxy port. @param username: Proxy username (optional). @param passwrod: Proxy password (optional). """ proxy = QNetworkProxy() proxy.setType(proxy_type) proxy.setHostName(hostname) proxy.setPort(port) if user and password is not None: proxy.setUser(user) proxy.setPassword(password) QNetworkProxy.setApplicationProxy(proxy)
if proxy_socket.error() != QTcpSocket.RemoteHostClosedError: url = proxy_socket.property('url').toUrl() error_string = proxy_socket.errorString() if self.debug: self.log.write('Error for %s %s\n\n' % (url, error_string)) proxy_socket.deleteLater() if __name__ == '__main__': app = QCoreApplication(sys.argv) server = HTTPProxy() manager = QNetworkAccessManager() manager.finished.connect(server.stopServing) manager.finished.connect(app.quit) proxy = QNetworkProxy() proxy.setType(QNetworkProxy.HttpProxy) proxy.setHostName('127.0.0.1') proxy.setPort(server.port()) proxy.setUser(server.username) proxy.setPassword(server.password) manager.setProxy(proxy) reply = manager.get(QNetworkRequest(QUrl('http://aws.amazon.com/'))) sys.exit(app.exec_())
def __init__(self, parent = None): QMainWindow.__init__(self, parent) self.setWindowTitle("FeedLol") self.aboutAction = QAction(QIcon("data/icons/help-about.svg"), "&About FeedLol...", self) self.connect(self.aboutAction, SIGNAL("triggered()"), self.slotAbout) self.reloadAction = QAction(QIcon("data/icons/view-refresh.svg"), "&Reload", self) self.reloadAction.setShortcut(QKeySequence.Refresh) self.homeAction = QAction(QIcon("data/icons/go-home.svg"), "Go &Home", self) self.homeAction.setShortcut("Alt+Home") self.userAction = QAction(QIcon("data/icons/user-identity.svg"), "&Me", self) self.userAction.setShortcut("Ctrl+M") self.logoutAction = QAction(QIcon("data/icons/dialog-close.svg"), "Log&out", self) self.logoutAction.setShortcut(QKeySequence.Close) self.settingsAction = QAction(QIcon("data/icons/configure.svg"), "&Preferences...", self) self.connect(self.settingsAction, SIGNAL("triggered()"), self.slotSettings) self.toolbar = QToolBar("Toolbar", self) self.toolbar.setObjectName("toolbar") self.toolbar.addAction(self.homeAction) self.toolbar.addAction(self.userAction) self.toolbar.addAction(self.reloadAction) self.toolbar.addSeparator() self.toolbar.addAction(self.logoutAction) self.toolbar.addSeparator() self.toolbar.addAction(self.settingsAction) self.toolbar.addAction(self.aboutAction) self.addToolBar(self.toolbar) self.loadStatus = QProgressBar(self) self.loadStatus.setRange(0, 100) self.loadStatus.setMaximumWidth(200) self.loadStatus.setTextVisible(False) self.loadStatus.hide() self.statusBar().addPermanentWidget(self.loadStatus) self.feedView = FeedView(self) self.setCentralWidget(self.feedView) self.connect(self.feedView, SIGNAL("titleChanged(const QString&)"), self.slotSetTitle) self.connect(self.feedView, SIGNAL("statusBarMessage(const QString&)"), self.statusBar(), SLOT("showMessage(const QString&)")) self.connect(self.feedView, SIGNAL("loadStarted()"), self.loadStart) self.connect(self.feedView, SIGNAL("loadFinished(bool)"), self.loadStop) self.connect(self.feedView, SIGNAL("loadProgress(int)"), self.loadProgress) self.connect(self.reloadAction, SIGNAL("triggered()"), self.feedView.reload) self.connect(self.homeAction, SIGNAL("triggered()"), self.feedView.goHome) self.connect(self.userAction, SIGNAL("triggered()"), self.feedView.goToUserPage) self.connect(self.logoutAction, SIGNAL("triggered()"), self.feedView.logout) self.connect(self.feedView.page(), SIGNAL("linkHovered(const QString&, const QString&, const QString&)"), self.linkHovered) self.settingsDialog = SettingsDialog(self.feedView, self) settings = QSettings() if settings.contains("proxy/type"): proxy = QNetworkProxy() proxyType = settings.value("proxy/type").toInt()[0] proxy.setType( (proxyType == 2) and QNetworkProxy.Socks5Proxy or ( (proxyType == 1) and QNetworkProxy.HttpProxy or QNetworkProxy.NoProxy ) ) if proxy.type() != QNetworkProxy.NoProxy: proxy.setHostName(settings.value("proxy/host").toString()) proxy.setPort(settings.value("proxy/port").toInt()[0]) if settings.value("proxy/user").toString(): proxy.setUser(settings.value("proxy/user").toString()) proxy.setPassword(settings.value("proxy/password").toString()) QNetworkProxy.setApplicationProxy(proxy) if settings.contains("mainWindow/geometry"): self.restoreGeometry(settings.value("mainWindow/geometry").toByteArray()) else: self.resize(320,480) if settings.contains("mainWindow/state"): self.restoreState(settings.value("mainWindow/state").toByteArray()) self.feedView.goHome()
def createWidgets(self): """ Create all qt widgets """ self.setWindowTitle(self.tr("Extensive Testing Client - Web Browser")) self.setWindowIcon(QIcon(":/main.png")) self.dockToolbarWebBrowser = QToolBar(self) self.dockToolbarWebBrowser.setToolButtonStyle( Qt.ToolButtonTextBesideIcon) browserLayoutGroup = QVBoxLayout() browserLayoutGroup.addWidget(self.dockToolbarWebBrowser) toolbarBrowserLayoutGroup = QHBoxLayout() self.locationEdit = QLineEdit(self) self.locationEdit.setSizePolicy( QSizePolicy.Expanding, self.locationEdit.sizePolicy().verticalPolicy()) self.webCounter = QLabel("(0%)") toolbarBrowserLayoutGroup.addWidget(QLabel("Load URL:")) toolbarBrowserLayoutGroup.addWidget(self.webCounter) toolbarBrowserLayoutGroup.addWidget(self.locationEdit) self.webTitle = QLabel("Title:") self.webView = QWebView() if QtHelper.str2bool( Settings.instance().readValue(key='Server/proxy-web-active')): proxy = QNetworkProxy() proxy.setType(3) # http proxy.setHostName( Settings.instance().readValue(key='Server/addr-proxy-http')) proxy.setPort( int(Settings.instance().readValue( key='Server/port-proxy-http'))) self.webView.page().networkAccessManager().setProxy(proxy) if QT_VERSION_STR.startswith("4."): self.webInspector = QWebInspector() self.webView.settings().setAttribute( QWebSettings.DeveloperExtrasEnabled, True) self.webInspector.setPage(self.webView.page()) self.webView.setHtml( '<html><head></head><body>No content loaded</body></html>') self.webView.settings().setAttribute(QWebSettings.PluginsEnabled, True) self.webView.settings().setAttribute( QWebSettings.JavascriptCanOpenWindows, True) browserLayoutGroup.addLayout(toolbarBrowserLayoutGroup) browserLayoutGroup.addWidget(self.webTitle) self.webTab = QTabWidget() self.webTab.addTab(self.webView, "Web Page") if QT_VERSION_STR.startswith("4."): self.webTab.addTab(self.webInspector, "Source Inspector") browserLayoutGroup.addWidget(self.webTab) self.setLayout(browserLayoutGroup)
current = home s = QSettings() for key, val in settings.iteritems(): settings_key = key for key2, val2 in current.iteritems(): if key2 == settings_key: settings_val = val2 current_setting = s.value(str(val).decode('unicode-escape')) s.setValue(unicode(str(val)), settings_val) s.sync() proxyEnabled = s.value("proxy/proxyEnabled", "") proxyType = s.value("proxy/proxyType", "") proxyHost = s.value("proxy/proxyHost", "") proxyPort = s.value("proxy/proxyPort", "") proxyUser = s.value("proxy/proxyUser", "") proxyPassword = s.value("proxy/proxyPassword", "") proxy = QNetworkProxy() proxy.setType(QNetworkProxy.HttpProxy) proxy.setHostName(proxyHost) proxy.setPort(int(proxyPort)) proxy.setUser(proxyUser) proxy.setPassword(proxyPassword) QNetworkProxy.setApplicationProxy(proxy) net_man = QgsNetworkAccessManager.instance() stringlist = "" net_man.setupDefaultProxyAndCache() net_man.setFallbackProxyAndExcludes(proxy, stringlist)
def main(): """ Catch the url (if any); then choose adequate defaults and build a browser window. Save cookies, if appropiate, at close. """ # Considerations: # Will use proxy? (if not google, fb, twitter... then yes) use_proxy = True # Which whitelist will use instead? host_whitelist = None # Will allow cookies? Which? Where are they saved? cookie_allow = ["github.com", "linkedin.com", "freerepublic.com"] cookie_file = None prefix = "" if len(argv) == 2: sitio = argv[1] if (sitio.split('.')[-2:] == ["facebook", "com"]): use_proxy = False host_whitelist = ["facebook.com", "akamaihd.net", "fbcdn.net"] cookie_allow = ["facebook.com"] cookie_file = "fbcookies.cj" prefix = "FB" elif (sitio.split('.')[-2:] == ["twitter", "com"]): use_proxy = False host_whitelist = ["twitter.com", "twimg.com"] cookie_allow = ["twitter.com"] cookie_file = "twcookies.cj" prefix = "TW" elif (sitio.split('.')[-2:] == ["google", "com"]): print "GOOGLE" use_proxy = False host_whitelist = [ "google.com", "google.com.mx", "googleusercontent.com", "gstatic.com", "googleapis.com" ] cookie_allow = ["google.com"] cookie_file = "gcookies.cj" prefix = "G" else: print "GENERAL" else: sitio = None print "EMPTY" # Proxy if use_proxy: proxy = QNetworkProxy() proxy.setType(QNetworkProxy.HttpProxy) proxy.setHostName('localhost') proxy.setPort(3128) QNetworkProxy.setApplicationProxy(proxy) app = QtGui.QApplication([]) clipboard = app.clipboard() db_log = DatabaseLog() netmanager = InterceptNAM(parent=app, name=prefix, log=db_log, whitelist=host_whitelist) cookiejar = CookieJar(parent=app, allowed=cookie_allow, storage=cookie_file) netmanager.setCookieJar(cookiejar) app.setApplicationName("Eilat") app.setApplicationVersion("1.2.002") mainwin = MainWin(netmanager, clipboard) if sitio: mainwin.add_tab(sitio) else: mainwin.add_tab() mainwin.show() def end_call(): """ The browser is closing - save cookies, if required. """ print "END" if cookie_file: print "SAVING COOKIES" with open(cookie_file, "w") as savefile: for cookie in cookiejar.allCookies(): savefile.write(cookie.toRawForm() + "\n") app.lastWindowClosed.connect(end_call) app.exec_()
def __init__(self, parent, logger, db_conn, update_func, safe_conn): super(TwitterGui, self).__init__(parent) self._db_conn = db_conn self.logger = logger self._reply_to_id = 0 self._update_func = update_func self._list = None if get_settings().get_proxy(): u = urlparse.urlsplit(get_settings().get_proxy()) proxy = QNetworkProxy() proxy.setType(QNetworkProxy.HttpProxy) proxy.setHostName(u.hostname); proxy.setPort(u.port) QNetworkProxy.setApplicationProxy(proxy); self.msgview = QWebView(self) self.msgview.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks) self.msgview.linkClicked.connect(self.link_clicked) self.userCombo = QComboBox(self) self.userCombo.setEditable(True) self.userCombo.activated.connect(self.toggle_user_in_list) self.showButton = QPushButton(chr(94), self) self.showButton.setMaximumHeight(13) self.showButton.clicked.connect(self.show_hide_animation) self.post_field = QTextEdit(self) self.post_field.setMaximumHeight(50) self.post_field.textChanged.connect(self.text_changed) self.send_button = QPushButton("Post", self) self.send_button.clicked.connect(self.post_status_clicked) self.refresh_button = QPushButton("Refresh", self) self.refresh_button.clicked.connect(self._update_func) self.attach_button = QPushButton("Attach", self) self.attach_button.clicked.connect(lambda _ : self.set_status("Attach something")) self.lists_box = QComboBox(self) self.lists_box.currentIndexChanged.connect(self.list_changed) self.lists_box.setEditable(False) self.lists_box.addItems([u"Home"] + self._db_conn.get_lists()) self.statusLabel = QLabel("Status", self) self.charCounter = QLabel("0", self) self.gridw = QWidget(self) self.gridw.setContentsMargins(0, 0, 0, 0) gridlay = QGridLayout(self.gridw) gridlay.setContentsMargins(0, 0, 0, 0) gridlay.addWidget(self.post_field, 0, 0, 2, 1) gridlay.addWidget(self.attach_button, 0, 1, 1, 1) gridlay.addWidget(self.send_button, 1, 1, 1, 1) gridlay.addWidget(self.lists_box, 0, 2, 1, 1) gridlay.addWidget(self.refresh_button, 1, 2, 1, 1) gridlay.addWidget(self.statusLabel, 2, 0, 1, 1) gridlay.addWidget(self.charCounter, 2, 1, 1, 2) hlay = QVBoxLayout(self) hlay.addWidget(self.msgview) hlay.addWidget(self.userCombo) hlay.addWidget(self.showButton) hlay.addWidget(self.gridw) safe_conn.connect_home_timeline_updated(self.update_view) safe_conn.connect_twitter_loop_started(self.start_refresh_animation) safe_conn.connect_twitter_loop_stopped(self.stop_refresh_animation) safe_conn.connect_update_posted(self.enable_posting) safe_conn.connect_range_limit_exceeded(lambda _ : self.set_status("Range limit exceeded")) safe_conn.connect_not_authenticated(lambda _ : self.set_status("Authentication failed")) self.gridw.hide() self.update_view() self.set_status("Twitter plugin initialized")
def main(): """ Catch the url (if any); then choose adequate defaults and build a browser window. Save cookies, if appropiate, at close. """ # Considerations: # Will use proxy? (if not google, fb, twitter... then yes) use_proxy = True # Which whitelist will use instead? host_whitelist = None # Will allow cookies? Which? Where are they saved? cookie_allow = ["github.com", "linkedin.com", "freerepublic.com"] cookie_file = None prefix = "" if len(argv) == 2: sitio = argv[1] if (sitio.split('.')[-2:] == ["facebook","com"]): use_proxy = False host_whitelist = ["facebook.com", "akamaihd.net", "fbcdn.net"] cookie_allow = ["facebook.com"] cookie_file = "fbcookies.cj" prefix = "FB" elif (sitio.split('.')[-2:] == ["twitter","com"]): use_proxy = False host_whitelist = ["twitter.com", "twimg.com"] cookie_allow = ["twitter.com"] cookie_file = "twcookies.cj" prefix = "TW" elif (sitio.split('.')[-2:] == ["google","com"]): print "GOOGLE" use_proxy = False host_whitelist = [ "google.com", "google.com.mx", "googleusercontent.com", "gstatic.com", "googleapis.com"] cookie_allow = ["google.com"] cookie_file = "gcookies.cj" prefix = "G" else: print "GENERAL" else: sitio = None print "EMPTY" # Proxy if use_proxy: proxy = QNetworkProxy() proxy.setType(QNetworkProxy.HttpProxy) proxy.setHostName('localhost') proxy.setPort(3128) QNetworkProxy.setApplicationProxy(proxy) app = QtGui.QApplication([]) clipboard = app.clipboard() db_log = DatabaseLog() netmanager = InterceptNAM( parent = app, name = prefix, log = db_log, whitelist = host_whitelist) cookiejar = CookieJar( parent = app, allowed = cookie_allow, storage = cookie_file) netmanager.setCookieJar(cookiejar) app.setApplicationName("Eilat") app.setApplicationVersion("1.2.002") mainwin = MainWin(netmanager, clipboard) if sitio: mainwin.add_tab(sitio) else: mainwin.add_tab() mainwin.show() def end_call(): """ The browser is closing - save cookies, if required. """ print "END" if cookie_file: print "SAVING COOKIES" with open(cookie_file, "w") as savefile: for cookie in cookiejar.allCookies(): savefile.write(cookie.toRawForm()+"\n") app.lastWindowClosed.connect(end_call) app.exec_()
socket.disconnectFromHost() if proxy_socket.error() != QTcpSocket.RemoteHostClosedError: url = proxy_socket.property('url').toUrl() error_string = proxy_socket.errorString() if self.debug: self.log.write('Error for %s %s\n\n' % (url, error_string)) proxy_socket.deleteLater() if __name__ == '__main__': app = QCoreApplication(sys.argv) server = HTTPProxy() manager = QNetworkAccessManager() manager.finished.connect(server.stopServing) manager.finished.connect(app.quit) proxy = QNetworkProxy() proxy.setType(QNetworkProxy.HttpProxy) proxy.setHostName('127.0.0.1') proxy.setPort(server.port()) proxy.setUser(server.username) proxy.setPassword(server.password) manager.setProxy(proxy) reply = manager.get(QNetworkRequest(QUrl('http://aws.amazon.com/'))) sys.exit(app.exec_())