Merge branch 'master' of ssh://lupin/qutebrowser
This commit is contained in:
commit
23d891c66d
5
TODO
5
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
|
||||
=====================================
|
||||
|
||||
|
@ -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,6 +54,7 @@ class NetworkManager(QNetworkAccessManager):
|
||||
}
|
||||
if cookiejar is not None:
|
||||
self.setCookieJar(cookiejar)
|
||||
if SSL_AVAILABLE:
|
||||
self.sslErrors.connect(self.on_ssl_errors)
|
||||
self.authenticationRequired.connect(self.on_authentication_required)
|
||||
self.proxyAuthenticationRequired.connect(
|
||||
@ -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:
|
||||
|
@ -110,3 +110,31 @@ 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)
|
||||
# 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
|
||||
|
@ -426,14 +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'])
|
||||
|
||||
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]])
|
||||
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__':
|
||||
|
@ -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)
|
||||
if val is None:
|
||||
for argname, val in vars(namespace).items():
|
||||
if not argname.startswith('qt_'):
|
||||
continue
|
||||
elif 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
|
||||
|
Loading…
Reference in New Issue
Block a user