Avoid circular import
This commit is contained in:
parent
c6f83d3148
commit
8a4ca25b8d
@ -75,23 +75,6 @@ class UnsupportedOperationError(WebTabError):
|
|||||||
"""Raised when an operation is not supported with the given backend."""
|
"""Raised when an operation is not supported with the given backend."""
|
||||||
|
|
||||||
|
|
||||||
class AbstractCertificateErrorWrapper:
|
|
||||||
|
|
||||||
"""A wrapper over an SSL/certificate error."""
|
|
||||||
|
|
||||||
def __init__(self, error):
|
|
||||||
self._error = error
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def is_overridable(self):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
|
||||||
class TabData:
|
class TabData:
|
||||||
|
|
||||||
"""A simple namespace with a fixed set of attributes.
|
"""A simple namespace with a fixed set of attributes.
|
||||||
|
45
qutebrowser/browser/webengine/certificateerror.py
Normal file
45
qutebrowser/browser/webengine/certificateerror.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
||||||
|
|
||||||
|
# Copyright 2016 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||||
|
#
|
||||||
|
# This file is part of qutebrowser.
|
||||||
|
#
|
||||||
|
# qutebrowser is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# qutebrowser is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
"""Wrapper over a QWebEngineCertificateError."""
|
||||||
|
|
||||||
|
|
||||||
|
from PyQt5.QtWebEngineWidgets import QWebEngineCertificateError
|
||||||
|
|
||||||
|
from qutebrowser.utils import usertypes, utils, debug
|
||||||
|
|
||||||
|
|
||||||
|
class CertificateErrorWrapper(usertypes.AbstractCertificateErrorWrapper):
|
||||||
|
|
||||||
|
"""A wrapper over a QWebEngineCertificateError."""
|
||||||
|
|
||||||
|
def __init__(self, error):
|
||||||
|
self._error = error
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self._error.errorDescription()
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return utils.get_repr(
|
||||||
|
self, error=debug.qenum_key(QWebEngineCertificateError,
|
||||||
|
self._error.error()),
|
||||||
|
string=str(self))
|
||||||
|
|
||||||
|
def is_overridable(self):
|
||||||
|
return self._error.isOverridable()
|
@ -30,8 +30,7 @@ from PyQt5.QtGui import QKeyEvent, QIcon
|
|||||||
# pylint: disable=no-name-in-module,import-error,useless-suppression
|
# pylint: disable=no-name-in-module,import-error,useless-suppression
|
||||||
from PyQt5.QtWidgets import QOpenGLWidget, QApplication
|
from PyQt5.QtWidgets import QOpenGLWidget, QApplication
|
||||||
from PyQt5.QtWebEngineWidgets import (QWebEnginePage, QWebEngineScript,
|
from PyQt5.QtWebEngineWidgets import (QWebEnginePage, QWebEngineScript,
|
||||||
QWebEngineProfile,
|
QWebEngineProfile)
|
||||||
QWebEngineCertificateError)
|
|
||||||
# pylint: enable=no-name-in-module,import-error,useless-suppression
|
# pylint: enable=no-name-in-module,import-error,useless-suppression
|
||||||
|
|
||||||
from qutebrowser.browser import browsertab, mouse, shared
|
from qutebrowser.browser import browsertab, mouse, shared
|
||||||
@ -79,26 +78,6 @@ _JS_WORLD_MAP = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class CertificateErrorWrapper(browsertab.AbstractCertificateErrorWrapper):
|
|
||||||
|
|
||||||
"""A wrapper over a QWebEngineCertificateError."""
|
|
||||||
|
|
||||||
def __init__(self, error):
|
|
||||||
self._error = error
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self._error.errorDescription()
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return utils.get_repr(
|
|
||||||
self, error=debug.qenum_key(QWebEngineCertificateError,
|
|
||||||
self._error.error()),
|
|
||||||
string=str(self))
|
|
||||||
|
|
||||||
def is_overridable(self):
|
|
||||||
return self._error.isOverridable()
|
|
||||||
|
|
||||||
|
|
||||||
class WebEnginePrinting(browsertab.AbstractPrinting):
|
class WebEnginePrinting(browsertab.AbstractPrinting):
|
||||||
|
|
||||||
"""QtWebEngine implementations related to printing."""
|
"""QtWebEngine implementations related to printing."""
|
||||||
|
@ -27,7 +27,7 @@ from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage
|
|||||||
# pylint: enable=no-name-in-module,import-error,useless-suppression
|
# pylint: enable=no-name-in-module,import-error,useless-suppression
|
||||||
|
|
||||||
from qutebrowser.browser import shared
|
from qutebrowser.browser import shared
|
||||||
from qutebrowser.browser.webengine import webenginetab
|
from qutebrowser.browser.webengine import webenginetab, certificateerror
|
||||||
from qutebrowser.config import config
|
from qutebrowser.config import config
|
||||||
from qutebrowser.utils import log, debug, usertypes, objreg, qtutils, jinja
|
from qutebrowser.utils import log, debug, usertypes, objreg, qtutils, jinja
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ class WebEnginePage(QWebEnginePage):
|
|||||||
def certificateError(self, error):
|
def certificateError(self, error):
|
||||||
self.certificate_error.emit()
|
self.certificate_error.emit()
|
||||||
url = error.url()
|
url = error.url()
|
||||||
error = webenginetab.CertificateErrorWrapper(error)
|
error = certificateerror.CertificateErrorWrapper(error)
|
||||||
log.webview.debug("Certificate error: {}".format(error))
|
log.webview.debug("Certificate error: {}".format(error))
|
||||||
|
|
||||||
url_string = url.toDisplayString()
|
url_string = url.toDisplayString()
|
||||||
|
55
qutebrowser/browser/webkit/certificateerror.py
Normal file
55
qutebrowser/browser/webkit/certificateerror.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
||||||
|
|
||||||
|
# Copyright 2016 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||||
|
#
|
||||||
|
# This file is part of qutebrowser.
|
||||||
|
#
|
||||||
|
# qutebrowser is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# qutebrowser is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
"""Wrapper over a QSslCertificateError."""
|
||||||
|
|
||||||
|
|
||||||
|
from PyQt5.QtNetwork import QSslError
|
||||||
|
|
||||||
|
from qutebrowser.utils import usertypes, utils, debug
|
||||||
|
|
||||||
|
|
||||||
|
class CertificateErrorWrapper(usertypes.AbstractCertificateErrorWrapper):
|
||||||
|
|
||||||
|
"""A wrapper over a QSslError."""
|
||||||
|
|
||||||
|
def __init__(self, error):
|
||||||
|
self._error = error
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self._error.errorString()
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return utils.get_repr(
|
||||||
|
self, error=debug.qenum_key(QSslError, self._error.error()),
|
||||||
|
string=str(self))
|
||||||
|
|
||||||
|
def __hash__(self):
|
||||||
|
try:
|
||||||
|
# Qt >= 5.4
|
||||||
|
return hash(self._error)
|
||||||
|
except TypeError:
|
||||||
|
return hash((self._error.certificate().toDer(),
|
||||||
|
self._error.error()))
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return self._error == other._error
|
||||||
|
|
||||||
|
def is_overridable(self):
|
||||||
|
return True
|
@ -33,7 +33,7 @@ from qutebrowser.config import config
|
|||||||
from qutebrowser.utils import (message, log, usertypes, utils, objreg, qtutils,
|
from qutebrowser.utils import (message, log, usertypes, utils, objreg, qtutils,
|
||||||
urlutils, debug)
|
urlutils, debug)
|
||||||
from qutebrowser.browser import shared
|
from qutebrowser.browser import shared
|
||||||
from qutebrowser.browser.webkit import webkittab
|
from qutebrowser.browser.webkit import webkittab, certificateerror
|
||||||
from qutebrowser.browser.webkit.network import (webkitqutescheme, networkreply,
|
from qutebrowser.browser.webkit.network import (webkitqutescheme, networkreply,
|
||||||
filescheme)
|
filescheme)
|
||||||
|
|
||||||
@ -233,7 +233,7 @@ class NetworkManager(QNetworkAccessManager):
|
|||||||
reply: The QNetworkReply that is encountering the errors.
|
reply: The QNetworkReply that is encountering the errors.
|
||||||
errors: A list of errors.
|
errors: A list of errors.
|
||||||
"""
|
"""
|
||||||
errors = [webkittab.CertificateErrorWrapper(e) for e in errors]
|
errors = [certificateerror.CertificateErrorWrapper(e) for e in errors]
|
||||||
log.webview.debug("Certificate errors: {!r}".format(
|
log.webview.debug("Certificate errors: {!r}".format(
|
||||||
' / '.join(str(err) for err in errors)))
|
' / '.join(str(err) for err in errors)))
|
||||||
try:
|
try:
|
||||||
|
@ -30,7 +30,6 @@ from PyQt5.QtWidgets import QApplication
|
|||||||
from PyQt5.QtWebKitWidgets import QWebPage, QWebFrame
|
from PyQt5.QtWebKitWidgets import QWebPage, QWebFrame
|
||||||
from PyQt5.QtWebKit import QWebSettings
|
from PyQt5.QtWebKit import QWebSettings
|
||||||
from PyQt5.QtPrintSupport import QPrinter
|
from PyQt5.QtPrintSupport import QPrinter
|
||||||
from PyQt5.QtNetwork import QSslError
|
|
||||||
|
|
||||||
from qutebrowser.browser import browsertab
|
from qutebrowser.browser import browsertab
|
||||||
from qutebrowser.browser.webkit import webview, tabhistory, webkitelem
|
from qutebrowser.browser.webkit import webview, tabhistory, webkitelem
|
||||||
@ -50,36 +49,6 @@ def init():
|
|||||||
objreg.register('js-bridge', js_bridge)
|
objreg.register('js-bridge', js_bridge)
|
||||||
|
|
||||||
|
|
||||||
class CertificateErrorWrapper(browsertab.AbstractCertificateErrorWrapper):
|
|
||||||
|
|
||||||
"""A wrapper over a QSslError."""
|
|
||||||
|
|
||||||
def __init__(self, error):
|
|
||||||
self._error = error
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self._error.errorString()
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return utils.get_repr(
|
|
||||||
self, error=debug.qenum_key(QSslError, self._error.error()),
|
|
||||||
string=str(self))
|
|
||||||
|
|
||||||
def __hash__(self):
|
|
||||||
try:
|
|
||||||
# Qt >= 5.4
|
|
||||||
return hash(self._error)
|
|
||||||
except TypeError:
|
|
||||||
return hash((self._error.certificate().toDer(),
|
|
||||||
self._error.error()))
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
|
||||||
return self._error == other._error
|
|
||||||
|
|
||||||
def is_overridable(self):
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class WebKitPrinting(browsertab.AbstractPrinting):
|
class WebKitPrinting(browsertab.AbstractPrinting):
|
||||||
|
|
||||||
"""QtWebKit implementations related to printing."""
|
"""QtWebKit implementations related to printing."""
|
||||||
|
@ -402,3 +402,20 @@ class Timer(QTimer):
|
|||||||
super().start(msec)
|
super().start(msec)
|
||||||
else:
|
else:
|
||||||
super().start()
|
super().start()
|
||||||
|
|
||||||
|
|
||||||
|
class AbstractCertificateErrorWrapper:
|
||||||
|
|
||||||
|
"""A wrapper over an SSL/certificate error."""
|
||||||
|
|
||||||
|
def __init__(self, error):
|
||||||
|
self._error = error
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def is_overridable(self):
|
||||||
|
raise NotImplementedError
|
||||||
|
@ -64,3 +64,20 @@ def ssl_error_page(request, quteproc):
|
|||||||
"loading page: *'")
|
"loading page: *'")
|
||||||
content = quteproc.get_content().strip()
|
content = quteproc.get_content().strip()
|
||||||
assert "Unable to load page" in content
|
assert "Unable to load page" in content
|
||||||
|
|
||||||
|
|
||||||
|
class AbstractCertificateErrorWrapper:
|
||||||
|
|
||||||
|
"""A wrapper over an SSL/certificate error."""
|
||||||
|
|
||||||
|
def __init__(self, error):
|
||||||
|
self._error = error
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def is_overridable(self):
|
||||||
|
raise NotImplementedError
|
||||||
|
27
tests/unit/utils/usertypes/test_misc.py
Normal file
27
tests/unit/utils/usertypes/test_misc.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
||||||
|
|
||||||
|
# Copyright 2016 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||||
|
#
|
||||||
|
# This file is part of qutebrowser.
|
||||||
|
#
|
||||||
|
# qutebrowser is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# qutebrowser is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
from qutebrowser.utils import usertypes
|
||||||
|
|
||||||
|
|
||||||
|
def test_abstract_certificate_error_wrapper():
|
||||||
|
err = object()
|
||||||
|
wrapper = usertypes.AbstractCertificateErrorWrapper(err)
|
||||||
|
assert wrapper._error is err
|
Loading…
Reference in New Issue
Block a user