--- a/src/eric7/WebBrowser/Tools/Scripts.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/WebBrowser/Tools/Scripts.py Wed Jul 13 14:55:47 2022 +0200 @@ -20,7 +20,7 @@ def setupWebChannel(worldId): """ Function generating a script to setup the web channel. - + @param worldId world ID for which to setup the channel @type int @return script to setup the web channel @@ -74,12 +74,13 @@ registerWebChannel(); }})()""" - + from WebBrowser.WebBrowserPage import WebBrowserPage + match = ( "// @exclude eric:*" - if worldId == WebBrowserPage.SafeJsWorld else - "// @include eric:*" + if worldId == WebBrowserPage.SafeJsWorld + else "// @include eric:*" ) return source.format(match, getJavascript("qwebchannel.js")) @@ -87,7 +88,7 @@ def setupWindowObject(): """ Function generating a script to setup window.object add-ons. - + @return generated script @rtype str """ @@ -106,14 +107,14 @@ window.location = 'eric:PrintPage'; }; })()""" - + return source def setStyleSheet(css): """ Function generating a script to set a user style sheet. - + @param css style sheet to be applied @type str @return script to set a user style sheet @@ -126,7 +127,7 @@ css.appendChild(document.createTextNode('{0}')); document.getElementsByTagName('head')[0].appendChild(css); }})()""" - + style = css.replace("'", "\\'").replace("\n", "\\n") return source.format(style) @@ -134,7 +135,7 @@ def getFormData(pos): """ Function generating a script to extract data for a form element. - + @param pos position to extract data at @type QPoint @return script to extract form data @@ -171,7 +172,7 @@ def getAllImages(): """ Function generating a script to extract all image tags of a web page. - + @return script to extract image tags @rtype str """ @@ -194,7 +195,7 @@ def getAllMetaAttributes(): """ Function generating a script to extract all meta attributes of a web page. - + @return script to extract meta attributes @rtype str """ @@ -219,7 +220,7 @@ def getOpenSearchLinks(): """ Function generating a script to extract all open search links. - + @return script to extract all open serach links @rtype str """ @@ -244,7 +245,7 @@ def sendPostData(url, data): """ Function generating a script to send Post data. - + @param url URL to send the data to @type QUrl @param data data to be sent @@ -261,30 +262,28 @@ {1} form.submit(); }})()""" - + valueSource = """ val = document.createElement('input'); val.setAttribute('type', 'hidden'); val.setAttribute('name', '{0}'); val.setAttribute('value', '{1}'); form.appendChild(val);""" - + values = "" query = QUrlQuery(data) - for name, value in query.queryItems( - QUrl.ComponentFormattingOption.FullyDecoded - ): + for name, value in query.queryItems(QUrl.ComponentFormattingOption.FullyDecoded): value = value.replace("'", "\\'") name = name.replace("'", "\\'") values += valueSource.format(name, value) - + return source.format(url.toString(), values) def setupFormObserver(): """ Function generating a script to monitor a web form for user entries. - + @return script to monitor a web page @rtype str """ @@ -357,7 +356,7 @@ def completeFormData(data): """ Function generating a script to fill in form data. - + @param data data to be filled into the form @type QByteArray @return script to fill a form @@ -388,7 +387,7 @@ }} }})()""" - + data = bytes(data).decode("utf-8") data = data.replace("'", "\\'") return source.format(data) @@ -397,7 +396,7 @@ def setCss(css): """ Function generating a script to set a given CSS style sheet. - + @param css style sheet @type str @return script to set the style sheet @@ -417,7 +416,7 @@ def scrollToAnchor(anchor): """ Function generating script to scroll to a given anchor. - + @param anchor name of the anchor to scroll to @type str @return script to set the style sheet @@ -436,6 +435,7 @@ }})()""" return source.format(anchor) + ########################################################################### ## scripts below are specific for eric ########################################################################### @@ -444,7 +444,7 @@ def getFeedLinks(): """ Function generating a script to extract all RSS and Atom feed links. - + @return script to extract all RSS and Atom feed links @rtype str """