def testSetupProxy(self): """Test proxy setup""" settings = QgsSettings() settings.setValue("proxy/proxyEnabled", True) settings.setValue("proxy/proxyPort", '1234') settings.setValue("proxy/proxyHost", 'myproxyhostname.com') settings.setValue("proxy/proxyUser", 'username') settings.setValue("proxy/proxyPassword", 'password') settings.setValue("proxy/proxyExcludedUrls", "http://www.myhost.com|http://www.myotherhost.com") QgsNetworkAccessManager.instance().setupDefaultProxyAndCache() vl = QgsVectorLayer(TEST_DATA_DIR + '/' + 'lines.shp', 'proxy_test', 'ogr') self.assertTrue(vl.isValid()) self.assertEqual(gdal.GetConfigOption("GDAL_HTTP_PROXY"), "myproxyhostname.com:1234") self.assertEqual(gdal.GetConfigOption("GDAL_HTTP_PROXYUSERPWD"), "username:password") settings.setValue("proxy/proxyEnabled", True) settings.remove("proxy/proxyPort") settings.setValue("proxy/proxyHost", 'myproxyhostname.com') settings.setValue("proxy/proxyUser", 'username') settings.remove("proxy/proxyPassword") settings.setValue("proxy/proxyExcludedUrls", "http://www.myhost.com|http://www.myotherhost.com") QgsNetworkAccessManager.instance().setupDefaultProxyAndCache() vl = QgsVectorLayer(TEST_DATA_DIR + '/' + 'lines.shp', 'proxy_test', 'ogr') self.assertTrue(vl.isValid()) self.assertEqual(gdal.GetConfigOption("GDAL_HTTP_PROXY"), "myproxyhostname.com") self.assertEqual(gdal.GetConfigOption("GDAL_HTTP_PROXYUSERPWD"), "username")
def __sync_request(self, url): _url = QUrl(url) _request = QNetworkRequest(_url) self.__replies.append(_request) QgsNetworkAccessManager.instance().sslErrors.connect(self.__supress_ssl_errors) _reply = QgsNetworkAccessManager.instance().get(_request) # wait loop = QEventLoop() _reply.finished.connect(loop.quit) loop.exec_() _reply.finished.disconnect(loop.quit) QgsNetworkAccessManager.instance().sslErrors.disconnect(self.__supress_ssl_errors) loop = None error = _reply.error() if error != QNetworkReply.NoError: raise Exception(error) result_code = _reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) result = _reply.readAll() self.__replies.append(_reply) _reply.deleteLater() if result_code in [301, 302, 307]: redirect_url = _reply.attribute(QNetworkRequest.RedirectionTargetAttribute) return self.__sync_request(redirect_url) else: return result
def DownLoadOverQT (dlURL, LokFileName): # QGIS3: funktioniert unter QGIS 3.x recht zuverlässig auch auf "eingeschränktem Rechner" # - nutzt die Proxyeinstellungen von QGIS # - funktioniert in QGIS selbst auch über HTTPS (es wird durch QGIS eiun Abfragefenster geöffnet) # - bei extrem großen Dateien (z.B. 500MBYte) crasht es bei ReadAll() # QGIS2: funktioniert unter QGIS 2.x innerhalb von QGIS aktuell recht zuverlässig auch auf "eingeschränktem Rechner" # außerhalb hängt sich der Code auf "eingeschräktem Rechner" auf und bringt dann auch kein Ergebnis # Normalrechner funktioniert es def WriteFile(LokFileName, content): # 1. Ziel löschen, wenn existent if path.exists(LokFileName): remove (LokFileName) out=open(LokFileName,'wb') out.write(content) out.close() def onfinish(): WriteFile(LokFileName,reply.readAll()); loop.quit() # 2. Download request = QNetworkRequest() request.setUrl(QUrl(dlURL)) manager = QgsNetworkAccessManager.instance() reply = manager.get(request) reply.setParent(None) loop = QEventLoop() reply.finished.connect(onfinish) loop.exec_() # Wiederholung bei redirekt (13.08.18 Thüringen leitet an HTTPS weiter) status=reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) if (status==301): redirectUrl = reply.attribute(request.RedirectionTargetAttribute) request = QNetworkRequest() request.setUrl(redirectUrl) manager = QgsNetworkAccessManager.instance() reply = manager.get(request) reply.setParent(None) loop = QEventLoop() reply.finished.connect(onfinish) loop.exec_() if path.exists(LokFileName): return path.getsize(LokFileName), reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) else: return None, reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) reply.deleteLater()
def sendVote(self, plugin_id, vote): """ send vote via the RPC """ if not plugin_id or not vote: return False url = "http://plugins.qgis.org/plugins/RPC2/" params = {"id": "djangorpc", "method": "plugin.vote", "params": [str(plugin_id), str(vote)]} req = QNetworkRequest(QUrl(url)) req.setRawHeader(b"Content-Type", b"application/json") QgsNetworkAccessManager.instance().post(req, bytes(json.dumps(params), "utf-8")) return True
def sendVote(self, plugin_id, vote): """ send vote via the RPC """ if not plugin_id or not vote: return False url = "http://plugins.qgis.org/plugins/RPC2/" params = "{\"id\":\"djangorpc\",\"method\":\"plugin.vote\",\"params\":[%s,%s]}" % (str(plugin_id), str(vote)) req = QNetworkRequest(QUrl(url)) req.setRawHeader("Content-Type", "application/json") QgsNetworkAccessManager.instance().post(req, params) return True
def executeRequest (self, url, callback, post = None): self.messageBar.clearWidgets() self.cmbOfferings.setEnabled (False) self.tabWidget.setEnabled (False) if post: request = QNetworkRequest(url) request.setRawHeader('Content-Type', 'application/xml') self.reply = QgsNetworkAccessManager.instance().post(request,post) else: self.reply = QgsNetworkAccessManager.instance().get(QNetworkRequest(url)) progressMessageBar = self.messageBar.createMessage(self.tr("Please wait while downloading")) progressBar = QtGui.QProgressBar(self) progressBar.setMinimum(0) progressBar.setFormat(self.tr("%v bytes downloaded!")) progressBar.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) def updateProgress (read, total): try: progressBar.setMaximum (total) progressBar.setValue (read) except: pass updateProgress (0,0) self.reply.downloadProgress.connect (updateProgress) progressMessageBar.layout().addWidget(progressBar) btnAbort = QtGui.QPushButton(self.tr("Abort")) btnAbort.clicked.connect(self.reply.abort) progressMessageBar.layout().addWidget(btnAbort) fd, replyFilename = mkstemp(suffix=".xml", prefix = callback.__name__, dir = self.selectedWorkDir()) os.close(fd) replyFile = open (replyFilename, "w") def replyReadyRead (): try: replyFile.write (self.reply.readAll()) except: pass self.reply.readyRead.connect(replyReadyRead) def finishRequest (): replyFile.close() self.cmbOfferings.setEnabled (True) self.tabWidget.setEnabled(True) self.messageBar.clearWidgets() if self.reply.error() != QNetworkReply.NoError: self.messageBar.pushMessage(self.reply.errorString(), QgsMessageBar.CRITICAL) else: callback(replyFilename) self.reply.deleteLater() self.reply.finished.connect(finishRequest) self.messageBar.pushWidget(progressMessageBar, QgsMessageBar.INFO)
def _getProxySettings(self): self.proxyEnabled = self.proxyHost = self.proxyPort = self.proxyUser = self.proxyPassword = None self.proxyUrl = "" proxyEnabled = self.s.value("proxy/proxyEnabled", "") if proxyEnabled == 1 or proxyEnabled == "true": self.proxyEnabled = True self.proxy_type = self.s.value("proxy/proxyType", "") self.proxyHost = self.s.value("proxy/proxyHost", "" ) self.proxyPort = self.s.value("proxy/proxyPort", "" ) self.proxyUser = self.s.value("proxy/proxyUser", "" ) self.proxyPassword = self.s.value("proxy/proxyPassword", "" ) if self.proxy_type == "DefaultProxy": proxies = urllib.request.getproxies() if len(proxies) == 0: qgsNetMan = QgsNetworkAccessManager.instance() proxy = qgsNetMan.proxy().applicationProxy() self.proxyHost = proxy.hostName() self.proxyPort = str(proxy.port()) self.proxyUser = proxy.user() self.proxyPassword = proxy.password() elif len(proxies) > 0 and 'http' in list(proxies.keys()): self.proxyUrl = proxies['http'] self.proxyUrlS = proxies['https'] else: self.proxyUrl = "http://" if self.proxyUser and self.proxyPassword: self.proxyUrl += self.proxyUser + ':' + self.proxyPassword + '@' self.proxyUrl += self.proxyHost + ':' + self.proxyPort self.proxyUrlS = self.proxyUrl.replace("http://", "https://")
def __init__(self, resourceType): super(GetScriptsAndModelsDialog, self).__init__(iface.mainWindow()) self.setupUi(self) self.manager = QgsNetworkAccessManager.instance() self.resourceType = resourceType if self.resourceType == self.MODELS: self.folder = ModelerUtils.modelsFolder() self.urlBase = 'https://raw.githubusercontent.com/qgis/QGIS-Processing/master/models/' self.icon = QIcon(os.path.join(pluginPath, 'images', 'model.png')) elif self.resourceType == self.SCRIPTS: self.folder = ScriptUtils.scriptsFolder() self.urlBase = 'https://raw.githubusercontent.com/qgis/QGIS-Processing/master/scripts/' self.icon = QIcon(os.path.join(pluginPath, 'images', 'script.png')) else: self.folder = RUtils.RScriptsFolder() self.urlBase = 'https://raw.githubusercontent.com/qgis/QGIS-Processing/master/rscripts/' self.icon = QIcon(os.path.join(pluginPath, 'images', 'r.png')) self.lastSelectedItem = None self.updateToolbox = False self.populateTree() self.buttonBox.accepted.connect(self.okPressed) self.buttonBox.rejected.connect(self.cancelPressed) self.tree.currentItemChanged.connect(self.currentItemChanged)
def executeProcess(self, processUrl, requestXml): self._processExecuted = False self.noFilesToFetch = 0 postData = QByteArray() postData.append(requestXml) scheme = processUrl.scheme() path = processUrl.path() server = processUrl.host() port = processUrl.port() processUrl.removeQueryItem('Request') processUrl.removeQueryItem('identifier') processUrl.removeQueryItem('Version') processUrl.removeQueryItem('Service') qDebug("Post URL=" + pystring(processUrl)) thePostHttp = QgsNetworkAccessManager.instance() request = QNetworkRequest(processUrl) request.setHeader( QNetworkRequest.ContentTypeHeader, "text/xml" ) #qDebug("Post REQUEST=" + pystring(postData)) self.thePostReply = thePostHttp.post(request, postData) self.thePostReply.finished.connect(partial(self.resultHandler, self.thePostReply) )
def get_qgis_proxy(cls): s = cls.get_settings() proxy_enabled = s.value("proxy/proxyEnabled", u"", type=unicode) proxy_type = s.value("proxy/proxyType", u"", type=unicode) proxy_host = s.value("proxy/proxyHost", u"", type=unicode) proxy_port = s.value("proxy/proxyPort", u"", type=unicode) proxy_user = s.value("proxy/proxyUser", u"", type=unicode) proxy_password = s.value("proxy/proxyPassword", u"", type=unicode) if proxy_enabled == "true": if proxy_type == "DefaultProxy": qgsNetMan = QgsNetworkAccessManager.instance() proxy = qgsNetMan.proxy().applicationProxy() proxy_host = proxy.hostName() proxy_port = str(proxy.port()) proxy_user = proxy.user() proxy_password = proxy.password() if proxy_type in ["DefaultProxy", "Socks5Proxy", "HttpProxy", "HttpCachingProxy"]: return ( proxy_host, proxy_port, proxy_user, proxy_password ) return ("", "", "", "")
def requestFetching(self, key, url=None, redirectionCounter=0): """ start fetching the repository given by key """ self.mRepositories[key]["state"] = 1 if not url: url = QUrl(self.mRepositories[key]["url"] + self.urlParams()) # v=str(Qgis.QGIS_VERSION_INT) # url.addQueryItem('qgis', '.'.join([str(int(s)) for s in [v[0], v[1:3]]]) ) # don't include the bugfix version! self.mRepositories[key]["QRequest"] = QNetworkRequest(url) authcfg = self.mRepositories[key]["authcfg"] if authcfg and isinstance(authcfg, str): if not QgsApplication.authManager().updateNetworkRequest( self.mRepositories[key]["QRequest"], authcfg.strip()): msg = QCoreApplication.translate( "QgsPluginInstaller", "Update of network request with authentication " "credentials FAILED for configuration '{0}'").format(authcfg) iface.pluginManagerInterface().pushMessage(msg, Qgis.Warning) self.mRepositories[key]["QRequest"] = None return self.mRepositories[key]["QRequest"].setAttribute(QNetworkRequest.User, key) self.mRepositories[key]["xmlData"] = QgsNetworkAccessManager.instance().get(self.mRepositories[key]["QRequest"]) self.mRepositories[key]["xmlData"].setProperty('reposName', key) self.mRepositories[key]["xmlData"].setProperty('redirectionCounter', redirectionCounter) self.mRepositories[key]["xmlData"].downloadProgress.connect(self.mRepositories[key]["Relay"].dataReadProgress) self.mRepositories[key]["xmlData"].finished.connect(self.xmlDownloaded)
def __init__(self, parent=None): DlgWaiting.__init__(self, parent) self.safeties = None self.updatedSafeties = None self.saved_id = None self.saved_number = None self.saved_sopralluoghi = None self.manager = QgsNetworkAccessManager.instance(); # clean listeners to avoid overlap try: self.manager.authenticationRequired.disconnect() except: pass try: self.manager.finished.disconnect() except: pass # add new listeners self.manager.authenticationRequired.connect(self.authenticationRequired) # get connection conf settings = QSettings() self.safetyUrl = settings.value("/rt_geosisma_offline/safetyUrl", "/api/v1/safety/") self.sopralluoghiUrl = settings.value("/rt_geosisma_offline/sopralluoghiUrl", "/api/v1/sopralluoghi/") self.baseApiUrl = settings.value("/rt_geosisma_offline/baseApiUrl", "http://geosisma-test.faunalia.it/") self.teamUrl = settings.value("/rt_geosisma_offline/teamUrl", "/api/v1/team/") self.requestUrl = settings.value("/rt_geosisma_offline/requestUrl", "/api/v1/request/") self.attachmentUrl = settings.value("/rt_geosisma_offline/attachmentUrl", "/api/v1/attachment/") self.staffUrl = settings.value("/rt_geosisma_offline/staffUrl", "/api/v1/staff/")
def __init__(self, config): # init superclass, needed for Threading QObject.__init__(self) if not isinstance(config, ProviderConfig): raise TypeError('Provider expected a Provider specific Config, got a {} instead'.format(type(config))) self.config = config if self.config.url is None: raise TypeError('url in config is None') elif self.config.url == '' or len(self.config.url) < 10: raise TypeError('url in config is empty or too short to be true') elif not (self.config.url.startswith('file://') or self.config.url.startswith('http://') or self.config.url.startswith('https://')): raise TypeError( 'url should start with: file://, http:// or https://, but starts with %s' % self.config.url[:8]) self.network_manager = QgsNetworkAccessManager.instance() # while this provider is not ready, keep processing Qt events!! self.ready = False # data will always be a list of something, so do 'iter(data)' if you want to iterate over the items self.data = None
def __init__(self, resourceType): super(GetScriptsAndModelsDialog, self).__init__(iface.mainWindow()) self.setupUi(self) if hasattr(self.leFilter, 'setPlaceholderText'): self.leFilter.setPlaceholderText(self.tr('Search...')) self.manager = QgsNetworkAccessManager.instance() repoUrl = ProcessingConfig.getSetting(ProcessingConfig.MODELS_SCRIPTS_REPO) self.resourceType = resourceType if self.resourceType == self.MODELS: self.folder = ModelerUtils.modelsFolders()[0] self.urlBase = '{}/models/'.format(repoUrl) self.icon = QgsApplication.getThemeIcon("/processingModel.svg") elif self.resourceType == self.SCRIPTS: self.folder = ScriptUtils.scriptsFolders()[0] self.urlBase = '{}/scripts/'.format(repoUrl) self.icon = QgsApplication.getThemeIcon("/processingScript.svg") self.lastSelectedItem = None self.updateProvider = False self.data = None self.populateTree() self.buttonBox.accepted.connect(self.okPressed) self.buttonBox.rejected.connect(self.cancelPressed) self.tree.currentItemChanged.connect(self.currentItemChanged) self.leFilter.textChanged.connect(self.fillTree)
def __init__(self, url, auth_cfg=None): self._network_manager = QgsNetworkAccessManager.instance() self._network_finished = False self._network_timeout = False self._url = url self._auth_cfg = auth_cfg self._content = None
def search(url, callback): QgsMessageLog.logMessage("URL:" + url, "Gazetteer") def requestFinished(reply): # Disconnect from the signal networkAccessManager = QgsNetworkAccessManager.instance() networkAccessManager.finished.disconnect(requestFinished) # Handle the reply if reply.error() != QNetworkReply.NoError: QgsMessageLog.logMessage("Network error #{0}: {1}".format(reply.error(), reply.errorString()), "Gazetteer") callback(u'') else: charset = 'UTF-8' try: _, params = cgi.parse_header(reply.header(QNetworkRequest.ContentTypeHeader)) charset = params['charset'] except: pass QgsMessageLog.logMessage("charset: " + charset, "Gazetteer") data = unicode(reply.readAll(), charset) reply.deleteLater() callback(data) networkAccessManager = QgsNetworkAccessManager.instance() networkAccessManager.finished.connect(requestFinished) networkAccessManager.get(QNetworkRequest(QUrl(QUrl.fromPercentEncoding(url))))
def __init__(self, server=None, projects_base=''): super(ProjectUpdater, self).__init__() self.updatethread = None self.server = server self.net = QgsNetworkAccessManager.instance() self.projects_base = projects_base self.create_worker()
def __init__(self, resourceType): super(GetScriptsAndModelsDialog, self).__init__(iface.mainWindow()) self.setupUi(self) self.manager = QgsNetworkAccessManager.instance() repoUrl = ProcessingConfig.getSetting(ProcessingConfig.MODELS_SCRIPTS_REPO) self.resourceType = resourceType if self.resourceType == self.MODELS: self.folder = ModelerUtils.modelsFolders()[0] self.urlBase = '{}/models/'.format(repoUrl) self.icon = QIcon(os.path.join(pluginPath, 'images', 'model.png')) elif self.resourceType == self.SCRIPTS: self.folder = ScriptUtils.scriptsFolders()[0] self.urlBase = '{}/scripts/'.format(repoUrl) self.icon = QIcon(os.path.join(pluginPath, 'images', 'script.png')) else: self.folder = RUtils.RScriptsFolders()[0] self.urlBase = '{}/rscripts/'.format(repoUrl) self.icon = QIcon(os.path.join(pluginPath, 'images', 'r.svg')) self.lastSelectedItem = None self.updateProvider = False self.populateTree() self.buttonBox.accepted.connect(self.okPressed) self.buttonBox.rejected.connect(self.cancelPressed) self.tree.currentItemChanged.connect(self.currentItemChanged)
def __init__(self, resourceType): super(GetScriptsAndModelsDialog, self).__init__(iface.mainWindow()) self.setupUi(self) if hasattr(self.leFilter, "setPlaceholderText"): self.leFilter.setPlaceholderText(self.tr("Search...")) self.manager = QgsNetworkAccessManager.instance() self.resourceType = resourceType if self.resourceType == self.MODELS: self.folder = ModelerUtils.modelsFolders()[0] self.urlBase = "https://raw.githubusercontent.com/qgis/QGIS-Processing/master/models/" self.icon = QIcon(os.path.join(pluginPath, "images", "model.png")) elif self.resourceType == self.SCRIPTS: self.folder = ScriptUtils.scriptsFolders()[0] self.urlBase = "https://raw.githubusercontent.com/qgis/QGIS-Processing/master/scripts/" self.icon = QIcon(os.path.join(pluginPath, "images", "script.png")) else: self.folder = RUtils.RScriptsFolders()[0] self.urlBase = "https://raw.githubusercontent.com/qgis/QGIS-Processing/master/rscripts/" self.icon = QIcon(os.path.join(pluginPath, "images", "r.svg")) self.lastSelectedItem = None self.updateProvider = False self.data = None self.populateTree() self.buttonBox.accepted.connect(self.okPressed) self.buttonBox.rejected.connect(self.cancelPressed) self.tree.currentItemChanged.connect(self.currentItemChanged) self.leFilter.textChanged.connect(self.fillTree)
def __init__(self, url, output_path, progress_dialog=None): """Constructor of the class. .. versionchanged:: 3.3 removed manager parameter. :param url: URL of file. :type url: str :param output_path: Output path. :type output_path: str :param progress_dialog: Progress dialog widget. :type progress_dialog: QWidget """ # noinspection PyArgumentList self.manager = QgsNetworkAccessManager.instance() self.url = QUrl(url) self.output_path = output_path self.progress_dialog = progress_dialog if self.progress_dialog: self.prefix_text = self.progress_dialog.labelText() self.output_file = None self.reply = None self.downloaded_file_buffer = None self.finished_flag = False
def __init__(self, parent, plugin): QDialog.__init__(self, parent) self.setupUi(self) self.plugin = plugin self.mResult = "" self.progressBar.setRange(0, 0) self.progressBar.setFormat("%p%") self.labelName.setText(plugin["name"]) self.buttonBox.clicked.connect(self.abort) url = QUrl(plugin["download_url"]) fileName = plugin["filename"] tmpDir = QDir.tempPath() tmpPath = QDir.cleanPath(tmpDir + "/" + fileName) self.file = QFile(tmpPath) self.request = QNetworkRequest(url) authcfg = repositories.all()[plugin["zip_repository"]]["authcfg"] if authcfg and isinstance(authcfg, basestring): if not QgsAuthManager.instance().updateNetworkRequest( self.request, authcfg.strip()): self.mResult = self.tr( "Update of network request with authentication " "credentials FAILED for configuration '{0}'").format(authcfg) self.request = None if self.request is not None: self.reply = QgsNetworkAccessManager.instance().get(self.request) self.reply.downloadProgress.connect(self.readProgress) self.reply.finished.connect(self.requestFinished) self.stateChanged(4)
def __init__(self, alg): super(AlgorithmDialogBase, self).__init__(iface.mainWindow()) self.setupUi(self) self.settings = QSettings() self.restoreGeometry(self.settings.value("/Processing/dialogBase", QByteArray())) self.executed = False self.mainWidget = None self.alg = alg # Rename OK button to Run self.btnRun = self.buttonBox.button(QDialogButtonBox.Ok) self.btnRun.setText(self.tr('Run')) self.btnClose = self.buttonBox.button(QDialogButtonBox.Close) self.setWindowTitle(AlgorithmClassification.getDisplayName(self.alg)) desktop = QDesktopWidget() if desktop.physicalDpiX() > 96: self.textHelp.setZoomFactor(desktop.physicalDpiX() / 96) algHelp = self.alg.shortHelp() if algHelp is None: self.textShortHelp.setVisible(False) else: self.textShortHelp.document().setDefaultStyleSheet('''.summary { margin-left: 10px; margin-right: 10px; } h2 { color: #555555; padding-bottom: 15px; } a { text-decoration: none; color: #3498db; font-weight: bold; } p { color: #666666; } b { color: #333333; } dl dd { margin-bottom: 5px; }''') self.textShortHelp.setHtml(algHelp) self.textShortHelp.setOpenLinks(False) def linkClicked(url): webbrowser.open(url.toString()) self.textShortHelp.anchorClicked.connect(linkClicked) self.textHelp.page().setNetworkAccessManager(QgsNetworkAccessManager.instance()) isText, algHelp = self.alg.help() if algHelp is not None: algHelp = algHelp if isText else QUrl(algHelp) try: if isText: self.textHelp.setHtml(algHelp) else: self.textHelp.settings().clearMemoryCaches() self.textHelp.load(algHelp) except: self.tabWidget.removeTab(2) else: self.tabWidget.removeTab(2) self.showDebug = ProcessingConfig.getSetting( ProcessingConfig.SHOW_DEBUG_IN_DIALOG)
def replyFinished(self): reply = self.sender() url = reply.request().url().toString() self.log("replyFinished: %s" % url) if not url in self.fetchedFiles: self.fetchedFiles[url] = None self.requestingUrls.remove(url) self.replies.remove(reply) isFromCache = 0 httpStatusCode = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) if reply.error() == QNetworkReply.NoError: self.fetchSuccesses += 1 if reply.attribute(QNetworkRequest.SourceIsFromCacheAttribute): self.cacheHits += 1 isFromCache = 1 elif not reply.hasRawHeader("Cache-Control"): cache = QgsNetworkAccessManager.instance().cache() if cache: metadata = cache.metaData(reply.request().url()) # self.log("Expiration date: " + metadata.expirationDate().toString().encode("utf-8")) if metadata.expirationDate().isNull(): metadata.setExpirationDate( QDateTime.currentDateTime().addSecs(self.DEFAULT_CACHE_EXPIRATION * 60 * 60) ) cache.updateMetaData(metadata) self.log( "Default expiration date has been set: %s (%d h)" % (url, self.DEFAULT_CACHE_EXPIRATION) ) if reply.isReadable(): data = reply.readAll() self.fetchedFiles[url] = data else: qDebug("http status code: " + str(httpStatusCode)) else: if self.sync and httpStatusCode == 404: self.fetchedFiles[url] = self.NOT_FOUND self.fetchErrors += 1 if self.errorStatus == self.NO_ERROR: self.errorStatus = self.UNKNOWN_ERROR self.emit(SIGNAL("replyFinished(QString, int, int)"), url, reply.error(), isFromCache) reply.deleteLater() if debug_mode: qDebug("queue: %d, requesting: %d" % (len(self.queue), len(self.requestingUrls))) if len(self.queue) + len(self.requestingUrls) == 0: # all replies have been received if self.sync: self.logT("eventLoop.quit()") self.eventLoop.quit() else: self.timer.stop() elif len(self.queue) > 0: # start fetching the next file self.fetchNext() self.log("replyFinished End: %s" % url)
def __init__(self, alg): super(AlgorithmDialogBase, self).__init__(iface.mainWindow()) self.setupUi(self) self.settings = QSettings() self.restoreGeometry(self.settings.value("/Processing/dialogBase", QByteArray())) self.executed = False self.mainWidget = None self.alg = alg # Rename OK button to Run self.btnRun = self.buttonBox.button(QDialogButtonBox.Ok) self.btnRun.setText(self.tr('Run')) self.btnClose = self.buttonBox.button(QDialogButtonBox.Close) self.setWindowTitle(self.alg.displayName()) # ~ desktop = QDesktopWidget() # ~ if desktop.physicalDpiX() > 96: # ~ self.txtHelp.setZoomFactor(desktop.physicalDpiX() / 96) algHelp = self.alg.shortHelp() if algHelp is None: self.textShortHelp.setVisible(False) else: self.textShortHelp.document().setDefaultStyleSheet('''.summary { margin-left: 10px; margin-right: 10px; } h2 { color: #555555; padding-bottom: 15px; } a { text-decoration: none; color: #3498db; font-weight: bold; } p { color: #666666; } b { color: #333333; } dl dd { margin-bottom: 5px; }''') self.textShortHelp.setHtml(algHelp) self.textShortHelp.setOpenLinks(False) def linkClicked(url): webbrowser.open(url.toString()) self.textShortHelp.anchorClicked.connect(linkClicked) isText, algHelp = self.alg.help() if algHelp is not None: algHelp = algHelp if isText else QUrl(algHelp) try: if isText: self.txtHelp.setHtml(algHelp) else: html = self.tr('<p>Downloading algorithm help... Please wait.</p>') self.txtHelp.setHtml(html) rq = QNetworkRequest(algHelp) self.reply = QgsNetworkAccessManager.instance().get(rq) self.reply.finished.connect(self.requestFinished) except Exception, e: self.tabWidget.removeTab(2)
def fetchResult(self, encoding, schema, fileLink, identifier): self.noFilesToFetch += 1 url = QUrl(fileLink) self.myHttp = QgsNetworkAccessManager.instance() self.theReply = self.myHttp.get(QNetworkRequest(url)) self.emit(SIGNAL("fetchingResult(int)"), self.noFilesToFetch) # Append encoding to 'finished' signal parameters self.encoding = encoding self.schema = schema self.theReply.finished.connect(partial(self.getResultFile, identifier, self.mimeType, encoding, schema, self.theReply))
def testProxyIsUpdated(self): """ Test that proxy is updated """ authm = QgsApplication.authManager() nam = QgsNetworkAccessManager.instance() proxy = nam.proxy() self.assertEqual(proxy.password(), '') self.assertEqual(proxy.user(), '') self.assertTrue(authm.updateNetworkProxy(proxy, self.auth_config.id())) self.assertEqual(proxy.user(), self.username) self.assertEqual(proxy.password(), self.password)
def testProxyIsUpdated(self): """ Test that proxy is updated """ authm = QgsApplication.authManager() nam = QgsNetworkAccessManager.instance() proxy = nam.proxy() self.assertEqual(proxy.password(), '') self.assertEqual(proxy.user(), '') self.assertTrue(authm.updateNetworkProxy(proxy, self.auth_config.id())) self.assertEqual(proxy.user(), self.username) self.assertEqual(proxy.password(), self.password)
def initGui(self): """Create the menu entries and toolbar icons inside the QGIS GUI.""" icon_path = os.path.join(self.plugin_dir, 'res', 'icon.png') self.mainAction = self.add_action(icon_path, text=self.tr(u'go2mapillary'), callback=self.run, checkable=True, parent=self.iface.mainWindow()) self.dlg = go2mapillaryDockWidget() self.dockwidget = QDockWidget("go2mapillary", self.iface.mainWindow()) self.dockwidget.setObjectName("go2mapillary") self.dockwidget.setWidget(self.dlg) self.dockwidget.visibilityChanged.connect( self.mlyDockwidgetvisibilityChanged) self.dlg.webView.page().setNetworkAccessManager( QgsNetworkAccessManager.instance()) self.dlg.webView.page().mainFrame().setScrollBarPolicy( Qt.Vertical, Qt.ScrollBarAlwaysOff) self.dlg.webView.page().mainFrame().setScrollBarPolicy( Qt.Horizontal, Qt.ScrollBarAlwaysOff) self.canvas.mapToolSet.connect(self.toggleViewer) self.viewer = mapillaryViewer(self) self.viewer.messageArrived.connect(self.viewerConnection) self.viewer.openFilter.connect(self.filter_images_func) #QgsExpressionContextUtils.setGlobalVariable( "mapillaryCurrentKey","noKey") QgsExpressionContextUtils.removeGlobalVariable("mapillaryCurrentKey") self.mapSelectionTool = None self.coverage = mapillary_coverage(self) self.filterDialog = mapillaryFilter(self) self.filterAction_images = QAction(QIcon(icon_path), 'filter mapillary coverage', self.iface.mainWindow()) self.filterAction_sequences = QAction(QIcon(icon_path), 'filter mapillary coverage', self.iface.mainWindow()) self.filterAction_overview = QAction(QIcon(icon_path), 'filter mapillary coverage', self.iface.mainWindow()) self.filterAction_images.triggered.connect(self.filter_images_func) self.filterAction_sequences.triggered.connect( self.filter_sequences_func) self.filterAction_overview.triggered.connect(self.filter_overview_func) self.sample_cursor = mapillary_cursor(self) self.sample_settings = mapillarySettings(self) self.sample_cursor.update_ds( self.sample_settings.settings['sample_source']) self.samples_form = mapillaryForm(self) self.iface.projectRead.connect(self.removeMapillaryLayerGroup) self.canvas.mapCanvasRefreshed.connect(self.mapRefreshed) self.enableMapillaryRender = False
def _replyFinished(self): reply = self.sender() url = reply.request().url().toString() if url not in self.fetchedFiles: self.fetchedFiles[url] = None if url in self.requestingReplies: del self.requestingReplies[url] httpStatusCode = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) if reply.error() == QNetworkReply.NoError: self._successes += 1 if reply.attribute(QNetworkRequest.SourceIsFromCacheAttribute): self._cacheHits += 1 elif not reply.hasRawHeader("Cache-Control"): cache = QgsNetworkAccessManager.instance().cache() if cache: metadata = cache.metaData(reply.request().url()) if metadata.expirationDate().isNull(): metadata.setExpirationDate(QDateTime.currentDateTime().addSecs(self.defaultCacheExpiration * 3600)) cache.updateMetaData(metadata) self.log("Default expiration date has been set: %s (%d h)" % (url, self.defaultCacheExpiration)) if reply.isReadable(): data = reply.readAll() self.fetchedFiles[url] = data else: qDebug("http status code: " + str(httpStatusCode)) else: self._errors += 1 if self.errorStatus == self.NO_ERROR: self.errorStatus = self.UNKNOWN_ERROR self.replyFinished.emit(url) reply.deleteLater() if len(self.queue) + len(self.requestingReplies) == 0: # all replies have been received if self.sync: self.logT("eventLoop.quit()") self.eventLoop.quit() else: self.timer.stop() self.allRepliesFinished.emit() elif len(self.queue) > 0: # start fetching the next file self.fetchNext()
def requestFetching(self,key): """ start fetching the repository given by key """ self.mRepositories[key]["state"] = 1 url = QUrl(self.mRepositories[key]["url"] + self.urlParams() ) #v=str(QGis.QGIS_VERSION_INT) #url.addQueryItem('qgis', '.'.join([str(int(s)) for s in [v[0], v[1:3]]]) ) # don't include the bugfix version! self.mRepositories[key]["QRequest"] = QNetworkRequest(url) self.mRepositories[key]["QRequest"].setAttribute( QNetworkRequest.User, key) self.mRepositories[key]["xmlData"] = QgsNetworkAccessManager.instance().get( self.mRepositories[key]["QRequest"] ) self.mRepositories[key]["xmlData"].setProperty( 'reposName', key) self.mRepositories[key]["xmlData"].downloadProgress.connect( self.mRepositories[key]["Relay"].dataReadProgress ) self.mRepositories[key]["xmlData"].finished.connect( self.xmlDownloaded )
def _refresh_contributors(self): self.edit_contributor_id.clear() url = SERVICE_MANAGER.get_contributor_endpoint(self.service_type, self.service_id) if not url: return self.button_refresh_contributors.setEnabled(False) request = QNetworkRequest(QUrl(url)) request.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True) reply = QgsNetworkAccessManager.instance().get(request) reply.finished.connect(lambda r=reply: self._reply_finished(r))
def fetchResult(self, encoding, schema, fileLink, identifier): self.noFilesToFetch += 1 url = QUrl(fileLink) self.myHttp = QgsNetworkAccessManager.instance() self.theReply = self.myHttp.get(QNetworkRequest(url)) self.fetchingResult.emit(self.noFilesToFetch) # Append encoding to 'finished' signal parameters self.encoding = encoding self.schema = schema self.theReply.finished.connect(partial(self.getResultFile, identifier, self.mimeType, encoding, schema, self.theReply)) self.theReply.downloadProgress.connect(lambda done, all, status="download": self.showProgressBar(done, all, status))
def requestDescribeProcess(self): """ Request process description """ self._requestExecuted = False self.doc = None self.inputs = [] self.outputs = [] url = self.requestUrl() myHttp = QgsNetworkAccessManager.instance() self._theReply = myHttp.get(QNetworkRequest(url)) self._theReply.finished.connect(self._describeProcessFinished)
def fetch_basic_mdp(self): self.require_mdp_basic_text_request = False self.is_mdp_basic_text_request = True self.message.emit(self.tr('Fetching MDPs'), Qgis.Info) self.pending_event_ids = self.macro_pending_event_ids[:1] self.macro_pending_event_ids = self.macro_pending_event_ids[1:] request = QNetworkRequest(QUrl(self.generate_url())) request.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True) reply = QgsNetworkAccessManager.instance().get(request) reply.finished.connect(lambda r=reply: self._reply_finished(r)) reply.downloadProgress.connect(self._reply_progress)
def __init__(self, target='', title='', parent=None): """Constructor.""" super(internalBrowser, self).__init__(parent) # Set up the user interface from Designer. # After setupUI you can access any designer object by doing # self.<objectname>, and you can use autoconnect slots - see # http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html # #widgets-and-dialogs-with-auto-connect self.setupUi(self) self.setWindowTitle(title) self.webView.page().setNetworkAccessManager( QgsNetworkAccessManager.instance()) self.webView.setUrl(QtCore.QUrl(target))
def __init__(self, url="http://nominatim.openstreetmap.org/search?format=json"): """ Constructor @param url:URL of Nominatim @type url:str """ self.__url = url self.network = QgsNetworkAccessManager.instance() self.data = None self.network_reply = None self.loop = None
def __init__(self, feedback=None): self.network_access_manager = QgsNetworkAccessManager.instance() self.network_access_manager.downloadProgress.connect( self.download_progress) self.network_access_manager.authenticationRequired.connect( self.authenticate) self.connection = None self.feedback = feedback self.settings = Settings() self.auth = 0 self.network_access_manager.setTimeout( self.settings.get_timeout_sec() * 1000)
def fetchResult(self, encoding, schema, fileLink, identifier, mimeType): self.noFilesToFetch += 1 url = QUrl(fileLink) self.myHttp = QgsNetworkAccessManager.instance() self.theReply = self.myHttp.get(QNetworkRequest(url)) self.fetchingResult.emit(self.noFilesToFetch) # Append encoding to 'finished' signal parameters self.encoding = encoding self.schema = schema self.theReply.finished.connect(partial(self.getResultFile, identifier, mimeType, encoding, schema, self.theReply)) self.theReply.downloadProgress.connect(lambda done, all, status="download": self.showProgressBar(done, all, status))
def fetchNext(self): if len(self.queue) == 0: return url = self.queue.pop(0) self.log("fetchNext: %s" % url) request = QNetworkRequest(QUrl(url)) request.setRawHeader("User-Agent", self.userAgent) reply = QgsNetworkAccessManager.instance().get(request) reply.finished.connect(self.replyFinishedSlot) self.requestingUrls.append(url) self.replies.append(reply) return reply
def test_AsyncNAM_local_timeout(self): """Test ANAM if it can manages operation canceled by client.""" """!!!Note!!! that finishedListener is emitted before than timeoutListener. When timeoutListener is called the httpResult has been changed to notify timout.""" # test url timeout by client timout self.checkEx = None def finishedListener(): try: httpResult = nam.httpResult() self.assertIn('Operation canceled', str(httpResult.exception)) self.assertIsInstance(httpResult.exception, RequestsException) except Exception as ex: self.checkEx = ex def timeoutListener(): try: httpResult = nam.httpResult() self.assertIn('Timeout error', str(httpResult.exception)) self.assertIsInstance(httpResult.exception, RequestsExceptionTimeout) except Exception as ex: self.checkEx = ex self.timeoutOriginal = self.settings.value(self.timeoutEntry) self.settings.setValue(self.timeoutEntry, 1000) loop = QtCore.QEventLoop() nam = NetworkAccessManager(debug=True) nam.request(self.serverUrl + '/delay/60', blocking=False) QgsNetworkAccessManager.instance().requestTimedOut.connect( timeoutListener) nam.reply.finished.connect(finishedListener) nam.reply.finished.connect(loop.exit, QtCore.Qt.QueuedConnection) loop.exec_(flags=QtCore.QEventLoop.ExcludeUserInputEvents) self.settings.setValue(self.timeoutEntry, self.timeoutOriginal) if self.checkEx: raise self.checkEx
def __init__(self, request_url, geojson=False): self.request_url = request_url self.manager = QgsNetworkAccessManager.instance() self.reply = None self.url = QUrl(self.request_url) self.req = QNetworkRequest(self.url) self.results = QByteArray() self.auth_token = get_authtoken() # Paginated data self._pagination_exhausted = False self.geojson = geojson if geojson: self.combine_new_data = self.combine_new_geojson_data
def blocking_request(request_type, url, key, payload=None, default_request=None, progress_callback=None): """This is an universal blocking request method we use in threads""" # pylint: disable=R0913 nam = QgsNetworkAccessManager.instance() if payload and not default_request: payload = QByteArray(json.dumps(payload).encode("utf-8")) if not default_request: default_request = GISCloudNetworkHandler.default_request req = QtNetwork.QNetworkRequest(default_request) req.setRawHeader(QByteArray(b'API-Key'), QByteArray(str(key).encode("utf-8"))) req.setUrl(QUrl(url)) if request_type == GISCloudNetworkHandler.POST: reply = nam.post(req, payload) elif request_type == GISCloudNetworkHandler.PUT: reply = nam.put(req, payload) elif request_type == GISCloudNetworkHandler.DELETE: reply = nam.deleteResource(req) else: reply = nam.get(req) loop = QEventLoop() if progress_callback: reply.uploadProgress.connect(progress_callback) reply.finished.connect(loop.quit) reply.error.connect(loop.quit) loop.exec_() result = {} result["status_code"] = reply.attribute( QtNetwork.QNetworkRequest.HttpStatusCodeAttribute) try: result["response"] = json.loads( reply.readAll().data().decode("utf-8")) except Exception: result["response"] = None location = reply.rawHeader(QByteArray(b'Location')) result["location"] = \ location.data().decode("utf-8") if location else None return result
def _download_qgis(packageUrl, handle): from qgis.core import QgsNetworkAccessManager request = QNetworkRequest(QUrl(packageUrl)) reply = QgsNetworkAccessManager.instance().get(request) evloop = QEventLoop() reply.finished.connect(evloop.quit) evloop.exec_(QEventLoop.ExcludeUserInputEvents) content_type = reply.rawHeader('Content-Type') if bytearray(content_type) == bytearray('text/plain; charset=utf-8'): handle.write(bytearray(reply.readAll())) else: ret_code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) raise Exception('Failed to download %s\n\nThe HTTP status code was %d.\n\nPlease check your network settings' % (packageUrl, ret_code))
def __init__(self, url=None): """Constructor.""" QObject.__init__(self) self._url = None self._metadata = None self._git_host = None self._git_owner = None self._git_repository = None self._network_manager = QgsNetworkAccessManager.instance() self._reply = None self._progress_dialog = None # Call proper setters here self.url = url
def __init__(self, iface): '''initialize the GUI control''' QObject.__init__(self) self.iface = iface self.dock = DockWidget() self.connectdlg = ConnectDialog() self.iface.addDockWidget(Qt.RightDockWidgetArea, self.dock) self.dock.newConnectionButton.clicked.connect( lambda: self.showDialog(self.connectdlg)) self.connectdlg.okButton.clicked.connect(self.setupNewConnection) self.topitem = EditorTopItem() self.connections = [] self.dock.treeWidget.addTopLevelItem(self.topitem) self.dock.treeWidget.setContextMenuPolicy(Qt.CustomContextMenu) self.dock.treeWidget.customContextMenuRequested.connect( self.on_context_menu) self.dock.treeWidget.itemDoubleClicked.connect( self.on_tree_item_double_clicked) self.timer = QTimer() ''' WORKAROUND: When performing requests with self.http, it will call the QgsNetworkAccessManager.instance(). For some reason QgsNetworkAccessManager.instance() is connected with the QtCore SIGNAL 'authenticationRequired' (inherited from QNetworkAccessManager) to a method where a dialog in QGIS pops up asking for the users credentials (when working with Basic Auth). We disable the signal here as the case of wrong identifacation credentials is treated separately in def: checkConnection(self) ''' try: QgsNetworkAccessManager.instance( ).authenticationRequired.disconnect() except: pass
def sendVote(self, plugin_id, vote): """ send vote via the RPC """ if not plugin_id or not vote: return False url = "http://plugins.qgis.org/plugins/RPC2/" params = { "id": "djangorpc", "method": "plugin.vote", "params": [str(plugin_id), str(vote)] } req = QNetworkRequest(QUrl(url)) req.setAttribute( QNetworkRequest.Attribute( QgsNetworkRequestParameters.AttributeInitiatorClass), "QgsPluginInstaller") req.setAttribute( QNetworkRequest.Attribute( QgsNetworkRequestParameters.AttributeInitiatorRequestId), "sendVote") req.setRawHeader(b"Content-Type", b"application/json") QgsNetworkAccessManager.instance().post( req, bytes(json.dumps(params), "utf-8")) return True
def fetch_data(self): """ Starts the fetch request """ if self.is_first_request: self.started.emit() self.is_first_request = False request = QNetworkRequest(QUrl(self.generate_url())) request.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True) reply = QgsNetworkAccessManager.instance().get(request) reply.finished.connect(lambda r=reply: self._reply_finished(r)) reply.downloadProgress.connect(self._reply_progress)
def test_proxy(client) -> None: """ Test that requests goes throught proxy """ settings = QgsSettings() assert settings.value('proxy/proxyEnabled') == 'true' assert settings.value('proxy/proxyHost') == 'proxy.whatever.com' assert settings.value('proxy/proxyType') == 'HttpProxy' nam = QgsNetworkAccessManager.instance() nam.setupDefaultProxyAndCache() default_proxy = nam.fallbackProxy() assert default_proxy.hostName() == 'proxy.whatever.com' assert default_proxy.type() == QNetworkProxy.HttpProxy
def geocode_addresses(self, address_list): """Geocode a list of addresses using GWS.""" req = QNetworkRequest(self.gws_url) req.setRawHeader(QByteArray(b"Content-Type"), QByteArray(b"application/json")) nam = QgsNetworkAccessManager.instance() data = QByteArray( json.dumps({ "cmd": "alkisgeocoderDecode", "params": { "crs": "EPSG:25832", "adressen": address_list } }).encode()) return nam.blockingPost(req, data, self.authcfg)
def test_post_multipart_action(self): """Test multipart""" self.body = None def _req_logger(self, params): self.body = bytes(params.content()) QgsNetworkAccessManager.instance( ).requestAboutToBeCreated[QgsNetworkRequestParameters].connect( partial(_req_logger, self)) temp_dir = QTemporaryDir() temp_path = temp_dir.path() temp_file = os.path.join(temp_path, 'multipart.txt') action = QgsAction( QgsAction.SubmitUrlMultipart, 'url_encoded', "http://fake_qgis_http_endpoint" + temp_file + r"?[% url_encode(map('a&+b', 'a and plus b', 'a=b', 'a equals b')) %]" ) ctx = QgsExpressionContext() action.run(ctx) while not self.body: QgsApplication.instance().processEvents() self.assertEqual( re.sub(r'\.oOo\.[^\r]*', '.oOo.UUID', self.body.decode('utf8')), '\r\n'.join([ '--boundary_.oOo.UUID', 'Content-Disposition: form-data; name="a&+b"', '', 'a and plus b', '--boundary_.oOo.UUID', 'Content-Disposition: form-data; name="a=b"', '', 'a equals b', '--boundary_.oOo.UUID', '' ]))
def download_file(url, filename, on_progress=None, on_finished=None, on_error=None, on_success=None): """ Will download the file from url to a local filename. The method will only return once it's finished. While downloading it will repeatedly report progress by calling on_progress with two parameters bytes_received and bytes_total. If an error occurs, it raises a NetworkError exception. It will return the filename if everything was ok. """ network_access_manager = QgsNetworkAccessManager.instance() req = QNetworkRequest(QUrl(url)) reply = network_access_manager.get(req) def on_download_progress(bytes_received, bytes_total): on_progress(bytes_received, bytes_total) def finished(): file = QFile(filename) file.open(QIODevice.WriteOnly) file.write(reply.readAll()) file.close() if reply.error() and on_error: on_error(reply.error(), reply.errorString()) elif not reply.error() and on_success: on_success() if on_finished: on_finished() reply.deleteLater() if on_progress: reply.downloadProgress.connect(on_download_progress) reply.finished.connect(finished) if not on_finished and not on_success: loop = QEventLoop() reply.finished.connect(loop.quit) loop.exec_() if reply.error(): raise NetworkError(reply.error(), reply.errorString()) else: return filename
def _fetch_fields(self): """ Triggers fetching fields """ if not self.service_uri: return self.label_fields.setText(self.tr('Fetching fields...')) # is_wms = 'wms' in self.service_uri # seems this must ALWAYS be WFS! url = self.service_uri + 'version=1.3.0&request=describeFeatureType&outputFormat=application/json&service={}'.format( 'WFS') request = QNetworkRequest(QUrl(url)) request.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True) reply = QgsNetworkAccessManager.instance().get(request) def response_finished(_reply: QNetworkReply): """ Triggered when the response is finished """ if sip.isdeleted(self.label_fields): # pylint:disable=no-member return self.label_fields.setText(self.tr('List of fields')) res = json.load(BytesIO(_reply.readAll().data())) self.layers_def = {} for _type in res['featureTypes']: type_name = _type['typeName'] if CqlBuilderWidget._clean_layer_name( type_name) not in self.layer_names: continue self.layer_combo.addItem(type_name) layer_fields = [] for prop in _type['properties']: layer_fields.append({ 'name': prop['name'], 'type': prop['localType'] }) self.layers_def[type_name] = layer_fields self._layer_combo_changed() reply.finished.connect(partial(response_finished, reply))
def __init__(self, parent, plugin): self.plugin = plugin QDockWidget.__init__(self, parent) self.setupUi(self) self.btnApply.setIcon(QIcon(":plugins/nominatim/arrow_green.png")) self.btnMask.setIcon(QIcon(":plugins/nominatim/add_mask.png")) self.btnLayer.setIcon(QIcon(":plugins/nominatim/add_layer.png")) self.tableResult.installEventFilter(self) # cf. eventFilter method self.tableResult.cellDoubleClicked.connect(self.onChoose) self.tableResult.cellEntered.connect(self.cellEntered) self.editSearch.returnPressed.connect(self.onReturnPressed) self.btnSearch.clicked.connect(self.onReturnPressed) self.btnApply.clicked.connect(self.onApply) self.btnHelp.clicked.connect(self.plugin.do_help) self.btnLocalize.clicked.connect(self.doLocalize) self.btnMask.clicked.connect(self.onMask) self.btnLayer.clicked.connect(self.onLayer) self.MultiPolygonLayerId = None self.LineLayerId = None self.PointLayerId = None try: self.cbExtent.setChecked(self.plugin.limitSearchToExtent) except: self.cbExtent.setChecked(self.plugin.limitSearchToExtent) self.currentExtent = self.plugin.canvas.extent() self.tableResult.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents) try: self.editSearch.setText(self.plugin.lastSearch) except: pass try: if self.plugin.localiseOnStartup: self.doLocalize() except Exception as e: for m in e.args: QgsMessageLog.logMessage(m, 'Extensions') pass self.nominatim_networkAccessManager = QgsNetworkAccessManager.instance()
def requestCapabilities(self): """ Request server capabilities """ self.doc = None url = QUrl() if '?' in self.baseUrl: myRequest = "&Request=GetCapabilities&identifier=&Service=WPS&Version=" + self.version else: myRequest = "?Request=GetCapabilities&identifier=&Service=WPS&Version=" + self.version url.setUrl(self.baseUrl + myRequest) myHttp = QgsNetworkAccessManager.instance() self._theReply = myHttp.get(QNetworkRequest(url)) self._theReply.finished.connect(self._capabilitiesRequestFinished)
def __init__(self, iface): """Constructor. :param iface: An interface instance that will be passed to this class which provides the hook by which you can manipulate the QGIS application at run time. :type iface: QgsInterface """ # Save reference to the QGIS interface self.iface = iface # initialize plugin directory self.plugin_dir = os.path.dirname(__file__) # initialize locale locale = QSettings().value("locale/userLocale")[0:2] locale_path = os.path.join(self.plugin_dir, "i18n", "ApiWithQt_{}.qm".format(locale)) if os.path.exists(locale_path): self.translator = QTranslator() self.translator.load(locale_path) if qVersion() > "4.3.3": QCoreApplication.installTranslator(self.translator) # Declare instance attributes self.actions = [] self.menu = self.tr("&ApiWithQt") # Check if plugin was started the first time in current QGIS session # Must be set in initGui() to survive plugin reloads self.first_start = None # additional initialization lines # getting creds self.utils = IsogeoUtils() self.app_creds = self.utils.credentials_loader( "C:\\Users\\Adminstrateur\\AppData\\Roaming\\QGIS\\QGIS3\\profiles\\default\\python\\plugins\\api_with_qt\\client_secrets.json" ) self.app_id = self.app_creds.get("client_id") self.app_secrets = self.app_creds.get("client_secret") # prepare connection self.naMngr = QgsNetworkAccessManager.instance() self.token_url = "https://id.api.isogeo.com/oauth/token" self.request_url = ( "https://v1.api.isogeo.com/resources/search?_limit=0&_offset=0") self.token = ""
def __init__(self, viewport): super(mapillaryViewer, self).__init__() self.viewport = viewport self.viewport.statusBarMessage.connect(self.getJSONmessage) WS = self.viewport.settings() WS.setAttribute(QWebSettings.JavascriptEnabled,True) WS.setAttribute(QWebSettings.DeveloperExtrasEnabled,True) WS.setAttribute(QWebSettings.JavascriptCanAccessClipboard,True) WS.setAttribute(QWebSettings.PrintElementBackgrounds,True) WS.setAttribute(QWebSettings.OfflineStorageDatabaseEnabled,True) WS.setAttribute(QWebSettings.LocalStorageEnabled,True) WS.setAttribute(QWebSettings.PluginsEnabled,True) WS.setAttribute(QWebSettings.WebGLEnabled,True) self.viewport.page().setNetworkAccessManager(QgsNetworkAccessManager.instance()) s = QSettings() #getting proxy from qgis options settings 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", "" ) print (proxyEnabled+"; "+proxyType+"; "+proxyHost+"; " + proxyPort+"; " + proxyUser+"; " +proxyPassword) if proxyEnabled == "true": # test if there are proxy settings proxy = QNetworkProxy() if proxyType == "DefaultProxy": proxy.setType(QNetworkProxy.DefaultProxy) elif proxyType == "Socks5Proxy": proxy.setType(QNetworkProxy.Socks5Proxy) elif proxyType == "HttpProxy": proxy.setType(QNetworkProxy.HttpProxy) elif proxyType == "HttpCachingProxy": proxy.setType(QNetworkProxy.HttpCachingProxy) elif proxyType == "FtpCachingProxy": proxy.setType(QNetworkProxy.FtpCachingProxy) proxy.setHostName(proxyHost) proxy.setPort(int(proxyPort)) proxy.setUser(proxyUser) proxy.setPassword(proxyPassword) #QNetworkProxy.setApplicationProxy(proxy) #self.page = os.path.join(os.path.dirname(__file__),'res','browser.html') self.page = os.path.join('https://enricofer.github.io/go2mapillary/res/browser.html') self.openLocation('') self.enabled = True print (self.page)
def testProxyIsUpdatedByUserSettings(self): """ Test that proxy is updated """ nam = QgsNetworkAccessManager.instance() nam.setupDefaultProxyAndCache() proxy = nam.proxy() self.assertEqual(proxy.password(), '') self.assertEqual(proxy.user(), '') settings = QgsSettings() settings.setValue("proxy/authcfg", self.auth_config.id()) settings.setValue("proxy/proxyEnabled", True) del(settings) nam.setupDefaultProxyAndCache() proxy = nam.fallbackProxy() self.assertEqual(proxy.password(), self.password) self.assertEqual(proxy.user(), self.username)
def requestDownloading(self): self.request = QNetworkRequest(self.url) authcfg = repositories.all()[self.plugin["zip_repository"]]["authcfg"] if authcfg and isinstance(authcfg, str): if not QgsApplication.authManager().updateNetworkRequest( self.request, authcfg.strip()): self.mResult = self.tr( "Update of network request with authentication " "credentials FAILED for configuration '{0}'").format(authcfg) self.request = None if self.request is not None: self.reply = QgsNetworkAccessManager.instance().get(self.request) self.reply.downloadProgress.connect(self.readProgress) self.reply.finished.connect(self.requestFinished) self.stateChanged(4)