Merge branch 'NoctuaNivalis-master'

This commit is contained in:
Florian Bruhin 2015-11-04 17:46:03 +01:00
commit 59bc72cfbb
3 changed files with 24 additions and 11 deletions

View File

@ -157,6 +157,7 @@ Contributors, sorted by the number of commits in descending order:
* Jimmy * Jimmy
* skinnay * skinnay
* Zach-Button * Zach-Button
* Felix Van der Jeugt
* rikn00 * rikn00
* Patric Schmitz * Patric Schmitz
* Martin Zimmermann * Martin Zimmermann

View File

@ -45,6 +45,17 @@ from qutebrowser.config import configexc, configdata
pyeval_output = ":pyeval was never called" pyeval_output = ":pyeval was never called"
HANDLERS = {}
def add_handler(name):
"""Add a handler to the qute: scheme."""
def namedecorator(function):
HANDLERS[name] = function
return function
return namedecorator
class QuteSchemeHandler(schemehandler.SchemeHandler): class QuteSchemeHandler(schemehandler.SchemeHandler):
"""Scheme handler for qute: URLs.""" """Scheme handler for qute: URLs."""
@ -108,6 +119,7 @@ class JSBridge(QObject):
message.error(win_id, e) message.error(win_id, e)
@add_handler('pyeval')
def qute_pyeval(_win_id, _request): def qute_pyeval(_win_id, _request):
"""Handler for qute:pyeval. Return HTML content as bytes.""" """Handler for qute:pyeval. Return HTML content as bytes."""
html = jinja.env.get_template('pre.html').render( html = jinja.env.get_template('pre.html').render(
@ -115,6 +127,7 @@ def qute_pyeval(_win_id, _request):
return html.encode('UTF-8', errors='xmlcharrefreplace') return html.encode('UTF-8', errors='xmlcharrefreplace')
@add_handler('version')
def qute_version(_win_id, _request): def qute_version(_win_id, _request):
"""Handler for qute:version. Return HTML content as bytes.""" """Handler for qute:version. Return HTML content as bytes."""
html = jinja.env.get_template('version.html').render( html = jinja.env.get_template('version.html').render(
@ -123,6 +136,7 @@ def qute_version(_win_id, _request):
return html.encode('UTF-8', errors='xmlcharrefreplace') return html.encode('UTF-8', errors='xmlcharrefreplace')
@add_handler('plainlog')
def qute_plainlog(_win_id, _request): def qute_plainlog(_win_id, _request):
"""Handler for qute:plainlog. Return HTML content as bytes.""" """Handler for qute:plainlog. Return HTML content as bytes."""
if log.ram_handler is None: if log.ram_handler is None:
@ -133,6 +147,7 @@ def qute_plainlog(_win_id, _request):
return html.encode('UTF-8', errors='xmlcharrefreplace') return html.encode('UTF-8', errors='xmlcharrefreplace')
@add_handler('log')
def qute_log(_win_id, _request): def qute_log(_win_id, _request):
"""Handler for qute:log. Return HTML content as bytes.""" """Handler for qute:log. Return HTML content as bytes."""
if log.ram_handler is None: if log.ram_handler is None:
@ -144,11 +159,13 @@ def qute_log(_win_id, _request):
return html.encode('UTF-8', errors='xmlcharrefreplace') return html.encode('UTF-8', errors='xmlcharrefreplace')
@add_handler('gpl')
def qute_gpl(_win_id, _request): def qute_gpl(_win_id, _request):
"""Handler for qute:gpl. Return HTML content as bytes.""" """Handler for qute:gpl. Return HTML content as bytes."""
return utils.read_file('html/COPYING.html').encode('ASCII') return utils.read_file('html/COPYING.html').encode('ASCII')
@add_handler('help')
def qute_help(win_id, request): def qute_help(win_id, request):
"""Handler for qute:help. Return HTML content as bytes.""" """Handler for qute:help. Return HTML content as bytes."""
try: try:
@ -176,6 +193,7 @@ def qute_help(win_id, request):
return utils.read_file(path).encode('UTF-8', errors='xmlcharrefreplace') return utils.read_file(path).encode('UTF-8', errors='xmlcharrefreplace')
@add_handler('settings')
def qute_settings(win_id, _request): def qute_settings(win_id, _request):
"""Handler for qute:settings. View/change qute configuration.""" """Handler for qute:settings. View/change qute configuration."""
config_getter = functools.partial(objreg.get('config').get, raw=True) config_getter = functools.partial(objreg.get('config').get, raw=True)
@ -183,14 +201,3 @@ def qute_settings(win_id, _request):
win_id=win_id, title='settings', config=configdata, win_id=win_id, title='settings', config=configdata,
confget=config_getter) confget=config_getter)
return html.encode('UTF-8', errors='xmlcharrefreplace') return html.encode('UTF-8', errors='xmlcharrefreplace')
HANDLERS = {
'pyeval': qute_pyeval,
'version': qute_version,
'plainlog': qute_plainlog,
'log': qute_log,
'gpl': qute_gpl,
'help': qute_help,
'settings': qute_settings,
}

View File

@ -33,6 +33,7 @@ import qutebrowser.app # pylint: disable=unused-import
from qutebrowser.commands import cmdutils from qutebrowser.commands import cmdutils
from qutebrowser.utils import utils from qutebrowser.utils import utils
from qutebrowser.browser import rfc6266 from qutebrowser.browser import rfc6266
from qutebrowser.browser.network import qutescheme
def whitelist_generator(): def whitelist_generator():
@ -71,6 +72,10 @@ def whitelist_generator():
yield 'PyQt5.QtGui.QAbstractTextDocumentLayout.PaintContext().clip' yield 'PyQt5.QtGui.QAbstractTextDocumentLayout.PaintContext().clip'
yield 'PyQt5.QtWidgets.QStyleOptionViewItem.backgroundColor' yield 'PyQt5.QtWidgets.QStyleOptionViewItem.backgroundColor'
# qute:... handlers
for func in qutescheme.HANDLERS.values():
yield 'qutebrowser.browser.network.qutescheme.' + func.__name__
# Globals # Globals
# https://bitbucket.org/jendrikseipp/vulture/issues/10/ # https://bitbucket.org/jendrikseipp/vulture/issues/10/
yield 'qutebrowser.misc.utilcmds.pyeval_output' yield 'qutebrowser.misc.utilcmds.pyeval_output'