def suggestionsUrl(self, searchTerm): """ Public method to get a URL ready for suggestions. @param searchTerm term to search for (string) @return URL (QUrl) """ if not self._suggestionsUrlTemplate: return QUrl() ret = QUrl.fromEncoded(QByteArray(self.parseTemplate( searchTerm, self._suggestionsUrlTemplate).encode("utf-8"))) if self.__searchMethod != "post": if qVersion() >= "5.0.0": from PyQt5.QtCore import QUrlQuery urlQuery = QUrlQuery(ret) for parameter in self._suggestionsParameters: urlQuery.addQueryItem( parameter[0], self.parseTemplate(searchTerm, parameter[1])) ret.setQuery(urlQuery) else: for parameter in self._suggestionsParameters: ret.addQueryItem( parameter[0], self.parseTemplate(searchTerm, parameter[1])) return ret
def test_file_pathsep(self, sep): url = QUrl('qute://pdfjs/file') query = QUrlQuery() query.addQueryItem('filename', 'foo{}bar'.format(sep)) url.setQuery(query) with pytest.raises(qutescheme.RequestDeniedError): qutescheme.data_for_url(url)
def url(self): """ Public method to generate the URL for this subscription. @return AdBlock URL for the subscription (QUrl) """ url = QUrl() url.setScheme("abp") url.setPath("subscribe") queryItems = [] queryItems.append(("location", bytes(self.__location).decode())) queryItems.append(("title", self.__title)) if self.__requiresLocation and self.__requiresTitle: queryItems.append(("requiresLocation", self.__requiresLocation)) queryItems.append(("requiresTitle", self.__requiresTitle)) if not self.__enabled: queryItems.append(("enabled", "false")) if self.__lastUpdate.isValid(): queryItems.append(("lastUpdate", self.__lastUpdate.toString(Qt.ISODate))) if qVersion() >= "5.0.0": from PyQt5.QtCore import QUrlQuery query = QUrlQuery() query.setQueryItems(queryItems) url.setQuery(query) else: url.setQueryItems(queryItems) return url
def getHttp(self, uri, params): QgsApplication.setOverrideCursor(Qt.WaitCursor) try: rq = QUrl(uri) q = QUrlQuery() for (k, v) in params.items(): q.addQueryItem(k, v) rq.setQuery(q) req = QNetworkRequest(rq) try: reply = self.nominatim_networkAccessManager.blockingGet(req) resource = reply.content().data().decode('utf8') r = json.loads(resource) if (isinstance(r, list)): self.populateTable(r) else: self.populateTable([r]) except: self.tableResult.clearContents() finally: QgsApplication.restoreOverrideCursor()
def getIpAddressReport(self, ipAddress): """ Public method to retrieve a report for an IP address. @param ipAddress valid IPv4 address in dotted quad notation @type str """ self.__lastIP = ipAddress queryItems = [ ("apikey", Preferences.getHelp("VirusTotalServiceKey")), ("ip", ipAddress), ] url = QUrl(self.GetIpAddressReportUrl) if qVersion() >= "5.0.0": from PyQt5.QtCore import QUrlQuery query = QUrlQuery() query.setQueryItems(queryItems) url.setQuery(query) else: url.setQueryItems(queryItems) request = QNetworkRequest(url) import Helpviewer.HelpWindow nam = Helpviewer.HelpWindow.HelpWindow.networkAccessManager() reply = nam.get(request) reply.finished.connect(self.__getIpAddressReportFinished) self.__replies.append(reply)
def getDomainReport(self, domain): """ Public method to retrieve a report for a domain. @param domain domain name @type str """ self.__lastDomain = domain queryItems = [ ("apikey", Preferences.getHelp("VirusTotalServiceKey")), ("domain", domain), ] url = QUrl(self.GetDomainReportUrl) if qVersion() >= "5.0.0": from PyQt5.QtCore import QUrlQuery query = QUrlQuery() query.setQueryItems(queryItems) url.setQuery(query) else: url.setQueryItems(queryItems) request = QNetworkRequest(url) import Helpviewer.HelpWindow nam = Helpviewer.HelpWindow.HelpWindow.networkAccessManager() reply = nam.get(request) reply.finished.connect(self.__getDomainReportFinished) self.__replies.append(reply)
def get_main_url(filename): """Get the URL to be opened to view a local PDF.""" url = QUrl('qute://pdfjs/web/viewer.html') query = QUrlQuery() query.addQueryItem('filename', filename) # read from our JS query.addQueryItem('file', '') # to avoid pdfjs opening the default PDF url.setQuery(query) return url
def handle_form_submitted(self, qurl, elements=dict()): # print("\n\ngot url: ", qurl) qqurl = QUrlQuery(qurl) for key, value in qqurl.queryItems(): elements[key] = value self.render(qurl.path(), elements)
def acceptNavigationRequest(self, url, _type, isMainFrame): query = QUrlQuery(url) if query.hasQueryItem("requrl"): orig_url = query.queryItemValue("requrl", QUrl.FullyDecoded) url = QUrl(orig_url) QDesktopServices.openUrl(url) return False return super().acceptNavigationRequest(url, _type, isMainFrame)
def link_clicked(self, qurl): # print("link_clicked ->: ", qurl) qqurl = QUrlQuery(qurl) elements = {} # print("got link_clicked url: ", qurl) for key, value in qqurl.queryItems(): elements[key] = value self.render(qurl.path(), elements)
def email(subject, body): """Opens the e-mail composer with the given subject and body, with version information added to it.""" subject = "[{0} {1}] {2}".format(appinfo.appname, appinfo.version, subject) body = "{0}\n\n{1}\n\n".format(debuginfo.version_info_string(' -- '), body) url = QUrl("mailto:" + appinfo.maintainer_email) query = QUrlQuery() query.addQueryItem("subject", subject) query.addQueryItem("body", body) url.setQuery(query) helpers.openUrl(url, "email")
def wrapper(SELF, request): # Looking for Pid in query string, try matching with locally bound peerid localPeerId = app.xwaredpy.peerId if not localPeerId: return request urlQuery = QUrlQuery(request.url()) queryItems = dict(urlQuery.queryItems()) if queryItems.get("pid", None) != localPeerId: return request return func(SELF, request)
def load_account_page(self, account, tab=None, task=None, reset_history=False, set_home=False): self.tab = tab self.task = task self.account = account url = QUrl(account.server.settings_url) url_query = QUrlQuery() for name, value in self.query_items: url_query.addQueryItem(name, value) url.setQuery(url_query) if set_home: self.homepage = url if reset_history: self.history().clear() self.page().mainFrame().evaluateJavaScript('window.location.replace("{}");'.format(url.toString())) # this will replace the current url in the history else: self.load(url)
def refresh_access_token(self, callback): refresh_token = config.persist["oauth_refresh_token"] log.debug("OAuth: refreshing access_token with a refresh_token %s", refresh_token) host, port = config.setting['server_host'], config.setting['server_port'] path = "/oauth2/token" url = QUrl() url_query = QUrlQuery() url_query.addQueryItem("grant_type", "refresh_token") url_query.addQueryItem("refresh_token", refresh_token) url_query.addQueryItem("client_id", MUSICBRAINZ_OAUTH_CLIENT_ID) url_query.addQueryItem("client_secret", MUSICBRAINZ_OAUTH_CLIENT_SECRET) url.setQuery(url_query.query(QUrl.FullyEncoded)) data = string_(url.query()) self.webservice.post(host, port, path, data, partial(self.on_refresh_access_token_finished, callback), parse_response_type=None, mblogin=True, priority=True, important=True)
def _preprocess_request_bind(request): # set boxName when binding the device to hostname urlQuery = QUrlQuery(request.url()) queryItems = urlQuery.queryItems() for i, item in enumerate(queryItems): if item[0] == "boxName": queryItems[i] = ("boxName", os.uname().nodename) urlQuery.setQueryItems(queryItems) # write changes back to request qurl = request.url() qurl.setQuery(urlQuery) request.setUrl(qurl) return request
def _qute_settings_set(url): """Handler for qute://settings/set.""" query = QUrlQuery(url) option = query.queryItemValue('option', QUrl.FullyDecoded) value = query.queryItemValue('value', QUrl.FullyDecoded) # https://github.com/qutebrowser/qutebrowser/issues/727 if option == 'content.javascript.enabled' and value == 'false': msg = ("Refusing to disable javascript via qute://settings " "as it needs javascript support.") message.error(msg) return 'text/html', b'error: ' + msg.encode('utf-8') try: config.instance.set_str(option, value, save_yaml=True) return 'text/html', b'ok' except configexc.Error as e: message.error(str(e)) return 'text/html', b'error: ' + str(e).encode('utf-8')
def exceptHook(type_, value, tback): stack = ''.join(traceback.format_exception(type_, value, tback)) title = QApplication.translate("ExcpHook", "System error") text = QApplication.translate("ExcpHook", "A system error occurred.\n" "Do you want to send an error message to the author?") msgBox = QMessageBox(QMessageBox.Information, title, text) msgBox.setDetailedText(stack) msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No) if msgBox.exec_() == QMessageBox.Yes: line = traceback.extract_tb(tback)[-1] subject = "[v%s] %s - %s:%d" % (version.Version, type_.__name__, line[0], line[1]) errorMessage = [] # errorMessage.append(QApplication.translate( # "ExcpHook", # "PLEASE ADD A COMMENT, IT WILL HELP IN SOLVING THE PROBLEM")) # errorMessage.append('') errorMessage.append("%s: %s" % (version.AppName, version.Version)) errorMessage.append("OS: %s %s (%s)" % (platform.system(), platform.release(), platform.version())) errorMessage.append("Python: %s (%s)" % (platform.python_version(), platform.architecture()[0])) errorMessage.append("Qt: %s" % PYQT_VERSION_STR) try: errorMessage.append("Locale: %s" % Settings()['locale']) except: pass errorMessage.append('') errorMessage.append(stack) url = QUrl('http://opennumismat.idea.informer.com/proj/') query = QUrlQuery() query.addQueryItem('mod', 'add') query.addQueryItem('cat', '3') query.addQueryItem('idea', subject) query.addQueryItem('descr', '\n'.join(errorMessage)) url.setQuery(query) executor = QDesktopServices() executor.openUrl(url) # Call the default handler sys.__excepthook__(type_, value, tback)
def __parseUrl(self, url): """ Private method to parse the AdBlock URL for the subscription. @param url AdBlock URL for the subscription (QUrl) """ if url.scheme() != "abp": return if url.path() != "subscribe": return if qVersion() >= "5.0.0": from PyQt5.QtCore import QUrlQuery urlQuery = QUrlQuery(url) self.__title = urlQuery.queryItemValue("title") self.__enabled = urlQuery.queryItemValue("enabled") != "false" self.__location = QByteArray(urlQuery.queryItemValue("location")) # Check for required subscription self.__requiresLocation = urlQuery.queryItemValue( "requiresLocation") self.__requiresTitle = urlQuery.queryItemValue("requiresTitle") if self.__requiresLocation and self.__requiresTitle: import Helpviewer.HelpWindow Helpviewer.HelpWindow.HelpWindow.adBlockManager()\ .loadRequiredSubscription(self.__requiresLocation, self.__requiresTitle) lastUpdateString = urlQuery.queryItemValue("lastUpdate") self.__lastUpdate = QDateTime.fromString(lastUpdateString, Qt.ISODate) else: self.__title = \ QUrl.fromPercentEncoding(url.encodedQueryItemValue("title")) self.__enabled = QUrl.fromPercentEncoding( url.encodedQueryItemValue("enabled")) != "false" self.__location = QByteArray(QUrl.fromPercentEncoding( url.encodedQueryItemValue("location"))) # Check for required subscription self.__requiresLocation = QUrl.fromPercentEncoding( url.encodedQueryItemValue("requiresLocation")) self.__requiresTitle = QUrl.fromPercentEncoding( url.encodedQueryItemValue("requiresTitle")) if self.__requiresLocation and self.__requiresTitle: import Helpviewer.HelpWindow Helpviewer.HelpWindow.HelpWindow.adBlockManager()\ .loadRequiredSubscription(self.__requiresLocation, self.__requiresTitle) lastUpdateByteArray = url.encodedQueryItemValue("lastUpdate") lastUpdateString = QUrl.fromPercentEncoding(lastUpdateByteArray) self.__lastUpdate = QDateTime.fromString(lastUpdateString, Qt.ISODate) self.__loadRules()
def exceptHook(type_, value, tback): stack = ''.join(traceback.format_exception(type_, value, tback)) title = QApplication.translate("ExcpHook", "System error") text = QApplication.translate("ExcpHook", "A system error occurred.\n" "Do you want to send an error message to the author\n" "(Google account required)?") msgBox = QMessageBox(QMessageBox.Information, title, text) msgBox.setDetailedText(stack) msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No) if msgBox.exec_() == QMessageBox.Yes: line = traceback.extract_tb(tback, 1)[0] subject = "[v%s] %s - %s:%d" % (version.Version, type_.__name__, line[0], line[1]) errorMessage = [] errorMessage.append("%s: %s" % (version.AppName, version.Version)) errorMessage.append("OS: %s %s %s (%s)" % (platform.system(), platform.release(), platform.architecture()[0], platform.version())) errorMessage.append("Python: %s" % platform.python_version()) errorMessage.append("Qt: %s" % PYQT_VERSION_STR) errorMessage.append('') errorMessage.append(stack) url = QUrl('https://code.google.com/p/open-numismat/issues/entry') query = QUrlQuery() query.addQueryItem('summary', subject) query.addQueryItem('comment', '\n'.join(errorMessage)) url.setQuery(query) executor = QDesktopServices() executor.openUrl(url) # Call the default handler sys.__excepthook__(type_, value, tback)
def _generate_pdfjs_script(filename): """Generate the script that shows the pdf with pdf.js. Args: filename: The name of the file to open. """ url = QUrl('qute://pdfjs/file') url_query = QUrlQuery() url_query.addQueryItem('filename', filename) url.setQuery(url_query) return jinja.js_environment.from_string(""" document.addEventListener("DOMContentLoaded", function() { if (typeof window.PDFJS !== 'undefined') { // v1.x {% if disable_create_object_url %} window.PDFJS.disableCreateObjectURL = true; {% endif %} window.PDFJS.verbosity = window.PDFJS.VERBOSITY_LEVELS.info; } else { // v2.x const options = window.PDFViewerApplicationOptions; {% if disable_create_object_url %} options.set('disableCreateObjectURL', true); {% endif %} options.set('verbosity', pdfjsLib.VerbosityLevel.INFOS); } const viewer = window.PDFView || window.PDFViewerApplication; viewer.open({{ url }}); }); """).render( url=javascript.to_js(url.toString(QUrl.FullyEncoded)), # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-70420 disable_create_object_url=( not qtutils.version_check('5.12') and not qtutils.version_check('5.7.1', exact=True, compiled=False) and objects.backend == usertypes.Backend.QtWebEngine))
def _sendRequest(self, url, params, headers={}): if self.asynchonous: if self.reply is not None: self.reply.finished.disconnect(self.reply_finished) self.reply.abort() self.reply = None url = QUrl(url) q = QUrlQuery(url) for key, value in params.items(): q.addQueryItem(key, value) url.setQuery(q) QgsLogger.debug('Request: {}'.format(url.toEncoded())) request = QNetworkRequest(url) for key, value in headers.items(): request.setRawHeader(key, value) self.reply = QgsNetworkAccessManager.instance().get(request) self.reply.finished.connect(self.reply_finished) else: response = urlopen(self.url + '?' + urllib.urlencode(params)) data = json.load(response) self.load_data(data)
def qute_plainlog(url): """Handler for qute://plainlog. An optional query parameter specifies the minimum log level to print. For example, qute://log?level=warning prints warnings and errors. Level can be one of: vdebug, debug, info, warning, error, critical. """ if log.ram_handler is None: text = "Log output was disabled." else: level = QUrlQuery(url).queryItemValue('level') if not level: level = 'vdebug' text = log.ram_handler.dump_log(html=False, level=level) src = jinja.render('pre.html', title='log', content=text) return 'text/html', src
def createRequest(self, op, request, outgoingData=None): """ Public method to create a request. @param op the operation to be performed (QNetworkAccessManager.Operation) @param request reference to the request object (QNetworkRequest) @param outgoingData reference to an IODevice containing data to be sent (QIODevice) @return reference to the created reply object (QNetworkReply) """ if op != QNetworkAccessManager.GetOperation: return None url = request.url() if url.path() != "subscribe": return None if qVersion() >= "5.0.0": from PyQt5.QtCore import QUrlQuery, QUrl title = QUrl.fromPercentEncoding( QByteArray(QUrlQuery(url).queryItemValue("title").encode())) else: from PyQt5.QtCore import QUrl title = QUrl.fromPercentEncoding( url.encodedQueryItemValue(b"title")) if not title: return None res = E5MessageBox.yesNo( None, self.tr("Subscribe?"), self.tr("""<p>Subscribe to this AdBlock subscription?</p>""" """<p>{0}</p>""").format(title)) if res: from .AdBlockSubscription import AdBlockSubscription import Helpviewer.HelpWindow dlg = Helpviewer.HelpWindow.HelpWindow.adBlockManager()\ .showDialog() subscription = AdBlockSubscription( url, False, Helpviewer.HelpWindow.HelpWindow.adBlockManager()) Helpviewer.HelpWindow.HelpWindow.adBlockManager()\ .addSubscription(subscription) dlg.addSubscription(subscription, False) dlg.setFocus() dlg.raise_() return EmptyNetworkReply(self.parent())
def email(subject, body, recipient=None): """Opens the e-mail composer with the given subject and body, with version information added to it.""" subject = "[{0} {1}] {2}".format(appinfo.appname, appinfo.version, subject) body = "{0}\n\n{1}\n\n".format(debuginfo.version_info_string('\n'), body) address = recipient or appinfo.maintainer_email url = QUrl("mailto:" + address) query = QUrlQuery() query.addQueryItem("subject", subject) query.addQueryItem("body", body) url.setQuery(query) helpers.openUrl(url, "email")
def qute_log(url): """Handler for qute://log. An optional query parameter specifies the minimum log level to print. For example, qute://log?level=warning prints warnings and errors. Level can be one of: vdebug, debug, info, warning, error, critical. """ if log.ram_handler is None: html_log = None else: level = QUrlQuery(url).queryItemValue('level') if not level: level = 'vdebug' html_log = log.ram_handler.dump_log(html=True, level=level) html = jinja.render('log.html', title='log', content=html_log) return 'text/html', html
def requestStarted(self: QWebEngineUrlSchemeHandler, request: QWebEngineUrlRequestJob) -> None: ''' see: http://doc.qt.io/qt-5/qwebengineurlschemehandler.html#requestStarted :param info: see http://doc.qt.io/qt-5/qwebengineurlrequestjob.html ''' # 隐藏浏览器窗口 self.parent().hide() url = request.requestUrl().toString() if url.startswith("pyqtclient://close"): self._close(request) return if url.startswith("pyqtclient://login"): # 把得到的code返回给其它窗口 self.codeGeted.emit( QUrlQuery(request.requestUrl()).queryItemValue("code")) # 关闭窗口(30秒以后,保证cookie被写入,bug) QTimer.singleShot(30000, lambda: self._close(request))
def url(self, player_id): if self.state == GameState.CLOSED: return None url = QUrl() url.setHost("lobby.faforever.com") query = QUrlQuery() query.addQueryItem("map", self.mapname) query.addQueryItem("mod", self.featured_mod) if self.state == GameState.OPEN: url.setScheme("fafgame") url.setPath("/" + str(player_id)) query.addQueryItem("uid", str(self.uid)) else: url.setScheme("faflive") url.setPath("/" + str(self.uid) + "/" + str(player_id) + ".SCFAreplay") url.setQuery(query) return url
def _handle_redirect(self, reply, request, redirect): url = request.url() error = int(reply.error()) # merge with base url (to cover the possibility of the URL being relative) redirect = url.resolved(redirect) if not WebService.urls_equivalent(redirect, reply.request().url()): log.debug("Redirect to %s requested", redirect.toString(QUrl.RemoveUserInfo)) redirect_host = string_(redirect.host()) redirect_port = self.url_port(redirect) redirect_query = dict( QUrlQuery(redirect).queryItems(QUrl.FullyEncoded)) redirect_path = redirect.path() original_host = string_(url.host()) original_port = self.url_port(url) original_host_key = (original_host, original_port) redirect_host_key = (redirect_host, redirect_port) if (original_host_key in REQUEST_DELAY_MINIMUM and redirect_host_key not in REQUEST_DELAY_MINIMUM): log.debug("Setting the minimum rate limit for %s to %i" % (redirect_host_key, REQUEST_DELAY_MINIMUM[original_host_key])) REQUEST_DELAY_MINIMUM[ redirect_host_key] = REQUEST_DELAY_MINIMUM[ original_host_key] self.get(redirect_host, redirect_port, redirect_path, request.handler, request.parse_response_type, priority=True, important=True, refresh=request.refresh, queryargs=redirect_query, cacheloadcontrol=request.attribute( QtNetwork.QNetworkRequest.CacheLoadControlAttribute)) else: log.error("Redirect loop: %s", reply.request().url().toString(QUrl.RemoveUserInfo)) handler(reply.readAll(), reply, error)
def __parseUrl(self, url): """ Private method to parse the AdBlock URL for the subscription. @param url AdBlock URL for the subscription @type QUrl """ if url.scheme() != "abp": return if url.path() != "subscribe": return urlQuery = QUrlQuery(url) self.__title = QUrl.fromPercentEncoding( QByteArray(urlQuery.queryItemValue("title").encode())) self.__enabled = urlQuery.queryItemValue("enabled") != "false" self.__location = QByteArray(QUrl.fromPercentEncoding( QByteArray(urlQuery.queryItemValue("location").encode())) .encode("utf-8")) # Check for required subscription self.__requiresLocation = QUrl.fromPercentEncoding( QByteArray(urlQuery.queryItemValue( "requiresLocation").encode())) self.__requiresTitle = QUrl.fromPercentEncoding( QByteArray(urlQuery.queryItemValue("requiresTitle").encode())) if self.__requiresLocation and self.__requiresTitle: from WebBrowser.WebBrowserWindow import WebBrowserWindow WebBrowserWindow.adBlockManager().loadRequiredSubscription( self.__requiresLocation, self.__requiresTitle) lastUpdateString = urlQuery.queryItemValue("lastUpdate") self.__lastUpdate = QDateTime.fromString(lastUpdateString, Qt.ISODate) self.__loadRules()
def _handle_redirect(self, reply, request, redirect): url = request.url() error = int(reply.error()) # merge with base url (to cover the possibility of the URL being relative) redirect = url.resolved(redirect) if not WebService.urls_equivalent(redirect, reply.request().url()): log.debug("Redirect to %s requested", redirect.toString(QUrl.RemoveUserInfo)) redirect_host = redirect.host() redirect_port = self.url_port(redirect) redirect_query = dict( QUrlQuery(redirect).queryItems(QUrl.FullyEncoded)) redirect_path = redirect.path() original_host = url.host() original_port = self.url_port(url) original_host_key = (original_host, original_port) redirect_host_key = (redirect_host, redirect_port) ratecontrol.copy_minimal_delay(original_host_key, redirect_host_key) self.get(redirect_host, redirect_port, redirect_path, request.handler, request.parse_response_type, priority=True, important=True, refresh=request.refresh, queryargs=redirect_query, mblogin=request.mblogin, cacheloadcontrol=request.attribute( QNetworkRequest.CacheLoadControlAttribute)) else: log.error("Redirect loop: %s", reply.request().url().toString(QUrl.RemoveUserInfo)) request.handler(reply.readAll(), reply, error)
def qute_log(url: QUrl) -> _HandlerRet: """Handler for qute://log. There are three query parameters: - level: The minimum log level to print. For example, qute://log?level=warning prints warnings and errors. Level can be one of: vdebug, debug, info, warning, error, critical. - plain: If given (and not 'false'), plaintext is shown. - logfilter: A filter string like the --logfilter commandline argument accepts. """ query = QUrlQuery(url) plain = (query.hasQueryItem('plain') and query.queryItemValue('plain').lower() != 'false') if log.ram_handler is None: content = "Log output was disabled." if plain else None else: level = query.queryItemValue('level') if not level: level = 'vdebug' filter_str = query.queryItemValue('logfilter') try: logfilter = (log.LogFilter.parse(filter_str, only_debug=False) if filter_str else None) except log.InvalidLogFilterError as e: raise UrlInvalidError(e) content = log.ram_handler.dump_log(html=not plain, level=level, logfilter=logfilter) template = 'pre.html' if plain else 'log.html' src = jinja.render(template, title='log', content=content) return 'text/html', src
def block(self, info): """ Public method to check, if a request should be blocked. @param info request info object @type QWebEngineUrlRequestInfo @return flag indicating to block the request @rtype bool """ locker = QMutexLocker(self.__mutex) # __IGNORE_WARNING__ if not self.isEnabled(): return False urlString = bytes(info.requestUrl().toEncoded()).decode().lower() urlDomain = info.requestUrl().host().lower() urlScheme = info.requestUrl().scheme().lower() if (not self.canRunOnScheme(urlScheme) or not self.__canBeBlocked(info.firstPartyUrl())): return False res = False blockedRule = self.__matcher.match(info, urlDomain, urlString) if blockedRule: res = True if (info.resourceType() == QWebEngineUrlRequestInfo.ResourceTypeMainFrame): url = QUrl("eric:adblock") query = QUrlQuery() query.addQueryItem("rule", blockedRule.filter()) query.addQueryItem("subscription", blockedRule.subscription().title()) url.setQuery(query) info.redirect(url) else: info.block(True) return res
def geocode(self, location): url = QUrl("http://maps.googleapis.com/maps/api/geocode/xml") query = QUrlQuery() query.addQueryItem("address", location) query.addQueryItem("sensor", "false") url.setQuery(query) """ url = QUrl("http://maps.google.com/maps/geo/") url.addQueryItem("q", location) url.addQueryItem("output", "csv") url.addQueryItem("sensor", "false") """ request = QNetworkRequest(url) reply = self.get(request) while reply.isRunning(): QApplication.processEvents() reply.deleteLater() self.deleteLater() return self._parseResult(reply)
def init(my_id = 'mw9027', oppenent_id = ''): WebChatFrame.q_widget = QtWidgets.QWidget() WebChatFrame.q_widget.show() WebChatFrame.q_widget.setFixedSize(300, 600) WebChatFrame.q_widget.move(MainFrame.mainwindow.mapToGlobal(QPoint(MainFrame.mainwindow.width()+1, -23))); horizontalLayout = QtWidgets.QHBoxLayout(WebChatFrame.q_widget) horizontalLayout.setContentsMargins(0, 0, 0, 0) view = QtWebEngineWidgets.QWebEngineView(WebChatFrame.q_widget) horizontalLayout.addWidget(view) view.settings().setAttribute(QtWebEngineWidgets.QWebEngineSettings.PluginsEnabled, True) view.settings().setAttribute(QtWebEngineWidgets.QWebEngineSettings.JavascriptEnabled, True) url = QUrl(WebChatFrame.url+'/chat?m_id='+my_id) urldata = QUrlQuery() urldata.addQueryItem('m_id', my_id) urldata.addQueryItem('oppenent_id', oppenent_id) url.setQuery(urldata) view.setUrl(url) view.show()
def exceptHook(type_, value, tback): stack = ''.join(traceback.format_exception(type_, value, tback)) title = QApplication.translate("ExcpHook", "System error") text = QApplication.translate( "ExcpHook", "A system error occurred.\n" "Do you want to send an error message to the author\n" "(Google account required)?") msgBox = QMessageBox(QMessageBox.Information, title, text) msgBox.setDetailedText(stack) msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No) if msgBox.exec_() == QMessageBox.Yes: line = traceback.extract_tb(tback, 1)[0] subject = "[v%s] %s - %s:%d" % (version.Version, type_.__name__, line[0], line[1]) errorMessage = [] errorMessage.append("%s: %s" % (version.AppName, version.Version)) errorMessage.append("OS: %s %s %s (%s)" % (platform.system(), platform.release(), platform.architecture()[0], platform.version())) errorMessage.append("Python: %s" % platform.python_version()) errorMessage.append("Qt: %s" % PYQT_VERSION_STR) errorMessage.append('') errorMessage.append(stack) url = QUrl('https://code.google.com/p/open-numismat/issues/entry') query = QUrlQuery() query.addQueryItem('summary', subject) query.addQueryItem('comment', '\n'.join(errorMessage)) url.setQuery(query) executor = QDesktopServices() executor.openUrl(url) # Call the default handler sys.__excepthook__(type_, value, tback)
def exchange_authorization_code(self, authorization_code, scopes, callback): log.debug( "OAuth: exchanging authorization_code %s for an access_token", authorization_code) path = "/oauth2/token" url = QUrl() url_query = QUrlQuery() url_query.addQueryItem("grant_type", "authorization_code") url_query.addQueryItem("code", authorization_code) url_query.addQueryItem("client_id", MUSICBRAINZ_OAUTH_CLIENT_ID) url_query.addQueryItem("client_secret", MUSICBRAINZ_OAUTH_CLIENT_SECRET) url_query.addQueryItem("redirect_uri", "urn:ietf:wg:oauth:2.0:oob") url.setQuery(url_query.query(QUrl.FullyEncoded)) data = url.query() self.webservice.post( self.host, self.port, path, data, partial(self.on_exchange_authorization_code_finished, scopes, callback), mblogin=True, priority=True, important=True, request_mimetype="application/x-www-form-urlencoded")
def auto_suggest(self): text = self._editor.text() if self.catch_coordinates(text): pass elif text: is_offline = False if QgsSettings().value("/kadas/isOffline") == "false" else True LOG.debug("is_offline %s" % is_offline) if is_offline: url = QgsSettings().value( "search/locationofflinesearchurl", "http://localhost:5000/SearchServerCh", ) else: url = QgsSettings().value( "search/locationsearchurl", "https://api3.geo.admin.ch/rest/services/api/SearchServer", ) url = QUrl(url) query = QUrlQuery() query.addQueryItem("sr", "2056") query.addQueryItem("searchText", text) query.addQueryItem("lang", "en") query.addQueryItem("type", "locations") query.addQueryItem("limit", "10") url.setQuery(query) LOG.debug(url) self._network_manager.get(QNetworkRequest(url))
def refresh_access_token(self, callback): log.debug("OAuth: refreshing access_token with a refresh_token %s", self.refresh_token) path = "/oauth2/token" url = QUrl() url_query = QUrlQuery() url_query.addQueryItem("grant_type", "refresh_token") url_query.addQueryItem("refresh_token", self.refresh_token) url_query.addQueryItem("client_id", MUSICBRAINZ_OAUTH_CLIENT_ID) url_query.addQueryItem("client_secret", MUSICBRAINZ_OAUTH_CLIENT_SECRET) url.setQuery(url_query.query(QUrl.FullyEncoded)) data = url.query() self.webservice.post( self.host, self.port, path, data, partial(self.on_refresh_access_token_finished, callback), mblogin=True, priority=True, important=True, request_mimetype="application/x-www-form-urlencoded")
def formatUrl(self, endpoint, params={}): url = QUrl(DIVI_HOST + endpoint) qr = QUrlQuery() qr.setQueryItems(list(params.items())) url.setQuery( qr ) return url
def loadMessages(self, skip=None, beforeId=None, afterId=None, limit=50): logger.debug("listMessages") url = QUrl( GITTER_API + "/rooms/{}/chatMessages".format(self.id) ) query = QUrlQuery() if skip: query.addQueryItem("skip", str(skip)) if beforeId: query.addQueryItem("beforeId", str(beforeId)) if afterId: query.addQueryItem("afterId", str(afterId)) elif self._messages.last_id: query.addQueryItem("afterId", str(self._messages.last_id())) if limit: query.addQueryItem("limit", str(limit)) url.setQuery(query) req = makeRequest(url, self._auth) reply = self._net.get(req) reply.finished.connect(lambda: self.readMessages(reply))
def exchange_authorization_code(self, authorization_code, scopes, callback): log.debug("OAuth: exchanging authorization_code %s for an access_token", authorization_code) host, port = config.setting['server_host'], config.setting['server_port'] path = "/oauth2/token" url = QUrl() url_query = QUrlQuery() url_query.addQueryItem("grant_type", "authorization_code") url_query.addQueryItem("code", authorization_code) url_query.addQueryItem("client_id", MUSICBRAINZ_OAUTH_CLIENT_ID) url_query.addQueryItem("client_secret", MUSICBRAINZ_OAUTH_CLIENT_SECRET) url_query.addQueryItem("redirect_uri", "urn:ietf:wg:oauth:2.0:oob") url.setQuery(url_query.query(QUrl.FullyEncoded)) data = string_(url.query()) self.webservice.post(host, port, path, data, partial(self.on_exchange_authorization_code_finished, scopes, callback), parse_response_type=None, mblogin=True, priority=True, important=True)
def _handle_reply(self, reply, request, handler, xml, refresh): error = int(reply.error()) if error: log.error( "Network request error for %s: %s (QT code %d, HTTP code %s)", reply.request().url().toString(QUrl.RemoveUserInfo), reply.errorString(), error, repr( reply.attribute( QtNetwork.QNetworkRequest.HttpStatusCodeAttribute))) if handler is not None: handler(reply.readAll(), reply, error) else: redirect = reply.attribute( QtNetwork.QNetworkRequest.RedirectionTargetAttribute) fromCache = reply.attribute( QtNetwork.QNetworkRequest.SourceIsFromCacheAttribute) cached = ' (CACHED)' if fromCache else '' log.debug( "Received reply for %s: HTTP %d (%s) %s", reply.request().url().toString(QUrl.RemoveUserInfo), reply.attribute( QtNetwork.QNetworkRequest.HttpStatusCodeAttribute), reply.attribute( QtNetwork.QNetworkRequest.HttpReasonPhraseAttribute), cached) if handler is not None: # Redirect if found and not infinite if redirect: url = request.url() # merge with base url (to cover the possibility of the URL being relative) redirect = url.resolved(redirect) if not XmlWebService.urls_equivalent( redirect, reply.request().url()): log.debug("Redirect to %s requested", redirect.toString(QUrl.RemoveUserInfo)) redirect_host = string_(redirect.host()) redirect_port = self.url_port(redirect) redirect_query = dict( QUrlQuery(redirect).queryItems(QUrl.FullyEncoded)) redirect_path = redirect.path() original_host = string_(url.host()) original_port = self.url_port(url) if ((original_host, original_port) in REQUEST_DELAY and (redirect_host, redirect_port) not in REQUEST_DELAY): log.debug( "Setting rate limit for %s:%i to %i" % (redirect_host, redirect_port, REQUEST_DELAY[ (original_host, original_port)])) REQUEST_DELAY[(redirect_host, redirect_port)] =\ REQUEST_DELAY[(original_host, original_port)] self.get(redirect_host, redirect_port, redirect_path, handler, xml, priority=True, important=True, refresh=refresh, queryargs=redirect_query, cacheloadcontrol=request.attribute( QtNetwork.QNetworkRequest. CacheLoadControlAttribute)) else: log.error( "Redirect loop: %s", reply.request().url().toString( QUrl.RemoveUserInfo)) handler(reply.readAll(), reply, error) elif xml: document = _read_xml(QXmlStreamReader(reply)) handler(document, reply, error) else: handler(reply.readAll(), reply, error)
def querystring2har(url): return [{ "name": six.text_type(name), "value": six.text_type(value) } for name, value in QUrlQuery(url).queryItems()]
def encode_uri(ds_uri, schema_name, project_name=None): u = QUrl() urlQuery = QUrlQuery() u.setScheme("postgresql") u.setHost(ds_uri.host()) if ds_uri.port() != '': u.setPort(int(ds_uri.port())) if ds_uri.username() != '': u.setUserName(ds_uri.username()) if ds_uri.password() != '': u.setPassword(ds_uri.password()) if ds_uri.service() != '': urlQuery.addQueryItem("service", ds_uri.service()) if ds_uri.authConfigId() != '': urlQuery.addQueryItem("authcfg", ds_uri.authConfigId()) if ds_uri.sslMode() != QgsDataSourceUri.SslPrefer: urlQuery.addQueryItem("sslmode", QgsDataSourceUri.encodeSslMode(ds_uri.sslMode())) urlQuery.addQueryItem("dbname", ds_uri.database()) urlQuery.addQueryItem("schema", schema_name) if project_name: urlQuery.addQueryItem("project", project_name) u.setQuery(urlQuery) return str(u.toEncoded(), 'utf-8')
def check_for_updates(self): if self.checkBox_UpdateCheck.isChecked(): print("check for updates") update_key = self.updateKey.displayText() if len(update_key) == 50: data = QUrlQuery() data.addQueryItem("update_key", update_key) data.addQueryItem("product", "OnAirScreen") data.addQueryItem("current_version", versionString) data.addQueryItem("distribution", distributionString) data.addQueryItem("mac", self.get_mac()) data.addQueryItem("include_beta", f'{self.checkBox_IncludeBetaVersions.isChecked()}') req = QtNetwork.QNetworkRequest(QUrl(update_url)) req.setHeader(QtNetwork.QNetworkRequest.ContentTypeHeader, "application/x-www-form-urlencoded") self.nam_update_check = QtNetwork.QNetworkAccessManager() self.nam_update_check.finished.connect(self.handle_update_check_response) self.nam_update_check.post(req, data.toString(QUrl.FullyEncoded).encode("UTF-8")) else: print("error, update key in wrong format") self.error_dialog = QErrorMessage() self.error_dialog.setWindowTitle("Update Check Error") self.error_dialog.showMessage('Update key is in the wrong format!', 'UpdateKeyError')
def load(self, input_type): # username input if input_type == 'username': # set up url, name and filename url = 'http://natusfera.gbif.es/observations/'\ '{0}.csv/?page={1}&per_page={2}' name = self.dialog.username_line_edit.text().lower() name = sub(' +', ' ', name) name = name.strip() filename = name # project input elif input_type == 'project': # set up url, name and filename url = 'http://natusfera.gbif.es/observations/project/'\ '{0}.csv/?page={1}&per_page={2}' name = self.dialog.project_line_edit.text().lower() name = sub(r'([^\s\w])+', ' ', name) name = sub(' +', ' ', name) name = name.strip() name = name.replace(' ', '-') filename = name # species input elif input_type == 'species': # set up url, name and filename url = 'http://natusfera.gbif.es/observations.csv/'\ '?taxon_name={0}&page={1}&per_page={2}' name = self.dialog.species_line_edit.text().lower() name = sub(' +', ' ', name) name = name.strip() filename = name.replace(' ', '-') # everything input if input_type == 'everything': # set up url, name and filename url = 'http://natusfera.gbif.es/observations.csv/'\ '?taxon_name={0}&page={1}&per_page={2}' name = '' filename = 'everything' if filename == '': # empty input error QMessageBox.critical(self.dialog, 'error', 'Please enter text.') return try: # url_test is a testing variable (will be deleted later) url_test = urlopen(url.format(name, 1, 1)) except UnicodeEncodeError: # ascii error QMessageBox.critical(self.dialog, 'error', 'Invalid ascii characters found.') return except HTTPError: # invalid username error QMessageBox.critical(self.dialog, 'error', 'Username not found.') return except URLError: QMessageBox.critical( # internet error self.dialog, 'error', 'No internet connection.') return if url_test.info()['X-Page'] == None: # invalid project error QMessageBox.critical(self.dialog, 'error', 'Project not found.') return if url_test.read() == b'': if input_type == 'species': # invalid species error QMessageBox.critical(self.dialog, 'error', 'Species not found.') return if input_type == 'username': # username with no observations error QMessageBox.critical(self.dialog, 'error', 'This user has no observations.') return if input_type == 'project': # project with no observations error QMessageBox.critical(self.dialog, 'error', 'This project has no observations.') return del url_test # display file dialog and save chosen directory csv_output = QFileDialog.getExistingDirectory(self.dialog, 'Working directory') # if dialog is canceled, return if not csv_output: return if os.path.isdir(csv_output) == False: # invalid output directory error QMessageBox.critical(self.dialog, 'error', 'Folder not found.') return # set up csv directories csv_dir = '{0}/.{1}.csv'.format(csv_output, filename) csv_corrected_dir = '{0}/{1}.csv'.format(csv_output, filename) # update url template url = url.format(name, '{0}', 200) # save http variables url_info = urlopen(url.format(1)) csv_page = int(url_info.info()['X-Page']) csv_perpage = int(url_info.info()['X-Per-Page']) csv_totalentries = int(url_info.info()['X-Total-Entries']) csv_totalpages = float(csv_totalentries) / float(csv_perpage) del url_info # if total pages is a decimal number if csv_totalpages.is_integer() == False: # convert it to integer and add one csv_totalpages = int(csv_totalpages) + 1 # start download dialog_downloading = NatusferaQGIS3DialogDownloading( self.dialog, csv_page, csv_totalpages + 1, 'Downloading {0}.csv'.format(filename), csv_dir, csv_corrected_dir, url) # while downloading keep updating the user interface while dialog_downloading.downloading_thread.isRunning(): QCoreApplication.processEvents() # if csv file does not exist, return if not os.path.isfile(csv_corrected_dir): return # set up QGIS delimited text layer uri = QUrl.fromLocalFile(csv_corrected_dir) urlQuery = QUrlQuery(uri) urlQuery.addQueryItem('type', 'csv') urlQuery.addQueryItem('xField', 'Longitude') urlQuery.addQueryItem('yField', 'Latitude') urlQuery.addQueryItem('spatialIndex', 'no') urlQuery.addQueryItem('subsetIndex', 'no') urlQuery.addQueryItem('watchFile', 'no') urlQuery.addQueryItem('crs', 'EPSG:4326') uri.setQuery(urlQuery) layer = QgsVectorLayer(uri.toString(), '{0}_layer'.format(filename), 'delimitedtext') # display QGIS layer QgsProject.instance().addMapLayer(layer) # close dialog self.dialog.close()
def loadMessages(self, skip=None, beforeId=None, afterId=None, limit=50): logger.debug("listMessages") url = QUrl(GITTER_API + "/rooms/{}/chatMessages".format(self.id)) query = QUrlQuery() if skip: query.addQueryItem("skip", str(skip)) if beforeId: query.addQueryItem("beforeId", str(beforeId)) if afterId: query.addQueryItem("afterId", str(afterId)) elif self._messages.last_id: query.addQueryItem("afterId", str(self._messages.last_id())) if limit: query.addQueryItem("limit", str(limit)) url.setQuery(query) req = makeRequest(url, self._auth) reply = self._net.get(req) reply.finished.connect(lambda: self.readMessages(reply))
def __dataRequest(self, page, client_id, client_secret, date_from, date_to, polygon): if not self.isAuthorized(): self.authRequest(client_id, client_secret, page, date_from, date_to, polygon) return print("page=", page) # print("accessTokenExpires=", self.__accessTokenExpires.toString(Qt.ISODate)) date_format = "yyyy-MM-ddThh:mm" url = QUrl(THERMAL_ANOMALY_URL) url_query = QUrlQuery() if polygon is not None: url_query.addQueryItem("polygon", polygon) if date_from is not None: url_query.addQueryItem("shooting", "ge" + date_from.toString(date_format)) if date_to is not None: url_query.addQueryItem("shooting", "le" + date_to.toString(date_format)) # _take=1000&_skip=0&_lastUpdated=ge2020-04-08T00%3A00%3A00 url_query.addQueryItem("_take", str(TAKE)) url_query.addQueryItem("_skip", str(page * TAKE).zfill(1)) # url.setQuery(url_query) print(url_query.queryItems()) request = QtNetwork.QNetworkRequest() request.setRawHeader(b'Authorization', ('Bearer ' + self.__accessToken).encode()) request.setHeader(QNetworkRequest.ContentTypeHeader, "application/json".encode()) request.setUrl(url) # print("request: ", url) self.dataReply = self.__manager.post(request, url_query.toString(QUrl.FullyEncoded).encode()) self.dataReply.finished.connect(lambda dr=self.dataReply: self.__data_request_finished(dr, client_id, client_secret, date_from, date_to, polygon))
def _SH_URLChanged(self, url): query_items = dict(QUrlQuery(url).queryItems()) self.tab = query_items.get('tab') or self.tab self.task = query_items.get('task') or self.task
def __findForm(self, webPage, data, boundary=None): """ Private method to find the form used for logging in. @param webPage reference to the web page (QWebPage) @param data data to be sent (QByteArray) @keyparam boundary boundary string (QByteArray) for multipart encoded data, None for urlencoded data @return parsed form (LoginForm) """ from .LoginForm import LoginForm form = LoginForm() if boundary is not None: args = self.__extractMultipartQueryItems(data, boundary) else: if qVersion() >= "5.0.0": from PyQt5.QtCore import QUrlQuery argsUrl = QUrl.fromEncoded( QByteArray(b"foo://bar.com/?" + QUrl.fromPercentEncoding( data.replace(b"+", b"%20")).encode("utf-8"))) encodedArgs = QUrlQuery(argsUrl).queryItems() else: argsUrl = QUrl.fromEncoded( QByteArray(b"foo://bar.com/?" + data.replace(b"+", b"%20")) ) encodedArgs = argsUrl.queryItems() args = set() for arg in encodedArgs: key = arg[0] value = arg[1] args.add((key, value)) # extract the forms from Helpviewer.JavaScriptResources import parseForms_js lst = webPage.mainFrame().evaluateJavaScript(parseForms_js) for map in lst: formHasPasswords = False formName = map["name"] formIndex = map["index"] if isinstance(formIndex, float) and formIndex.is_integer(): formIndex = int(formIndex) elements = map["elements"] formElements = set() formElementTypes = {} deadElements = set() for elementMap in elements: try: name = elementMap["name"] value = elementMap["value"] type_ = elementMap["type"] except KeyError: continue if type_ == "password": formHasPasswords = True t = (name, value) try: if elementMap["autocomplete"] == "off": deadElements.add(t) except KeyError: pass if name: formElements.add(t) formElementTypes[name] = type_ if formElements.intersection(args) == args: form.hasAPassword = formHasPasswords if not formName: form.name = formIndex else: form.name = formName args.difference_update(deadElements) for elt in deadElements: if elt[0] in formElementTypes: del formElementTypes[elt[0]] form.elements = list(args) form.elementTypes = formElementTypes break return form
def __parseUrl(self, url): """ Private method to parse the AdBlock URL for the subscription. @param url AdBlock URL for the subscription (QUrl) """ if url.scheme() != "abp": return if url.path() != "subscribe": return if qVersion() >= "5.0.0": from PyQt5.QtCore import QUrlQuery urlQuery = QUrlQuery(url) self.__title = QUrl.fromPercentEncoding( QByteArray(urlQuery.queryItemValue("title").encode())) self.__enabled = urlQuery.queryItemValue("enabled") != "false" self.__location = QByteArray( QUrl.fromPercentEncoding( QByteArray(urlQuery.queryItemValue( "location").encode())).encode("utf-8")) # Check for required subscription self.__requiresLocation = QUrl.fromPercentEncoding( QByteArray( urlQuery.queryItemValue("requiresLocation").encode())) self.__requiresTitle = QUrl.fromPercentEncoding( QByteArray(urlQuery.queryItemValue("requiresTitle").encode())) if self.__requiresLocation and self.__requiresTitle: import Helpviewer.HelpWindow Helpviewer.HelpWindow.HelpWindow.adBlockManager()\ .loadRequiredSubscription(self.__requiresLocation, self.__requiresTitle) lastUpdateString = urlQuery.queryItemValue("lastUpdate") self.__lastUpdate = QDateTime.fromString(lastUpdateString, Qt.ISODate) else: self.__title = \ QUrl.fromPercentEncoding(url.encodedQueryItemValue(b"title")) self.__enabled = QUrl.fromPercentEncoding( url.encodedQueryItemValue(b"enabled")) != "false" self.__location = QByteArray( QUrl.fromPercentEncoding( url.encodedQueryItemValue(b"location")).encode("utf-8")) # Check for required subscription self.__requiresLocation = QUrl.fromPercentEncoding( url.encodedQueryItemValue(b"requiresLocation")) self.__requiresTitle = QUrl.fromPercentEncoding( url.encodedQueryItemValue(b"requiresTitle")) if self.__requiresLocation and self.__requiresTitle: import Helpviewer.HelpWindow Helpviewer.HelpWindow.HelpWindow.adBlockManager()\ .loadRequiredSubscription(self.__requiresLocation, self.__requiresTitle) lastUpdateByteArray = url.encodedQueryItemValue(b"lastUpdate") lastUpdateString = QUrl.fromPercentEncoding(lastUpdateByteArray) self.__lastUpdate = QDateTime.fromString(lastUpdateString, Qt.ISODate) self.__loadRules()
def _open_wfs(self, name, capabilites_url): # Add new HTTPConnection like in source # https://github.com/qgis/QGIS/blob/master/src/gui/qgsnewhttpconnection.cpp # https://github.com/qgis/QGIS/blob/79616fd8d8285b4eb93adafdfcb97a3e429b832e/src/app/qgisapp.cpp#L3783 self.msg_log_debug(u'add WFS: Name={0}, original URL={1}'.format( name, capabilites_url)) # remove additional url parameters, otherwise adding wfs works the frist time only # https://github.com/qgis/QGIS/blob/9eee12111567a84f4d4de7e020392b3c01c28598/src/gui/qgsnewhttpconnection.cpp#L199-L214 url = QUrl(capabilites_url) query_string = url.query() if query_string: query_string = QUrlQuery(query_string) query_string.removeQueryItem('SERVICE') query_string.removeQueryItem('REQUEST') query_string.removeQueryItem('FORMAT') query_string.removeQueryItem('service') query_string.removeQueryItem('request') query_string.removeQueryItem('format') #also remove VERSION: shouldn't be necessary, but QGIS sometimes seems to append version=1.0.0 query_string.removeQueryItem('VERSION') query_string.removeQueryItem('version') url.setQuery(query_string) capabilites_url = url.toString() self.msg_log_debug(u'add WFS: Name={0}, base URL={1}'.format( name, capabilites_url)) s = QSettings() self.msg_log_debug(u'existing WFS url: {0}'.format( s.value(u'qgis/connections-wfs/{0}/url'.format(name), ''))) key_user = u'qgis/WFS/{0}/username'.format(name) key_pwd = u'qgis/WFS/{0}/password'.format(name) key_referer = u'qgis/connections-wfs/{0}/referer'.format(name) key_url = u'qgis/connections-wfs/{0}/url'.format(name) key_authcfg = u'qgis/WFS/{0}/authcfg'.format(name) s.remove(key_user) s.remove(key_pwd) s.remove(key_referer) s.remove(key_url) s.sync() s.setValue(key_user, '') s.setValue(key_pwd, '') s.setValue(key_referer, '') s.setValue(key_url, capabilites_url) if self.settings.auth_propagate and self.settings.authcfg: s.setValue(key_authcfg, self.settings.authcfg) s.setValue(u'qgis/connections-wfs/selected', name) # create new dialog wfs_dlg = QgsProviderRegistry.instance().selectWidget( "WFS", self.main_win) wfs_dlg = QgsProviderRegistry.instance().createSelectionWidget( "WFS", self.main_win) wfs_dlg.addVectorLayer.connect( lambda url: iface.addVectorLayer(url, name, "WFS")) wfs_dlg.show()