Revert "Serve broken qutebrowser logo via qute:resources"

This reverts commit 37fa7431b0.
This commit is contained in:
Florian Bruhin 2016-11-10 07:51:19 +01:00
parent bbd842bd82
commit f1bba45db5
6 changed files with 12 additions and 45 deletions

View File

@ -24,7 +24,6 @@ Module attributes:
_HANDLERS: The handlers registered via decorators.
"""
import mimetypes
import urllib.parse
import qutebrowser
@ -103,7 +102,7 @@ class add_handler: # pylint: disable=invalid-name
url=url.toDisplayString(),
error='{} is not available with this '
'backend'.format(url.toDisplayString()),
icon='', qutescheme=True)
icon='')
return 'text/html', html
@ -238,8 +237,7 @@ def qute_help(url):
"repository, please run scripts/asciidoc2html.py. "
"If you're running a released version this is a bug, please "
"use :report to report it.",
icon='',
qutescheme=True)
icon='')
return 'text/html', html
urlpath = url.path()
if not urlpath or urlpath == '/':
@ -255,12 +253,3 @@ def qute_help(url):
else:
data = utils.read_file(path)
return 'text/html', data
@add_handler('resource')
def qute_resource(url):
"""Serve resources via a qute://resource/... URL."""
data = utils.read_file(url.path(), binary=True)
mimetype, _encoding = mimetypes.guess_type(url.fileName())
assert mimetype is not None, url
return mimetype, data

View File

@ -102,7 +102,7 @@ def dirbrowser_html(path):
html = jinja.render('error.html',
title="Error while reading directory",
url='file:///{}'.format(path), error=str(e),
icon='', qutescheme=False)
icon='')
return html.encode('UTF-8', errors='xmlcharrefreplace')
files = get_file_list(path, all_files, os.path.isfile)

View File

@ -178,8 +178,7 @@ class BrowserPage(QWebPage):
title = "Error loading page: {}".format(urlstr)
error_html = jinja.render(
'error.html',
title=title, url=urlstr, error=error_str, icon='',
qutescheme=False)
title=title, url=urlstr, error=error_str, icon='')
errpage.content = error_html.encode('utf-8')
errpage.encoding = 'utf-8'
return True

View File

@ -73,7 +73,7 @@ function searchFor(uri) {
<table>
<tr>
<td style="width: 10%; vertical-align: top;">
<img style="width: 100%; display: block; max-width: 256px;" src="{{ resource_url('img/broken_qutebrowser_logo.png', qutescheme) }}" />
<img style="width: 100%; display: block; max-width: 256px;" src="{{ resource_url('img/broken_qutebrowser_logo.png') }}" />
</td>
<td style="padding-left: 40px;">
<h1>Unable to load page</h1>

View File

@ -26,7 +26,7 @@ import traceback
import jinja2
import jinja2.exceptions
from qutebrowser.utils import utils, urlutils, log, qtutils
from qutebrowser.utils import utils, urlutils, log
from PyQt5.QtCore import QUrl
@ -64,25 +64,14 @@ def _guess_autoescape(template_name):
return ext in ['html', 'htm', 'xml']
def resource_url(path, qutescheme=False):
def resource_url(path):
"""Load images from a relative path (to qutebrowser).
Arguments:
path: The relative path to the image
qutescheme: If the logo needs to be served via a qute:// scheme.
This is the case when we want to show an error page from
there.
"""
if qutescheme:
url = QUrl()
url.setScheme('qute')
url.setHost('resource')
url.setPath('/' + path)
qtutils.ensure_valid(url)
return url.toString(QUrl.FullyEncoded)
else:
full_path = utils.resource_filename(path)
return QUrl.fromLocalFile(full_path).toString(QUrl.FullyEncoded)
image = utils.resource_filename(path)
return QUrl.fromLocalFile(image).toString(QUrl.FullyEncoded)
def render(template, **kwargs):

View File

@ -39,10 +39,8 @@ def patch_read_file(monkeypatch):
"""A read_file which returns a simple template if the path is right."""
if path == os.path.join('html', 'test.html'):
return """Hello {{var}}"""
elif path == os.path.join('html', 'resource_url.html'):
return """{{ resource_url('utils/testfile', False) }}"""
elif path == os.path.join('html', 'resource_url_qute.html'):
return """{{ resource_url('utils/testfile', True) }}"""
elif path == os.path.join('html', 'test2.html'):
return """{{ resource_url('utils/testfile') }}"""
elif path == os.path.join('html', 'undef.html'):
return """{{ does_not_exist() }}"""
elif path == os.path.join('html', 'undef_error.html'):
@ -61,7 +59,7 @@ def test_simple_template():
def test_resource_url():
"""Test resource_url() which can be used from templates."""
data = jinja.render('resource_url.html')
data = jinja.render('test2.html')
print(data)
url = QUrl(data)
assert url.isValid()
@ -77,14 +75,6 @@ def test_resource_url():
assert f.read().splitlines()[0] == "Hello World!"
def test_resource_url_qutescheme():
"""Test resource_url() which can be used from templates."""
data = jinja.render('resource_url_qute.html')
print(data)
url = QUrl(data)
assert url == QUrl('qute://resource/utils/testfile')
def test_not_found():
"""Test with a template which does not exist."""
with pytest.raises(jinja2.TemplateNotFound) as excinfo: