def __init__(self, parent=None): super(proxies, self).__init__(parent) self.client = parent self.proxies = {} self.proxiesDestination = {} port = 12000 errored = False for i in range(11) : port = port + 1 self.proxies[i] = QtNetwork.QUdpSocket(self) if not self.proxies[i].bind(QtNetwork.QHostAddress.LocalHost, port) : self.__logger.warn("Can't bind socket %i" % i) errored = True else : self.__logger.info("binding socket %i on port %i" % (i, self.proxies[i].localPort())) self.proxies[i].readyRead.connect(functools.partial(self.processPendingDatagrams, i)) self.proxiesDestination[i] = None if errored: QtGui.QMessageBox.warning(self.client, "Cannot use proxy server", "FAF is unable to bind the port <b>12000 to 12011 on TCP</b>.<br>Please check your firewall settings.<br><b>You may experience connections problems until it's fixed.</b>") self.proxySocket = QtNetwork.QTcpSocket(self) self.proxySocket.connected.connect(self.connectedProxy) self.proxySocket.readyRead.connect(self.readData) self.proxySocket.disconnected.connect(self.disconnectedFromProxy) self.blockSize = 0 self.uid = None self.canClose = False self.testedPortsAmount = {} self.testedPorts = [] self.testedLoopbackAmount = {} self.testedLoopback = [] self.testing = False
def _consultar_ultima_version_del_servidor(self): direccion = QtCore.QUrl("https://raw.githubusercontent.com/hugoruscitti/pilas/gh-pages/version.json") self.manager = QtNetwork.QNetworkAccessManager(self.MainWindow) self.manager.get(QtNetwork.QNetworkRequest(direccion)) self.manager.connect(self.manager, QtCore.SIGNAL("finished(QNetworkReply*)"), self._cuando_termina_de_consultar_version)
def firstWindow(self, fileNames): """Open first main window""" try: # check for existing TreeLine session socket = QtNetwork.QLocalSocket() socket.connectToServer('treeline-session', QtCore.QIODevice.WriteOnly) # if found, send files to open and exit TreeLine if socket.waitForConnected(1000): socket.write(repr(fileNames)) if socket.waitForBytesWritten(1000): socket.close() sys.exit(0) qApp = QtGui.QApplication.instance() # start local server to listen for attempt to start new session self.serverSocket = QtNetwork.QLocalServer() self.serverSocket.listen('treeline-session') qApp.connect(self.serverSocket, QtCore.SIGNAL('newConnection()'), self.getSocket) except AttributeError: print 'Warning: Could not create local socket' if fileNames: fileNames = [unicode(fileName, globalref.localTextEncoding) for fileName in fileNames] self.openMultipleFiles(fileNames) else: win = treemainwin.TreeMainWin() self.windowList.append(win) self.updateWinMenu() self.autoOpen() win.show() globalref.setStatusBar(_('Ready'), 2000)
def _consultar_ultima_version_del_servidor(self): direccion = QtCore.QUrl("http://www.pilas-engine.com.ar/version.json") self.manager = QtNetwork.QNetworkAccessManager(self.main) self.manager.get(QtNetwork.QNetworkRequest(direccion)) self.manager.connect(self.manager, QtCore.SIGNAL("finished(QNetworkReply*)"), self._cuando_termina_de_consultar_version)
def __init__(self, argv): QtGui.QApplication.__init__(self, argv) settings = utils.Settings() # Prepare socket for sending notifications self.socketTo = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.socketTo.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) self.socketTo.connect(('255.255.255.255', settings.notificationPort)) # Prepare socket for receiving notifications self.socketFrom = QtNetwork.QUdpSocket() anyAddress = QtNetwork.QHostAddress(QtNetwork.QHostAddress.Any) self.socketFrom.bind(anyAddress, settings.notificationPort) self.connect(self.socketFrom, SIGNAL("readyRead()"), self.onNotification) # Prepare the ping agent self.pingAgent = PingAgent(self, settings.dbHost) # Run the timer which checks the connection periodically self.connectionTimer = QTimer(self) self.connect(self.connectionTimer, SIGNAL("timeout()"), self.checkConnection) # Check the connection every 16 seconds if the connection is lost # or every 5 minutes if the connection is here self.connectionTimer.start(16 * 1000) # Check it at the very beginning QtCore.QTimer.singleShot(1000, self.checkConnection)
def __init__(self, guid, *argv): super(QtSingleApplication, self).__init__(*argv) self._id = guid self._activationWindow = None self._activateOnMessage = False # Is there another instance running? self._outSocket = QtNetwork.QLocalSocket() self._outSocket.connectToServer(self._id) self._isRunning = self._outSocket.waitForConnected() if self._isRunning: # Yes, there is. self._outStream = QtCore.QTextStream(self._outSocket) self._outStream.setCodec('UTF-8') else: # No, there isn't. self._outSocket = None self._outStream = None self._inSocket = None self._inStream = None self._server = QtNetwork.QLocalServer() self._server.listen(self._id) # noinspection PyUnresolvedReferences self._server.newConnection.connect( self._onNewConnection ) # PyCharm doesn't recognize newConnection.connect()...
def send_server_invite_option(self, invite_client_ids, channel_id): # for each client_id find the socket on which to send the # server_invite option for invite_client_id in invite_client_ids: for _, client_sockets in self.channels.items(): for (client_id, socket) in client_sockets: if invite_client_id == client_id: #Hier kann es auch sein, dass nur eine Id gebraucht #wird und nicht eine Liste... option_data = Container(channel_id=channel_id, client_id=invite_client_ids) option = Container(option_id="SERVER_INVITE_OPTION", option_data=option_data) pdu = Container(id=self.id, option=[option]) ip_to_invite = QtNetwork.QHostAddress( socket.peerAddress()) udpSocket_for_invites = QtNetwork.QUdpSocket(self) udpSocket_for_invites.bind( ip_to_invite, broadcast_port, QtNetwork.QUdpSocket.ShareAddress) udpSocket_for_invites.writeDatagram( InstantSoupData.peer_pdu.build(pdu), ip_to_invite, broadcast_port) log.debug('PDU: SERVER_INVITE_OPTION - id: %i - SENT' % self.pdu_number)
def __init__(self, id, *argv): super(QtSingleApplication, self).__init__(*argv) self._id = id self._activationWindow = None self._activateOnMessage = False # Is there another instance running? self._outSocket = QtNetwork.QLocalSocket() self._outSocket.connectToServer(self._id) self._isRunning = self._outSocket.waitForConnected() if self._isRunning: # Yes, there is. self._outStream = QtCore.QTextStream(self._outSocket) self._outStream.setCodec('UTF-8') else: # No, there isn't. self._outSocket = None self._outStream = None self._inSocket = None self._inStream = None self._server = QtNetwork.QLocalServer(self) self._server.listen(self._id) self._server.newConnection.connect(self._onNewConnection) self.NAM = QtNetwork.QNetworkAccessManager(self)
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.blockSize = 0 self.tcpSocket = QtNetwork.QTcpSocket(self) self.tcpSocket.readyRead.connect(self.readSig) self.tcpSocket.connectToHost(QtNetwork.QHostAddress('127.0.0.1'), 5000)
def Do_DownloadData(strFile, isFin=False): strData = 'GET /userRpm/' + strFile + ' HTTP/1.1\r\n' \ 'Cookie: ' + conf__strCookie + '\r\n' \ 'Referer: ' + conf__strLinkPrefix + 'MenuRpm.htm\r\n\r\n' print strData cachedData = [] def on_ready_read(): if client.bytesAvailable(): print '-' * 50 print 'on_ready_read()' print client.bytesAvailable(), 'read.' data = str(client.readAll()) cachedData.append(data) print len(data), client.bytesAvailable() #print data def on_connected(): client.writeData(strData) print 'connected.' def on_disconnect(): print '-' * 50 print 'on_disconnect()' print len(cachedData) print ''.join(cachedData) if isFin: exit(0) client = QtNetwork.QTcpSocket() client.readyRead.connect(on_ready_read) client.connected.connect(on_connected) client.disconnected.connect(on_disconnect) client.connectToHost(QtNetwork.QHostAddress('192.168.1.1'), 80)
def sendSDP(self, flags, tag, dp, dc, dax, day, cmd, seq, arg1, arg2, arg3, bArray): """ You know, the detail experiment with sendSDP() see mySDPinger.py the bArray can be constructed simply by using type casting. Ex: elements = [0, 200, 50, 25, 10, 255] bArray = bytearray(elements) # byte must be in range(0, 256) Something wrong with bArray -> try to use list instead """ da = (dax << 8) + day dpc = (dp << 5) + dc sa = 0 spc = 255 pad = struct.pack('2B', 0, 0) hdr = struct.pack('4B2H', flags, tag, dpc, spc, da, sa) scp = struct.pack('2H3I', cmd, seq, arg1, arg2, arg3) sdp = pad + hdr + scp """ if bArray is not None: sdp = pad + hdr + scp + bArray else: sdp = pad + hdr + scp """ if bArray is not None: for b in bArray: sdp += struct.pack('<B', b) #sdp += b CmdSock = QtNetwork.QUdpSocket() CmdSock.writeDatagram(sdp, QtNetwork.QHostAddress(DEF_HOST), DEF_SEND_PORT) time.sleep(DEF_SDP_TIMEOUT) return sdp
def __init__(self, parent): QtCore.QObject.__init__(self, parent) self.host2ip = {} self.ip2host = {} self.last_calc = time.time() self.pilotsHistory = {} self.timer = QtCore.QTimer(self) self.connect(self.timer, QtCore.SIGNAL("timeout()"), self.on_timer) self.dnsLookupThread = DnsLookupThread(self) self.connect(self.dnsLookupThread, QtCore.SIGNAL("domain_found"), self.on_domain_found) #def run(self): self.dnsLookupThread.start() self.timer.start(1000) self.telnetString = {} self.telnetTimer = {} self.telnetSocket = {} self.lastUpdate = None self.server = QtNetwork.QTcpServer(self) self.connect(self.server, QtCore.SIGNAL("newConnection()"), self.on_websocket_connection) self.server.listen(QtNetwork.QHostAddress(QtNetwork.QHostAddress.Any), 5050) self.clientSockets = {} self.increment = 0
def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.setupUi(self) self.setCentralWidget(self.mdiArea); self.statusTxt = QtGui.QLabel("") self.statusBar().addWidget(self.statusTxt) self.connect(self.action_Tubotron, SIGNAL("triggered()"), SLOT("Tubotron()")) self.connect(self.action_Temperature, SIGNAL("triggered()"), SLOT("Temperature()")) self.connect(self.action_Utilization, SIGNAL("triggered()"), SLOT("Utilization()")) self.connect(self.action_Frequency, SIGNAL("triggered()"), SLOT("Frequency()")) self.connect(self.action_SaveData, SIGNAL("triggered()"), SLOT("SaveData()")) self.connect(self.action_SelectBoard, SIGNAL("triggered()"), SLOT("SelectBoard()")) self.connect(self.action_CoreSwitcher, SIGNAL("triggered()"), SLOT("CoreSwitch()")) self.TubSock = QtNetwork.QUdpSocket(self) # this is for Tubotron self.RptSock = QtNetwork.QUdpSocket(self) # this if for report streaming (temperature, utilization, etc) self.RplSock = QtNetwork.QUdpSocket(self) # this for generic reply for specific command request self.initRptSock(DEF.RECV_PORT) self.initRplSock(DEF.REPLY_PORT) self.uw = None self.tw = None self.fw = None self.sw = None # First, trigger the Board type and get the core map self.SelectBoard()
def __init__(self, argv): super(SingleApplication, self).__init__(argv) self.isSingle = True self.setApplicationName('HelloWord') serverName = self.applicationName() socket = QtNetwork.QLocalSocket() socket.connectToServer(serverName) if socket.waitForConnected(1000): # print u'已存在一个实例' self.isSingle = False return # print u'建立本地服务器' self.server = QtNetwork.QLocalServer(self) # self.server.listen(serverName) self.server.newConnection.connect(self.newLocalConnection) if not self.server.listen(serverName): # print '听' # 防止程序崩溃时,残留进程服务,移除之 # 确保监听成功 if self.server.serverError() == QtNetwork.QAbstractSocket.AddressInUseError and \ QtCore.QFile.exists(self.server.serverName()): QtCore.QFile.remove(self.server.serverName()) # print u'什么情况?' self.server.listen(serverName)
def __init__(self): QtGui.QMainWindow.__init__(self) self.tabs = QtGui.QTabWidget( self, tabsClosable=True, movable=True, currentChanged=self.currentTabChanged, elideMode=QtCore.Qt.ElideRight, tabCloseRequested=lambda idx: self.tabs.widget(idx).deleteLater()) self.setCentralWidget(self.tabs) self.bars = {} self.star = QtGui.QAction(QtGui.QIcon.fromTheme("emblem-favorite"), "Bookmark", self, checkable=True, triggered=self.bookmarkPage, shortcut="Ctrl+d") self.tabs.setCornerWidget( QtGui.QToolButton(self, text="New Tab", icon=QtGui.QIcon.fromTheme("document-new"), clicked=lambda: self.addTab().url.setFocus(), shortcut="Ctrl+t")) self.addAction( QtGui.QAction("Full Screen", self, checkable=True, toggled=lambda v: self.showFullScreen() if v else self.showNormal(), shortcut="F11")) self.bookmarks = self.get("bookmarks", {}) self.bookmarkPage() # Load the bookmarks menu self.history = self.get("history", []) + self.bookmarks.keys() self.completer = QtGui.QCompleter( QtCore.QStringList([QtCore.QString(u) for u in self.history])) # Use a app-wide, persistent cookiejar self.cookies = QtNetwork.QNetworkCookieJar( QtCore.QCoreApplication.instance()) self.cookies.setAllCookies([ QtNetwork.QNetworkCookie.parseCookies(c)[0] for c in self.get("cookiejar", []) ]) # Downloads bar at the bottom of the window self.downloads = QtGui.QToolBar("Downloads") self.addToolBar(QtCore.Qt.BottomToolBarArea, self.downloads) # Proxy support proxy_url = QtCore.QUrl(os.environ.get('http_proxy', '')) QtNetwork.QNetworkProxy.setApplicationProxy( QtNetwork.QNetworkProxy( QtNetwork.QNetworkProxy.HttpProxy if unicode(proxy_url.scheme( )).startswith('http') else QtNetwork.QNetworkProxy.Socks5Proxy, proxy_url.host(), proxy_url.port(), proxy_url.userName(), proxy_url.password())) if 'http_proxy' in os.environ else None [self.addTab(QtCore.QUrl(u)) for u in self.get("tabs", [])]
def __init__(self, client): self.client = client self.s = QtNetwork.QLocalSocket() self.s.readyRead.connect(self.create) self.s2 = QtNetwork.QLocalSocket() self.s2.readyRead.connect(self.changeValue) self.l = kst.LineEdit(client, "", self.s2, 0.47, 0.975, 0.93, 0.025) self.b = kst.Button(client, "Go!", self.s, 0.97, 0.975, 0.05, 0.025) self.plot = client.new_plot((0.5, 0.4885), (0.9, 0.8)) self.genVec = client.new_generated_vector(-100, 100, 1000)
def __init__(self, send_port, targetIP, parent=None): super(UDP_sendStatus, self).__init__(parent) self.sendPort = num(send_port) self.target_IP = QtNetwork.QHostAddress(targetIP) try: self.ss = QtNetwork.QUdpSocket(self) except: print "Trouble opening UDP on socket %d" % (self.sendPort)
def start(self): self.messageEmited.emit("NGQ Manager", "Initialization" + "...", QtGui.QSystemTrayIcon.Information, 100) self.tcpServer = QtNetwork.QTcpServer() self.tcpServer.listen(QtNetwork.QHostAddress(self.__host), self.__port) self.tcpServer.newConnection.connect(self.__newConnectionHandle) self.configure() self.ngqListChanged.connect(self.__chooseWaitingTasksForProject) self.__putToWaitingTasks(partial(self.executeArgs, self.__argString), None, self.__initializationTime)
def sendChunk(ch_port, ba): da = 0 dpc = (ch_port << 5) + 1 sa = 0 spc = 255 pad = struct.pack('<2B', 0, 0) hdr = struct.pack('<4B2H', 7, 0, dpc, spc, da, sa) sdp = pad + hdr + ba CmdSock = QtNetwork.QUdpSocket() CmdSock.writeDatagram(sdp, QtNetwork.QHostAddress(DEF_HOST), DEF_SEND_PORT) CmdSock.flush()
def sendImgInfo(self, cmd, data_type): dpc = (SDP_RECV_JPG_INFO_PORT << 5) + SDP_RECV_CORE_ID #destination port and core pad = struct.pack('2B', 0, 0) hdr = struct.pack('4B2H', 7, 0, dpc, 255, 0, 0) scp = struct.pack('2H3I', cmd, data_type, self.szImgFile, 0, 0) sdp = pad + hdr + scp CmdSock = QtNetwork.QUdpSocket() CmdSock.writeDatagram(sdp, QtNetwork.QHostAddress(self.spinn), SPINN_PORT) CmdSock.flush() # then give a break, otherwise spinnaker will collapse self.delay()
def checkConnection(self): # check if connection to 8.8.8.8:53 is available """ Host: 8.8.8.8 (google-public-dns-a.google.com) OpenPort: 53/tcp Service: domain (DNS/TCP) """ url = "http://www.google.com" req = QtNetwork.QNetworkRequest(QUrl(url)) self.nam = QtNetwork.QNetworkAccessManager() self.nam.finished.connect(self.connectionResponse) self.nam.get(req)
def __init__(self, parent=None): super(App, self).__init__(parent) x, y, w, h = 500, 200, 1024, 768 self.setGeometry(x, y, w, h) self.setFixedSize(w, h) self.url_lineedit = QtGui.QLineEdit(self) self.url_lineedit.setGeometry(0, 0, 900, 22) self.connect(self.url_lineedit, QtCore.SIGNAL('returnPressed()'), self.url_returnPressed) self.progressbar = QtGui.QProgressBar(self) self.progressbar.setGeometry(900, 0, 124, 22) self.progressbar.setMinimum(0) self.progressbar.setMaximum(100) self.webview = QtWebKit.QWebView(self) qsettings = self.webview.settings() qsettings.setAttribute(QtWebKit.QWebSettings.DeveloperExtrasEnabled, True) self.inspector = QtWebKit.QWebInspector(self) self.inspector.setPage(self.webview.page()) self.inspector.setGeometry(0, h - 200, w, 200) self.inspector.setVisible(True) self.webview.setGeometry(0, 22, w, h - 200) self.connect(self.webview, QtCore.SIGNAL("loadStarted()"), self.webview_loadStarted) self.connect(self.webview, QtCore.SIGNAL("loadFinished(bool)"), self.webview_loadFinished) self.connect(self.webview, QtCore.SIGNAL('loadProgress(int)'), self.webview_loadProgress) cache = QtNetwork.QNetworkDiskCache() dir = QtGui.QDesktopServices.storageLocation( QtGui.QDesktopServices.CacheLocation) cache.setCacheDirectory(dir) self.am = self.webview.page().networkAccessManager() self.am.setCache(cache) self.cj = QtNetwork.QNetworkCookieJar() self.am.setCookieJar(self.cj) self._portal_url = "http://www.baidu.com/" self.url_lineedit.setText(self._portal_url) self.webview.load(QtCore.QUrl(self._portal_url)) self.url_lineedit.setFocus() self.setup_global_shortcuts()
def sendImgInfo(self): dpc = (SDP_RECV_RAW_INFO_PORT << 5) + SDP_RECV_CORE_ID # destination port and core pad = struct.pack('2B', 0, 0) hdr = struct.pack('4B2H', 7, 0, dpc, 255, 0, 0) scp = struct.pack('2H3I', SDP_CMD_INIT_SIZE, 0, len(self.orgImg), self.wImg, self.hImg) sdp = pad + hdr + scp CmdSock = QtNetwork.QUdpSocket() CmdSock.writeDatagram(sdp, QtNetwork.QHostAddress(self.spinn), SPINN_PORT) CmdSock.flush() # then give a break, otherwise spinnaker might collapse self.delay()
def __init__(self, def_image_dir="./", parent=None): self.img_dir = def_image_dir self.img = None self.res = None self.continyu = True super(edgeGUI, self).__init__(parent) self.setupUi(self) self.orgViewPort = imgWidget("Original Image") #self.orgViewPort.show() self.resViewPort = imgWidget("Result SpiNNaker") #self.resViewPort.show() self.hostViewPort = imgWidget("Result PC-version") #self.hostViewPort.show() self.trx = trxIndicator() #self.trx.show() self.connect(self.pbLoad, QtCore.SIGNAL("clicked()"), QtCore.SLOT("pbLoadClicked()")) self.connect(self.pbSend, QtCore.SIGNAL("clicked()"), QtCore.SLOT("pbSendClicked()")) self.connect(self.pbProcess, QtCore.SIGNAL("clicked()"), QtCore.SLOT("pbProcessClicked()")) self.connect(self.pbSave, QtCore.SIGNAL("clicked()"), QtCore.SLOT("pbSaveClicked()")) self.connect(self.pbClear, QtCore.SIGNAL("clicked()"), QtCore.SLOT("pbClearClicked()")) #self.connect(self.cbSpiNN, QtCore.SIGNAL("currentIndexChanged(int)")), QtCore.SLOT("cbSpiNNChanged(int)") self.cbSpiNN.currentIndexChanged.connect(self.cbSpiNNChanged) if spiNN == spin3: self.cbSpiNN.setCurrentIndex(0) else: self.cbSpiNN.setCurrentIndex(1) # self.sdpUpdate can be connected to other slot # self.sdpUpdate.connect(SOME_OTHER_SLOT) self.RptSock = QtNetwork.QUdpSocket(self) self.sdpSender = QtNetwork.QUdpSocket(self) self.initRptSock(DEF_RESULT_PORT) # self.initRptSock(DEF_REPLY_PORT) self.DbgSock = QtNetwork.QUdpSocket(self) self.initDbgSock(DEF_DEBUG_PORT) self.tResult = [0, 0, 0] self.debugVal = 0 self.ResultTriggered = False
def start(self): if self.port: self.stop() if config.setting["browser_integration_localhost_only"]: self.host_address = QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost) else: self.host_address = QtNetwork.QHostAddress(QtNetwork.QHostAddress.Any) for port in range(config.setting["browser_integration_port"], 65535): if self.listen(self.host_address, port): log.debug("Starting the browser integration (%s:%d)", self.host_address.toString(), port) self.port = port self.tagger.listen_port_changed.emit(self.port) break
def checkConnection(self): from PyQt4 import QtNetwork self.socket = QtNetwork.QLocalSocket(self) self.connect(self.socket, QtCore.SIGNAL('connected()'), self.onSocketConnected) self.socket.connectToServer(self.serverName) if not self.socket.waitForConnected(1000): self.isServer = True if self.isServer: self.server = QtNetwork.QLocalServer() self.connect(self.server, QtCore.SIGNAL('newConnection()'), self.onNewConnection) QtNetwork.QLocalServer.removeServer(self.serverName)
def new_network_request(self): if self.network_reply and not self.network_reply.isFinished(): self.network_reply.abort() if self.proxy_host_editor.text(): proxy = QtNetwork.QNetworkProxy( QtNetwork.QNetworkProxy.HttpProxy, self.proxy_host_editor.text(), int(str(self.proxy_port_editor.text()))) #, #self.proxy_username_editor.text(), #self.proxy_password_editor.text() ) self.manager.setProxy(proxy) else: self.manager.setProxy(QtNetwork.QNetworkProxy()) self.network_reply = self.manager.get( QtNetwork.QNetworkRequest(QtCore.QUrl('http://aws.amazon.com')))
def requestHandData(self, url, timeout=-1, proxyHostName=None, proxyPort=80, proxyUserName=None, proxyPassword=None, userAgent=None): # check what proxy to use if not proxyHostName and not self.proxy().hostName(): # no proxy set pass elif not proxyHostName and self.proxy().hostName(): # reset proxy to default self.setProxy(self.defaultProxy) elif proxyHostName == self.proxy().hostName(): # check if we have to create another proxy myProxy = self.proxy() if proxyPort != myProxy.port() or proxyUserName != myProxy.user( ) or proxyPassword != myProxy.password(): proxy = QtNetwork.QNetworkProxy() proxy.setType(proxy.HttpProxy) proxy.setHostName(proxyHostName) proxy.setPort(proxyPort) if proxyUserName: proxy.setUser(proxyUserName) if proxyPassword: proxy.setPassword(proxyPassword) self.setProxy(proxy) elif proxyHostName != self.proxy().hostName(): # create new proxy proxy = QtNetwork.QNetworkProxy() proxy.setType(proxy.HttpProxy) proxy.setHostName(proxyHostName) proxy.setPort(proxyPort) if proxyUserName: proxy.setUser(proxyUserName) if proxyPassword: proxy.setPassword(proxyPassword) self.setProxy(proxy) else: raise valueError('we should not have ended here!') if self._reply is not None: self._reply.abort() self._timer.stop() request = QtNetwork.QNetworkRequest(url) if userAgent is not None: request.setRawHeader('User-Agent', userAgent) self._reply = self.get(request) if timeout >= 0: self._timer.start(timeout)
def __init__(self, name, socket, requester, *args, **kwargs): ''' Constructor ''' QtCore.QObject.__init__(self, *args, **kwargs) self.name = name logger = logging.getLogger("faf.secondaryServer.%s" % self.name) logger.info("Instanciating secondary server.") self.socketPort = socket self.requester = requester self.result = self.RESULT_NONE self.command = None self.message = None self.blockSize = 0 self.serverSocket = QtNetwork.QTcpSocket() self.serverSocket.error.connect(self.handleServerError) self.serverSocket.readyRead.connect(self.readDataFromServer) self.serverSocket.disconnected.connect(self.disconnected) self.serverSocket.error.connect(self.errored) self.invisible = False
def getNetworkProxyFromQgsSettings(self): """ get (QNetworkProxy) proxy from qgis options settings """ proxy = QtNetwork.QNetworkProxy() s = QSettings() 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", "") if proxyEnabled == "true": # test if there are proxy settings if proxyType == "DefaultProxy": proxy.setType(QtNetwork.QNetworkProxy.DefaultProxy) elif proxyType == "Socks5Proxy": proxy.setType(QtNetwork.QNetworkProxy.Socks5Proxy) elif proxyType == "HttpProxy": proxy.setType(QtNetwork.QNetworkProxy.HttpProxy) elif proxyType == "HttpCachingProxy": proxy.setType(QtNetwork.QNetworkProxy.HttpCachingProxy) elif proxyType == "FtpCachingProxy": proxy.setType(QtNetwork.QNetworkProxy.FtpCachingProxy) proxy.setHostName(proxyHost) proxy.setPort(int(proxyPort)) proxy.setUser(proxyUser) proxy.setPassword(proxyPassword) return proxy