Fixes issues.
This commit is contained in:
parent
77190554cc
commit
814841200a
@ -1,6 +1,7 @@
|
|||||||
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
||||||
|
|
||||||
# Copyright 2014-2015 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
# Copyright 2014-2015 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||||
|
# Copyright 2015 Antoni Boucher (antoyo) <bouanto@zoho.com>
|
||||||
#
|
#
|
||||||
# This file is part of qutebrowser.
|
# This file is part of qutebrowser.
|
||||||
#
|
#
|
||||||
@ -20,14 +21,7 @@
|
|||||||
# pylint complains when using .render() on jinja templates, so we make it shut
|
# pylint complains when using .render() on jinja templates, so we make it shut
|
||||||
# up for this whole module.
|
# up for this whole module.
|
||||||
|
|
||||||
# pylint: disable=no-member
|
"""Handler functions for file:... pages."""
|
||||||
# https://bitbucket.org/logilab/pylint/issue/490/
|
|
||||||
|
|
||||||
"""Handler functions for different qute:... pages.
|
|
||||||
|
|
||||||
Module attributes:
|
|
||||||
pyeval_output: The output of the last :pyeval command.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@ -55,7 +49,19 @@ def get_file_list(basedir, all_files, filterfunc):
|
|||||||
return sorted(items, key=lambda v: v['name'].lower())
|
return sorted(items, key=lambda v: v['name'].lower())
|
||||||
|
|
||||||
|
|
||||||
def dirbrowser(urlstring):
|
def is_root(directory):
|
||||||
|
"""Check if the directory is the root directory.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
directory: The directory to check.
|
||||||
|
|
||||||
|
Return:
|
||||||
|
Whether the directory is a root directory or not.
|
||||||
|
"""
|
||||||
|
return os.path.dirname(directory) == directory
|
||||||
|
|
||||||
|
|
||||||
|
def dirbrowser_html(urlstring):
|
||||||
"""Get the directory browser web page.
|
"""Get the directory browser web page.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -69,20 +75,30 @@ def dirbrowser(urlstring):
|
|||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
# https://bitbucket.org/logilab/pylint/issue/490/
|
# https://bitbucket.org/logilab/pylint/issue/490/
|
||||||
|
|
||||||
folder = resource_filename('img/folder.svg')
|
folder_icon = resource_filename('img/folder.svg')
|
||||||
file = resource_filename('img/file.svg')
|
file_icon = resource_filename('img/file.svg')
|
||||||
|
|
||||||
if os.path.dirname(urlstring) == urlstring:
|
if is_root(urlstring):
|
||||||
parent = None
|
parent = None
|
||||||
else:
|
else:
|
||||||
parent = os.path.dirname(urlstring)
|
parent = os.path.dirname(urlstring)
|
||||||
|
|
||||||
|
try:
|
||||||
all_files = os.listdir(urlstring)
|
all_files = os.listdir(urlstring)
|
||||||
|
except (PermissionError, OSError) as e:
|
||||||
|
html = jinja.env.get_template('error.html').render(
|
||||||
|
title="Error while reading directory",
|
||||||
|
url='file://%s' % urlstring,
|
||||||
|
error=str(e),
|
||||||
|
icon='')
|
||||||
|
return html.encode('UTF-8', errors='xmlcharrefreplace')
|
||||||
|
|
||||||
files = get_file_list(urlstring, all_files, os.path.isfile)
|
files = get_file_list(urlstring, all_files, os.path.isfile)
|
||||||
directories = get_file_list(urlstring, all_files, os.path.isdir)
|
directories = get_file_list(urlstring, all_files, os.path.isdir)
|
||||||
html = template.render(title=title, url=urlstring, icon='',
|
html = template.render(title=title, url=urlstring, icon='',
|
||||||
parent=parent, files=files,
|
parent=parent, files=files,
|
||||||
directories=directories, folder=folder,
|
directories=directories, folder_icon=folder_icon,
|
||||||
file=file)
|
file_icon=file_icon)
|
||||||
return html.encode('UTF-8', errors='xmlcharrefreplace')
|
return html.encode('UTF-8', errors='xmlcharrefreplace')
|
||||||
|
|
||||||
|
|
||||||
@ -99,10 +115,10 @@ class FileSchemeHandler(schemehandler.SchemeHandler):
|
|||||||
_outgoing_data: QIODevice * outgoingData
|
_outgoing_data: QIODevice * outgoingData
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
A QNetworkReply.
|
A QNetworkReply for directories, None for files.
|
||||||
"""
|
"""
|
||||||
urlstring = request.url().toLocalFile()
|
urlstring = request.url().toLocalFile()
|
||||||
if os.path.isdir(urlstring) and os.access(urlstring, os.R_OK):
|
if os.path.isdir(urlstring):
|
||||||
data = dirbrowser(urlstring)
|
data = dirbrowser_html(urlstring)
|
||||||
return networkreply.FixedDataNetworkReply(
|
return networkreply.FixedDataNetworkReply(
|
||||||
request, data, 'text/html', self.parent())
|
request, data, 'text/html', self.parent())
|
||||||
|
@ -297,6 +297,25 @@ class NetworkManager(QNetworkAccessManager):
|
|||||||
download.destroyed.connect(self.on_adopted_download_destroyed)
|
download.destroyed.connect(self.on_adopted_download_destroyed)
|
||||||
download.do_retry.connect(self.adopt_download)
|
download.do_retry.connect(self.adopt_download)
|
||||||
|
|
||||||
|
def setReferer(self, req, current_url):
|
||||||
|
"""Set the referer header."""
|
||||||
|
referer_header_conf = config.get('network', 'referer-header')
|
||||||
|
|
||||||
|
try:
|
||||||
|
if referer_header_conf == 'never':
|
||||||
|
# Note: using ''.encode('ascii') sends a header with no value,
|
||||||
|
# instead of no header at all
|
||||||
|
req.setRawHeader('Referer'.encode('ascii'), QByteArray())
|
||||||
|
elif (referer_header_conf == 'same-domain' and
|
||||||
|
not urlutils.same_domain(req.url(), current_url)):
|
||||||
|
req.setRawHeader('Referer'.encode('ascii'), QByteArray())
|
||||||
|
# If refer_header_conf is set to 'always', we leave the header
|
||||||
|
# alone as QtWebKit did set it.
|
||||||
|
except urlutils.InvalidUrlError:
|
||||||
|
# req.url() or current_url can be invalid - this happens on
|
||||||
|
# https://www.playstation.com/ for example.
|
||||||
|
pass
|
||||||
|
|
||||||
# WORKAROUND for:
|
# WORKAROUND for:
|
||||||
# http://www.riverbankcomputing.com/pipermail/pyqt/2014-September/034806.html
|
# http://www.riverbankcomputing.com/pipermail/pyqt/2014-September/034806.html
|
||||||
#
|
#
|
||||||
@ -322,7 +341,7 @@ class NetworkManager(QNetworkAccessManager):
|
|||||||
if scheme in self._scheme_handlers:
|
if scheme in self._scheme_handlers:
|
||||||
result = self._scheme_handlers[scheme].createRequest(
|
result = self._scheme_handlers[scheme].createRequest(
|
||||||
op, req, outgoing_data)
|
op, req, outgoing_data)
|
||||||
if result:
|
if result is not None:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
host_blocker = objreg.get('host-blocker')
|
host_blocker = objreg.get('host-blocker')
|
||||||
@ -348,22 +367,8 @@ class NetworkManager(QNetworkAccessManager):
|
|||||||
webview = objreg.get('webview', scope='tab', window=self._win_id,
|
webview = objreg.get('webview', scope='tab', window=self._win_id,
|
||||||
tab=self._tab_id)
|
tab=self._tab_id)
|
||||||
current_url = webview.url()
|
current_url = webview.url()
|
||||||
referer_header_conf = config.get('network', 'referer-header')
|
|
||||||
|
|
||||||
try:
|
self.setReferer(req, current_url)
|
||||||
if referer_header_conf == 'never':
|
|
||||||
# Note: using ''.encode('ascii') sends a header with no value,
|
|
||||||
# instead of no header at all
|
|
||||||
req.setRawHeader('Referer'.encode('ascii'), QByteArray())
|
|
||||||
elif (referer_header_conf == 'same-domain' and
|
|
||||||
not urlutils.same_domain(req.url(), current_url)):
|
|
||||||
req.setRawHeader('Referer'.encode('ascii'), QByteArray())
|
|
||||||
# If refer_header_conf is set to 'always', we leave the header
|
|
||||||
# alone as QtWebKit did set it.
|
|
||||||
except urlutils.InvalidUrlError:
|
|
||||||
# req.url() or current_url can be invalid - this happens on
|
|
||||||
# https://www.playstation.com/ for example.
|
|
||||||
pass
|
|
||||||
|
|
||||||
accept_language = config.get('network', 'accept-language')
|
accept_language = config.get('network', 'accept-language')
|
||||||
if accept_language is not None:
|
if accept_language is not None:
|
||||||
|
@ -32,11 +32,11 @@ ul > li {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ul > li {
|
ul > li {
|
||||||
background-image: url('{{folder}}');
|
background-image: url('{{folder_icon}}');
|
||||||
}
|
}
|
||||||
|
|
||||||
ul.files > li {
|
ul.files > li {
|
||||||
background-image: url('{{file}}');
|
background-image: url('{{file_icon}}');
|
||||||
}
|
}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user