Merge branch 'master' of ssh://lupin/qutebrowser

This commit is contained in:
Florian Bruhin 2014-06-12 19:01:37 +02:00
commit 23d891c66d
6 changed files with 61 additions and 19 deletions

5
TODO
View File

@ -79,6 +79,11 @@ hints
- uppercase hint chars without requiring upper case to type (easier to - uppercase hint chars without requiring upper case to type (easier to
distinguish) distinguish)
style
=====
- Add a global none attribute/setting to every ConfigType
dwb keybindings to possibly implement dwb keybindings to possibly implement
===================================== =====================================

View File

@ -18,12 +18,20 @@
"""Our own QNetworkAccessManager.""" """Our own QNetworkAccessManager."""
from PyQt5.QtCore import pyqtSlot from PyQt5.QtCore import pyqtSlot
from PyQt5.QtNetwork import QNetworkAccessManager from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkReply
try:
from PyQt5.QtNetwork import QSslSocket
except ImportError:
SSL_AVAILABLE = False
else:
SSL_AVAILABLE = QSslSocket.supportsSsl()
import qutebrowser.config.config as config import qutebrowser.config.config as config
import qutebrowser.utils.message as message import qutebrowser.utils.message as message
import qutebrowser.utils.log as log import qutebrowser.utils.log as log
from qutebrowser.network.qutescheme import QuteSchemeHandler from qutebrowser.network.qutescheme import QuteSchemeHandler
from qutebrowser.network.schemehandler import ErrorNetworkReply
from qutebrowser.utils.usertypes import PromptMode from qutebrowser.utils.usertypes import PromptMode
@ -46,7 +54,8 @@ class NetworkManager(QNetworkAccessManager):
} }
if cookiejar is not None: if cookiejar is not None:
self.setCookieJar(cookiejar) self.setCookieJar(cookiejar)
self.sslErrors.connect(self.on_ssl_errors) if SSL_AVAILABLE:
self.sslErrors.connect(self.on_ssl_errors)
self.authenticationRequired.connect(self.on_authentication_required) self.authenticationRequired.connect(self.on_authentication_required)
self.proxyAuthenticationRequired.connect( self.proxyAuthenticationRequired.connect(
self.on_proxy_authentication_required) self.on_proxy_authentication_required)
@ -116,7 +125,11 @@ class NetworkManager(QNetworkAccessManager):
A QNetworkReply. A QNetworkReply.
""" """
scheme = req.url().scheme() scheme = req.url().scheme()
if scheme in self._scheme_handlers: if scheme == 'https' and not SSL_AVAILABLE:
return ErrorNetworkReply(
"SSL is not supported by the installed Qt library!",
QNetworkReply.ProtocolUnknownError)
elif scheme in self._scheme_handlers:
reply = self._scheme_handlers[scheme].createRequest( reply = self._scheme_handlers[scheme].createRequest(
op, req, outgoing_data) op, req, outgoing_data)
else: else:

View File

@ -110,3 +110,31 @@ class SpecialNetworkReply(QNetworkReply):
def isFinished(self): def isFinished(self):
"""Check if the reply is finished.""" """Check if the reply is finished."""
return True return True
class ErrorNetworkReply(QNetworkReply):
"""QNetworkReply which always returns an error."""
def __init__(self, errorstring, error, parent=None):
"""Constructor.
Args:
errorstring: The error string to print.
error: The numerical error value.
parent: The parent to pass to QNetworkReply.
"""
super().__init__(parent)
self.setError(error, errorstring)
# For some reason, a segfault will be triggered if these lambdas aren't
# there. pylint: disable=unnecessary-lambda
QTimer.singleShot(0, lambda: self.error.emit(error))
QTimer.singleShot(0, lambda: self.finished.emit())
def abort(self):
"""Do nothing since it's a fake reply."""
pass
def bytesAvailable(self):
"""We always have 0 bytes available."""
return 0

View File

@ -426,14 +426,11 @@ class GetQtArgsTests(TestCase):
"""Test commandline with a Qt argument and flag.""" """Test commandline with a Qt argument and flag."""
ns = self._namespace(['--qt-stylesheet', 'foobar', '--qt-reverse'], ns = self._namespace(['--qt-stylesheet', 'foobar', '--qt-reverse'],
flags=['--qt-reverse'], args=['--qt-stylesheet']) flags=['--qt-reverse'], args=['--qt-stylesheet'])
self.assertEqual(utils.get_qt_args(ns), [sys.argv[0], qt_args = utils.get_qt_args(ns)
'-stylesheet', 'foobar', self.assertEqual(qt_args[0], sys.argv[0])
'-reverse']) self.assertIn('-reverse', qt_args)
self.assertIn('-stylesheet', qt_args)
def test_qt_unknown(self): self.assertIn('foobar', qt_args)
"""Test commandline with unknown Qt argument."""
ns = self._namespace(['--qt-foo'], flags=['--qt-foo'])
self.assertEqual(utils.get_qt_args(ns), [sys.argv[0]])
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -272,16 +272,15 @@ def get_qt_args(namespace):
The argv list to be passed to Qt. The argv list to be passed to Qt.
""" """
argv = [sys.argv[0]] argv = [sys.argv[0]]
qt_args = ('style', 'stylesheet', 'widget-count', 'reverse', for argname, val in vars(namespace).items():
'qmljsdebugger') if not argname.startswith('qt_'):
for argname in qt_args: continue
val = getattr(namespace, 'qt_' + argname, None) elif val is None:
if val is None:
# flag/argument not given # flag/argument not given
continue continue
elif val is True: elif val is True:
argv.append('-' + argname) argv.append('-' + argname[3:])
else: else:
argv.append('-' + argname) argv.append('-' + argname[3:])
argv.append(val[0]) argv.append(val[0])
return argv return argv

View File

@ -206,7 +206,7 @@ def version():
lines += [ lines += [
'', '',
'{}: {}'.format(platform.python_implementation(), '{}: {}'.format(platform.python_implementation(),
platform.python_version()), platform.python_version()),
'Qt: {}, runtime: {}'.format(QT_VERSION_STR, qVersion()), 'Qt: {}, runtime: {}'.format(QT_VERSION_STR, qVersion()),
'PyQt: {}'.format(PYQT_VERSION_STR), 'PyQt: {}'.format(PYQT_VERSION_STR),
] ]