From ef01566621cc6bf037ec4b37472fa4a86e7b0bc3 Mon Sep 17 00:00:00 2001 From: Jean-Louis Fuchs Date: Sat, 23 Jul 2016 09:44:43 +0000 Subject: [PATCH 1/5] Initialize qt logging to qutebrowser as early as possible --- qutebrowser/misc/earlyinit.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qutebrowser/misc/earlyinit.py b/qutebrowser/misc/earlyinit.py index c2b631f96..c53492360 100644 --- a/qutebrowser/misc/earlyinit.py +++ b/qutebrowser/misc/earlyinit.py @@ -309,13 +309,14 @@ def earlyinit(args): # Here we check if QtCore is available, and if not, print a message to the # console or via Tk. check_pyqt_core() + # Init logging as early as possible + init_log(args) # Now the faulthandler is enabled we fix the Qt harfbuzzing library, before # importing QtWidgets. fix_harfbuzz(args) # Now we can be sure QtCore is available, so we can print dialogs on # errors, so people only using the GUI notice them as well. check_qt_version() - check_ssl_support() remove_inputhook() check_libraries(args) - init_log(args) + check_ssl_support() From f040fd5a6dac338fd0f3eae48b5bb219e52aa449 Mon Sep 17 00:00:00 2001 From: Jean-Louis Fuchs Date: Sat, 23 Jul 2016 10:01:56 +0000 Subject: [PATCH 2/5] Ignore missing SSLv3 messages from Qt --- qutebrowser/utils/log.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qutebrowser/utils/log.py b/qutebrowser/utils/log.py index 7f67ae9f2..76d8e0dc7 100644 --- a/qutebrowser/utils/log.py +++ b/qutebrowser/utils/log.py @@ -330,6 +330,10 @@ def qt_message_handler(msg_type, context, msg): "Image of format '' blocked because it is not considered safe. If you " "are sure it is safe to do so, you can white-list the format by " "setting the environment variable QTWEBKIT_IMAGEFORMAT_WHITELIST=", + # Installing Qt from the installer may cause it looking for SSL3 which + # may not be available on the system + "QSslSocket: cannot resolve SSLv3_client_method", + "QSslSocket: cannot resolve SSLv3_server_method", ] if sys.platform == 'darwin': suppressed_msgs += [ From 64f208486e6244a543f94c42afb1481ec1b563e4 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 23 Jul 2016 13:04:45 +0200 Subject: [PATCH 3/5] Add log.ignore_py_warnings() --- qutebrowser/utils/log.py | 15 ++++++++++++++- tests/unit/utils/test_log.py | 13 +++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/qutebrowser/utils/log.py b/qutebrowser/utils/log.py index 76d8e0dc7..a1210caf0 100644 --- a/qutebrowser/utils/log.py +++ b/qutebrowser/utils/log.py @@ -167,9 +167,14 @@ def init_log(args): root.addHandler(ram) root.setLevel(logging.NOTSET) logging.captureWarnings(True) + _init_py_warnings() + QtCore.qInstallMessageHandler(qt_message_handler) + + +def _init_py_warnings(): + """Initialize Python warning handling.""" warnings.simplefilter('default') warnings.filterwarnings('ignore', module='pdb', category=ResourceWarning) - QtCore.qInstallMessageHandler(qt_message_handler) @contextlib.contextmanager @@ -182,6 +187,14 @@ def disable_qt_msghandler(): QtCore.qInstallMessageHandler(old_handler) +@contextlib.contextmanager +def ignore_py_warnings(**kwargs): + """Contextmanager to temporarily hke certain Python warnings.""" + warnings.filterwarnings('ignore', **kwargs) + yield + _init_py_warnings() + + def _init_handlers(level, color, force_color, json_logging, ram_capacity): """Init log handlers. diff --git a/tests/unit/utils/test_log.py b/tests/unit/utils/test_log.py index 5554717d9..4bf12c526 100644 --- a/tests/unit/utils/test_log.py +++ b/tests/unit/utils/test_log.py @@ -23,6 +23,7 @@ import logging import argparse import itertools import sys +import warnings import pytest import pytest_catchlog @@ -36,6 +37,7 @@ def restore_loggers(): Based on CPython's Lib/test/test_logging.py. """ + logging.captureWarnings(False) logger_dict = logging.getLogger().manager.loggerDict logging._acquireLock() try: @@ -278,3 +280,14 @@ def test_stub(caplog, suffix, expected): log.stub(suffix) assert len(caplog.records) == 1 assert caplog.records[0].message == expected + + +def test_ignore_py_warnings(caplog): + logging.captureWarnings(True) + with log.ignore_py_warnings(category=UserWarning): + warnings.warn("hidden", UserWarning) + with caplog.at_level(logging.WARNING): + warnings.warn("not hidden", UserWarning) + assert len(caplog.records) == 1 + msg = caplog.records[0].message.splitlines()[0] + assert msg.endswith("UserWarning: not hidden") From 40a3e24b05de22fd07369680e37a03010aab2c0e Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 23 Jul 2016 13:04:53 +0200 Subject: [PATCH 4/5] Ignore warning when importing pkg_resources On Debian Jessie we get a PendingDeprecationWarning which we now see since the log is init'ed earlier. --- qutebrowser/utils/qtutils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/qutebrowser/utils/qtutils.py b/qutebrowser/utils/qtutils.py index 4da9d48af..7d6da1dc6 100644 --- a/qutebrowser/utils/qtutils.py +++ b/qutebrowser/utils/qtutils.py @@ -33,11 +33,17 @@ import sys import operator import contextlib -import pkg_resources from PyQt5.QtCore import (qVersion, QEventLoop, QDataStream, QByteArray, QIODevice, QSaveFile) from PyQt5.QtWidgets import QApplication +from qutebrowser.utils import log + +with log.ignore_py_warnings(category=PendingDeprecationWarning, module='imp'): + # This imports 'imp' and gives us a PendingDeprecationWarning on + # Debian Jessie. + import pkg_resources + MAXVALS = { 'int': 2 ** 31 - 1, From d1cc5428351533639c49ba2c3c8f32cda5407b5c Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 23 Jul 2016 13:05:55 +0200 Subject: [PATCH 5/5] Update authors --- README.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/README.asciidoc b/README.asciidoc index 12a114ca9..33a11911e 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -210,6 +210,7 @@ Contributors, sorted by the number of commits in descending order: * Regina Hug * Mathias Fussenegger * Marcelo Santos +* Jean-Louis Fuchs * Fritz V155 Reichwald * Franz Fellner * zwarag