From 7628c92689ac8b048be6dbfdf2be1c0ef7efb6af Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 11 Jun 2014 15:33:07 +0200 Subject: [PATCH 1/6] Support platforms where Qt is compiled without SSL support --- qutebrowser/network/networkmanager.py | 19 ++++++++++++++++--- qutebrowser/network/schemehandler.py | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/qutebrowser/network/networkmanager.py b/qutebrowser/network/networkmanager.py index b3209aea9..737e3a31e 100644 --- a/qutebrowser/network/networkmanager.py +++ b/qutebrowser/network/networkmanager.py @@ -18,12 +18,20 @@ """Our own QNetworkAccessManager.""" 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.utils.message as message import qutebrowser.utils.log as log from qutebrowser.network.qutescheme import QuteSchemeHandler +from qutebrowser.network.schemehandler import ErrorNetworkReply from qutebrowser.utils.usertypes import PromptMode @@ -46,7 +54,8 @@ class NetworkManager(QNetworkAccessManager): } if cookiejar is not None: 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.proxyAuthenticationRequired.connect( self.on_proxy_authentication_required) @@ -116,7 +125,11 @@ class NetworkManager(QNetworkAccessManager): A QNetworkReply. """ 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( op, req, outgoing_data) else: diff --git a/qutebrowser/network/schemehandler.py b/qutebrowser/network/schemehandler.py index 1f96e74dd..df4abc1c8 100644 --- a/qutebrowser/network/schemehandler.py +++ b/qutebrowser/network/schemehandler.py @@ -110,3 +110,27 @@ class SpecialNetworkReply(QNetworkReply): def isFinished(self): """Check if the reply is finished.""" 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) + QTimer.singleShot(0, lambda: self.error.emit(error)) + QTimer.singleShot(0, lambda: self.finished.emit()) + + def abort(self): + pass + + def bytesAvailable(self): + return 0 From 1b8a44ac2686a9ace2443f8ab7db6a04edc9ee11 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 12 Jun 2014 15:13:26 +0200 Subject: [PATCH 2/6] Simplify get_qt_args --- qutebrowser/test/utils/test_misc.py | 5 ----- qutebrowser/utils/misc.py | 11 +++++------ 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/qutebrowser/test/utils/test_misc.py b/qutebrowser/test/utils/test_misc.py index d9b042b3f..5414a53a2 100644 --- a/qutebrowser/test/utils/test_misc.py +++ b/qutebrowser/test/utils/test_misc.py @@ -430,11 +430,6 @@ class GetQtArgsTests(TestCase): '-stylesheet', 'foobar', '-reverse']) - def test_qt_unknown(self): - """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__': unittest.main() diff --git a/qutebrowser/utils/misc.py b/qutebrowser/utils/misc.py index e2527aa0a..f398ca8f7 100644 --- a/qutebrowser/utils/misc.py +++ b/qutebrowser/utils/misc.py @@ -272,16 +272,15 @@ def get_qt_args(namespace): The argv list to be passed to Qt. """ argv = [sys.argv[0]] - qt_args = ('style', 'stylesheet', 'widget-count', 'reverse', - 'qmljsdebugger') - for argname in qt_args: - val = getattr(namespace, 'qt_' + argname, None) + for argname, val in vars(namespace).items(): + if not argname.startswith('qt_'): + pass if val is None: # flag/argument not given continue elif val is True: - argv.append('-' + argname) + argv.append('-' + argname[3:]) else: - argv.append('-' + argname) + argv.append('-' + argname[3:]) argv.append(val[0]) return argv From 3d6d81e1cb5747723e1710cc3d6510067cca6a98 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 12 Jun 2014 15:17:27 +0200 Subject: [PATCH 3/6] Fix lint --- qutebrowser/network/schemehandler.py | 4 ++++ qutebrowser/utils/version.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/qutebrowser/network/schemehandler.py b/qutebrowser/network/schemehandler.py index df4abc1c8..595e44fef 100644 --- a/qutebrowser/network/schemehandler.py +++ b/qutebrowser/network/schemehandler.py @@ -126,11 +126,15 @@ class ErrorNetworkReply(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 diff --git a/qutebrowser/utils/version.py b/qutebrowser/utils/version.py index ecbd602b0..09dc62528 100644 --- a/qutebrowser/utils/version.py +++ b/qutebrowser/utils/version.py @@ -206,7 +206,7 @@ def version(): lines += [ '', '{}: {}'.format(platform.python_implementation(), - platform.python_version()), + platform.python_version()), 'Qt: {}, runtime: {}'.format(QT_VERSION_STR, qVersion()), 'PyQt: {}'.format(PYQT_VERSION_STR), ] From c90e01e16ad768942d897f250c0fccc819c52b5f Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 12 Jun 2014 15:17:38 +0200 Subject: [PATCH 4/6] Fix qt_args test. The order of the arguments is non-deterministic. --- qutebrowser/test/utils/test_misc.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/qutebrowser/test/utils/test_misc.py b/qutebrowser/test/utils/test_misc.py index 5414a53a2..289d76100 100644 --- a/qutebrowser/test/utils/test_misc.py +++ b/qutebrowser/test/utils/test_misc.py @@ -426,9 +426,11 @@ class GetQtArgsTests(TestCase): """Test commandline with a Qt argument and flag.""" ns = self._namespace(['--qt-stylesheet', 'foobar', '--qt-reverse'], flags=['--qt-reverse'], args=['--qt-stylesheet']) - self.assertEqual(utils.get_qt_args(ns), [sys.argv[0], - '-stylesheet', 'foobar', - '-reverse']) + qt_args = utils.get_qt_args(ns) + self.assertEqual(qt_args[0], sys.argv[0]) + self.assertIn('-reverse', qt_args) + self.assertIn('-stylesheet', qt_args) + self.assertIn('foobar', qt_args) if __name__ == '__main__': From c13ac6d5b038de032f355ac9b806425ea89a2a4a Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 12 Jun 2014 15:22:16 +0200 Subject: [PATCH 5/6] Fix get_qt_args with non-Qt args. --- qutebrowser/utils/misc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qutebrowser/utils/misc.py b/qutebrowser/utils/misc.py index f398ca8f7..a7d2c5be2 100644 --- a/qutebrowser/utils/misc.py +++ b/qutebrowser/utils/misc.py @@ -274,8 +274,8 @@ def get_qt_args(namespace): argv = [sys.argv[0]] for argname, val in vars(namespace).items(): if not argname.startswith('qt_'): - pass - if val is None: + continue + elif val is None: # flag/argument not given continue elif val is True: From 2a165468d82c29553257d123bcbad26b38ace722 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 12 Jun 2014 15:22:32 +0200 Subject: [PATCH 6/6] Update TODO --- TODO | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/TODO b/TODO index ff5683d34..b9ce538d8 100644 --- a/TODO +++ b/TODO @@ -79,6 +79,11 @@ hints - uppercase hint chars without requiring upper case to type (easier to distinguish) +style +===== + +- Add a global none attribute/setting to every ConfigType + dwb keybindings to possibly implement =====================================