Beispiel #1
0
    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
Beispiel #3
0
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()
Beispiel #4
0
    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
Beispiel #5
0
    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
Beispiel #6
0
 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 __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/")
Beispiel #8
0
 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()
Beispiel #9
0
    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, 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 __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)
Beispiel #12
0
    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 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))))
Beispiel #14
0
    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)
Beispiel #16
0
    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
Beispiel #17
0
    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 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) )
Beispiel #19
0
    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, 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 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 ("", "", "", "")
Beispiel #22
0
    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)
Beispiel #23
0
    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))
Beispiel #26
0
 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 _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()
Beispiel #28
0
  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 )
Beispiel #29
0
    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 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 _refresh_contributors(self):
        """
        Refreshes the list of contributors from the service
        """
        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))
Beispiel #32
0
 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)
Beispiel #33
0
    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)
Beispiel #34
0
    def json_reply_finished(self):
        error = self.reply.error()

        if error == QNetworkReply.NoError:
            redirect = self.reply.attribute(
                QNetworkRequest.RedirectionTargetAttribute)
            if redirect is not None and redirect != self.reply.url():
                url = self.reply.url()
                if redirect.isRelative():
                    url = self.reply.url().resolved(redirect)

                log.debug(f'Redirected to {url.toString()}')
                self.reply.deleteLater()
                self.reply = None
                # noinspection PyArgumentList
                self.reply = QgsNetworkAccessManager.instance().get(
                    QNetworkRequest(url))
                self.reply.finished.connect(self.json_reply_finished)
                return

            status = self.reply.attribute(
                QNetworkRequest.HttpStatusCodeAttribute)
            msg = self.reply.attribute(
                QNetworkRequest.HttpReasonPhraseAttribute)
            log.debug(f'Request finished: {status} - {msg}')
            try:
                data = bytes(self.reply.readAll())
                self.json = json.loads(data)
            except Exception as e:
                log.debug(str(e))
            # noinspection PyUnresolvedReferences
            self.finished.emit()
        else:
            # report any errors except for the one we have caused
            # by cancelling the request
            if error != QNetworkReply.OperationCanceledError:
                msg = f'Network request failed: {self.reply.errorString()}'
                log.debug(msg)
                # noinspection PyUnresolvedReferences
                self.errored.emit(msg)
            else:
                # noinspection PyUnresolvedReferences
                self.aborted.emit()

            self.reply.deleteLater()
            self.reply = None
Beispiel #35
0
    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))
Beispiel #36
0
 def __init__(self, target, parent = None):
     super(internalBrowser, self).__init__(parent)
     self.setupUi(self)
     self.webView.page().setNetworkAccessManager(QgsNetworkAccessManager.instance())
     if target[0:4] == 'http':
         self.setWindowTitle('Help')
         self.webView.setUrl(QUrl(target))
     else:
         self.setWindowTitle('Auth')
         self.webView.setHtml(target)
         self.timer = QTimer()
         self.timer.setInterval(500)
         self.timer.timeout.connect(self.codeProbe)
         self.timer.start()
         self.auth_code = None
         self.show()
         self.raise_()
Beispiel #37
0
    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))

        self.txtHelp.page().setNetworkAccessManager(QgsNetworkAccessManager.instance())

        # load algorithm help if available
        isText, algHelp = self.alg.help()
        if algHelp is not None:
            algHelp = algHelp if isText else QUrl(algHelp)
        else:
            algHelp = self.tr('<h2>Sorry, no help is available for this '
                              'algorithm.</h2>')
        try:
            if isText:
                self.txtHelp.setHtml(algHelp)
            else:
                self.txtHelp.settings().clearMemoryCaches()
                self.tabWidget.setTabText(2, self.tr("Help (loading...)"))
                self.tabWidget.setTabEnabled(2, False)
                self.txtHelp.loadFinished.connect(self.loadFinished)
                self.tabWidget.currentChanged.connect(self.loadHelp)
                self.txtHelp.load(algHelp)
                self.algHelp = algHelp
        except:
            self.txtHelp.setHtml(
                self.tr('<h2>Could not open help file :-( </h2>'))

        self.showDebug = ProcessingConfig.getSetting(
            ProcessingConfig.SHOW_DEBUG_IN_DIALOG)
Beispiel #38
0
    def fetchNext(self):
        if len(self.queue) == 0:
            return
        url = self.queue.pop(0)
        self.log("fetchNext: %s" % url)

        # create request
        request = QNetworkRequest(QUrl(url))
        if self.userAgent:
            request.setRawHeader(
                "User-Agent", self.userAgent
            )  # will be overwritten in QgsNetworkAccessManager::createRequest() since 2.2

        # send request
        reply = QgsNetworkAccessManager.instance().get(request)
        reply.finished.connect(self._replyFinished)
        self.requestingReplies[url] = reply
        return reply
Beispiel #39
0
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:
        msg = 'Failed to download %s\n\nPlease check your QGIS network settings and authentication db' % (
            packageUrl)
        ret_code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
        if ret_code:
            msg += '\n\nThe HTTP status code was %d.' % (ret_code)
        raise Exception(msg)
Beispiel #40
0
def downloadBinPackage(packageUrl, destinationFileName):
    request = QNetworkRequest(QUrl(packageUrl))
    request.setRawHeader('Accept-Encoding', 'gzip,deflate')

    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('application/zip'):
        if os.path.isfile(destinationFileName):
            os.unlink(destinationFileName)

        destinationFile = open(destinationFileName, 'wb')
        destinationFile.write(bytearray(reply.readAll()))
        destinationFile.close()
    else:
        ret_code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
        raise IOError("{} {}".format(ret_code, packageUrl))
Beispiel #41
0
    def to_ili2db_args(self):

        # Valid ili file, don't pass --modeldir (it can cause ili2db errors)
        with_modeldir = not self.ilifile

        args = self.base_configuration.to_ili2db_args(with_modeldir=with_modeldir)

        proxy = QgsNetworkAccessManager.instance().fallbackProxy()
        if proxy.type() == QNetworkProxy.HttpProxy:
            args += ["--proxy", proxy.hostName()]
            args += ["--proxyPort", str(proxy.port())]

        if self.ilimodels:
            args += ['--models', self.ilimodels]

        if self.tomlfile:
            args += ["--iliMetaAttrs", self.tomlfile]

        return args
Beispiel #42
0
    def __init__(self, parentInstance):
        super(mapillaryViewer, self).__init__()
        self.parentInstance = parentInstance
        self.viewport = parentInstance.dlg.webView
        #self.viewport.statusBarMessage.connect(self.getJSONmessage)
        self.viewport.page().mainFrame().javaScriptWindowObjectCleared.connect(
            self.registerJS)
        self.locationKey = None
        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())
        self.mly_api = mapillaryApi()
        self.page = os.path.join(os.path.dirname(__file__), 'res',
                                 'browser.html')
        self.openLocation('')
        self.enabled = True

        proxy_conf = getProxySettings()
        if proxy_conf:
            proxy = QNetworkProxy()
            if proxy_conf['type'] == "DefaultProxy":
                proxy.setType(QNetworkProxy.DefaultProxy)
            elif proxy_conf['type'] == "Socks5Proxy":
                proxy.setType(QNetworkProxy.Socks5Proxy)
            elif proxy_conf['type'] == "HttpProxy":
                proxy.setType(QNetworkProxy.HttpProxy)
            elif proxy_conf['type'] == "HttpCachingProxy":
                proxy.setType(QNetworkProxy.HttpCachingProxy)
            elif proxy_conf['type'] == "FtpCachingProxy":
                proxy.setType(QNetworkProxy.FtpCachingProxy)
            proxy.setHostName(proxy_conf['host'])
            proxy.setPort(int(proxy_conf['port']))
            proxy.setUser(proxy_conf['user'])
            proxy.setPassword(proxy_conf['password'])
            QNetworkProxy.setApplicationProxy(proxy)
def _sync_get(url):
    global __network_manager
    if __network_manager is None:
        __network_manager = QNetworkAccessManager()
        __network_manager.setProxy(QgsNetworkAccessManager.instance().proxy())
    pause = QEventLoop()
    req = QNetworkRequest(url)
    req.setRawHeader(b"Accept", b"application/xml")
    req.setRawHeader(b"Accept-Language", b"fr")
    reply = __network_manager.get(req)
    reply.finished.connect(pause.quit)
    is_ok = [True]

    def onError(self):
        is_ok[0] = False
        pause.quit()

    reply.error.connect(onError)
    pause.exec_()
    return reply, is_ok[0]
Beispiel #44
0
    def requestDescribeProcess(self):
        """
        Request process description
        """
        self._requestExecuted = False
        self.doc = None
        self.inputs = []
        self.outputs = []

        url = self.requestUrl()
        myHttp = QgsNetworkAccessManager.instance()
        request = QNetworkRequest(url)

        # add cookies in header
        serverCookie = WpsServerCookie(url)
        if serverCookie.checkServerCookies():
            request.setRawHeader("Cookie", serverCookie.getServerCookies())

        self._theReply = myHttp.get(request)
        self._theReply.finished.connect(self._describeProcessFinished)
Beispiel #45
0
 def run(self):
     """
     Executes the custom plugin functionality.
     This method is called by the previously defined QAction object (callback), 
     which went into the toolbar icon and the menu entry.
     """
     if self.dockwidget is None:
         self.dockwidget = DockCbers4aDownloader()
         self.iface.addDockWidget(Qt.RightDockWidgetArea, self.dockwidget)
         self.dockwidget.visibilityChanged.connect(self.visibility_changed)
         self.init()
         self.dockwidget.show()
         webPage = self.dockwidget.webView.page()
         webPage.setNetworkAccessManager(QgsNetworkAccessManager.instance())
     else:
         if self.dockwidget.isVisible():
             self.dockwidget.footprint.setChecked(False)
             self.footprint.hide()
             self.dockwidget.hide()
         else:
             self.dockwidget.show()
Beispiel #46
0
    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)
def _post_data(url: str,
               data_: typing.Dict,
               network_manager: QgsNetworkAccessManager,
               auth_config: str,
               feedback: typing.Optional[QgsFeedback] = None):
    request = QNetworkRequest(QUrl(url))
    request.setHeader(QNetworkRequest.ContentTypeHeader, 'application/json')
    reply = network_manager.blockingPost(request,
                                         json.dumps(data_).encode('utf-8'),
                                         auth_config,
                                         True,
                                         feedback=feedback)
    status_code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
    raw_string_contents = bytes(reply.content()).decode('utf-8')
    if status_code == 201:
        result = json.loads(raw_string_contents)
    else:
        raise QgsProcessingException(f'POST request failed. '
                                     f'status_code: {status_code} - '
                                     f'error_string: {reply.errorString()} - '
                                     f'reply_contents: {raw_string_contents}')
    return result
Beispiel #48
0
    def loadModel(self):
        imd = None
        try:
            loader = ModelLoader(self.ui.mDataLineEdit.text())
            models = loader.detect_models()
            model_names = map(lambda m: m.name, models)
            self._log_output("Looking up models: " + ', '.join(model_names))
            ili = loader.gen_lookup_ili()
            qDebug(ili)
            wpsreq = self._create_wps_request(ili)
            url = self.ui.mIlisMetaUrlLineEdit.text()
            req = QNetworkRequest(QUrl(url))
            req.setHeader(QNetworkRequest.ContentTypeHeader, 'application/xml')
            reply = QgsNetworkAccessManager.instance().post(req, wpsreq)

            # Wait for reply or timeout
            loop = QEventLoop()
            reply.finished.connect(loop.quit)
            QTimer.singleShot(15000, reply.abort)
            loop.exec_()

            if reply.isFinished() and reply.error() == QNetworkReply.NoError:
                result = reply.readAll()
                imd = self._parse_wps_response(result)
        except:
            qDebug("Exception during IlisModel download")
        if imd is None:
            self._show_log_window()
            QgsApplication.messageLog().logMessage(
                "Couldn't download Ilismeta model", "Interlis",
                Qgis.MessageLevel(1))
            self.ui.mModelLineEdit.setText("")
        else:
            fh, imdfn = tempfile.mkstemp(suffix='.imd')
            os.close(fh)
            with codecs.open(imdfn, "w", encoding='utf-8') as file:
                file.write(imd)
            self.ui.mModelLineEdit.setText(imdfn)
 def processAlgorithm(self, parameters, context, feedback):
     raw_report = self.parameterAsString(parameters,
                                         REPORT_HANDLER_INPUT_NAME, context)
     report = json.loads(raw_report)
     auth_config = parse_as_expression(
         self.parameterAsExpression(parameters, self.INPUT_AUTH_CONFIG,
                                    context))
     base_url = parse_as_expression(
         self.parameterAsExpression(parameters,
                                    self.INPUT_DOMINODE_BASE_URL, context))
     if not base_url:
         raise QgsProcessingException(f'Invalid base_url: {base_url}')
     else:
         base_url = base_url if base_url.endswith('/') else f'{base_url}/'
     feedback.pushInfo(f'report: {report}')
     feedback.pushInfo(f'auth_config: {auth_config}')
     feedback.pushInfo(f'base_url: {base_url}')
     network_manager = QgsNetworkAccessManager.instance()
     resource = get_resource(report['dataset'], base_url, network_manager,
                             feedback)
     if resource is None:
         resource = post_resource(report['dataset'],
                                  report['dataset_type'],
                                  report['artifact_type'],
                                  base_url,
                                  network_manager=network_manager,
                                  auth_config=auth_config,
                                  feedback=feedback)
     feedback.pushInfo(f'resource: {resource}')
     validation_report = post_validation_report(report, base_url,
                                                network_manager,
                                                auth_config, feedback)
     feedback.pushInfo(f'validation_report: {validation_report}')
     return {
         self.OUTPUT_RESULT: True,
         self.OUTPUT_DOMINODE_RESOURCE_URL: resource['url'],
         self.OUTPUT_VALIDATION_REPORT_URL: validation_report['url'],
     }
    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()
        request = QNetworkRequest(url)

        # add cookies in header
        serverCookie = WpsServerCookie(url)
        if serverCookie.checkServerCookies():
            request.setRawHeader("Cookie", serverCookie.getServerCookies())

        self._theReply = myHttp.get(request)
        self._theReply.finished.connect(self._capabilitiesRequestFinished)
Beispiel #51
0
    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)
        self.reply = QgsNetworkAccessManager.instance().get(self.request)
        self.reply.downloadProgress.connect(self.readProgress)
        self.reply.finished.connect(self.requestFinished)

        self.stateChanged(4)
Beispiel #52
0
    def _sendRequest(self, url, params, headers={}):
        if self.asynchonous:

            if self.reply is not None:
                self.reply.finished.disconnect(self.replyFinished)
                self.reply.abort()
                self.reply = None

            url = QUrl(url)
            for key, value in params.iteritems():
                url.addQueryItem(key, value)
            QgsLogger.debug('Request: {}'.format(url.toEncoded()))
            request = QNetworkRequest(url)
            for key, value in headers.iteritems():
                request.setRawHeader(key, value)
            self.reply = QgsNetworkAccessManager.instance().get(request)
            self.reply.finished.connect(self.replyFinished)

        else:
            response = urllib2.urlopen(self.url + '?' +
                                       urllib.urlencode(params))
            data = json.load(response)
            self.loadData(data)
Beispiel #53
0
    def __init__(self):
        # inheritance
        super().__init__()

        self.tr = object
        # API client parameters :
        # creds
        self.app_id = str
        self.app_secret = str
        # URL
        self.api_url_base = str
        self.api_url_auth = str
        self.api_url_token = str
        self.api_url_redirect = str

        # Requesting operation attributes
        # manage requesting
        self.loopCount = 0
        # make request
        self.qnam = QgsNetworkAccessManager.instance()
        self.token = str
        self.currentUrl = str
        self.request = object
def get_resource(
    name: str,
    dominode_base_url: str,
    network_manager: QgsNetworkAccessManager,
    feedback: typing.Optional[QgsFeedback] = None,
) -> typing.Optional[typing.Dict]:
    url_query = QUrlQuery()
    url_query.addQueryItem('name', name)
    url = QUrl(
        f'{dominode_base_url}/dominode-validation/api/dominode-resources/')
    url.setQuery(url_query)
    request = QNetworkRequest(url)
    request.setHeader(QNetworkRequest.ContentTypeHeader, 'application/json')
    reply = network_manager.blockingGet(request, '', True, feedback=feedback)
    status_code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
    result = None
    if status_code == 200:
        raw_string_contents = bytes(reply.content()).decode('utf-8')
        contents = json.loads(raw_string_contents)
        exists = contents.get('count', 0) > 0
        if exists:
            result = contents['results'][0]
    return result
Beispiel #55
0
def set_proxy_configuration(logger: logging.Logger) -> None:
    """ Display proxy configuration
    """
    from qgis.PyQt.QtNetwork import QNetworkProxy
    from qgis.core import QgsNetworkAccessManager

    nam = QgsNetworkAccessManager.instance()
    nam.setupDefaultProxyAndCache()

    proxy = nam.fallbackProxy()
    proxy_type = proxy.type()
    if proxy_type == QNetworkProxy.NoProxy:
        return

    logger.info(
        "Proxy configuration enabled: %s:%s, type: %s", proxy.hostName(),
        proxy.port(), {
            QNetworkProxy.DefaultProxy: 'DefaultProxy',
            QNetworkProxy.Socks5Proxy: 'Socks5Proxy',
            QNetworkProxy.HttpProxy: 'HttpProxy',
            QNetworkProxy.HttpCachingProxy: 'HttpCachingProxy',
            QNetworkProxy.HttpCachingProxy: 'FtpCachingProxy',
        }.get(proxy_type, 'Undetermined'))  # noqa E124
Beispiel #56
0
    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)
        self.mRepositories[key]["QRequest"].setAttribute(
            QNetworkRequest.Attribute(
                QgsNetworkRequestParameters.AttributeInitiatorClass), "Relay")
        self.mRepositories[key]["QRequest"].setAttribute(
            QNetworkRequest.FollowRedirectsAttribute, True)
        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]["xmlDataFinished"] = self.mRepositories[key][
            "xmlData"].finished.connect(self.xmlDownloaded)
def _sync_get(url):
    global __network_manager
    if __network_manager is None:
        __network_manager = QNetworkAccessManager()
        __network_manager.setProxy(QgsNetworkAccessManager.instance().proxy())
    pause = QEventLoop()
    req = QNetworkRequest(url)
    req.setRawHeader(b"Accept", b"application/xml")
    req.setRawHeader(b"Accept-Language",
                     bytes(settings.value("default_language", "fr"), "utf8"))
    req.setRawHeader(
        b"User-Agent",
        bytes(settings.value("http_user_agent", plugin_name()), "utf8"))
    reply = __network_manager.get(req)
    reply.finished.connect(pause.quit)
    is_ok = [True]

    def onError(self):
        is_ok[0] = False
        pause.quit()

    reply.error.connect(onError)
    pause.exec_()
    return reply, is_ok[0]
    def __init__(self, layout):
        super().__init__(layout)
        self.setCacheMode(QGraphicsItem.NoCache)
        self.plot_settings = PlotSettings()
        self.web_page = LoggingWebPage(self)
        self.web_page.setNetworkAccessManager(
            QgsNetworkAccessManager.instance())

        # This makes the background transparent. (copied from QgsLayoutItemLabel)
        palette = self.web_page.palette()
        palette.setBrush(QPalette.Base, Qt.transparent)
        self.web_page.setPalette(palette)
        self.web_page.mainFrame().setZoomFactor(10.0)
        self.web_page.mainFrame().setScrollBarPolicy(Qt.Horizontal,
                                                     Qt.ScrollBarAlwaysOff)
        self.web_page.mainFrame().setScrollBarPolicy(Qt.Vertical,
                                                     Qt.ScrollBarAlwaysOff)

        self.web_page.loadFinished.connect(self.loading_html_finished)
        self.html_loaded = False
        self.html_units_to_layout_units = self.calculate_html_units_to_layout_units(
        )

        self.sizePositionChanged.connect(self.refresh)
Beispiel #59
0
    def fetch_missing(self):
        # pop first missing origin from front of queue and fetch it
        self.message.emit(
            self.tr(
                'Returned XML was incomplete. {} missing origins left to fetch'
            ).format(len(self.missing_origins)), Qgis.Warning)

        remaining = list(self.missing_origins)
        next_origin = remaining[0]
        self.missing_origins = set(remaining[1:])

        # change smi: prefix to http://
        parts = next_origin.split(":")
        next_origin = 'http://' + ':'.join(parts[1:])

        self.is_missing_origin_request = True

        request = QNetworkRequest(QUrl(next_origin))
        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, url="http://overpass-api.de/api/", output=None):
        """
        Constructor

        @param url:URL of OverPass
        @type url:str

        @param output:Output desired (XML or JSON)
        @type output:str
        """

        if not url:
            url = "http://overpass-api.de/api/"

        self.__url = url
        self.result_path = None

        if output not in (None, "json", "xml"):
            raise OutPutFormatException

        self.__output = output
        self.network = QgsNetworkAccessManager.instance()
        self.network_reply = None
        self.loop = None