From 6aeecb3803615b8a23b2b5c9f346ba68ed270dc0 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 29 Sep 2014 20:36:53 +0200 Subject: [PATCH] Fix lints/bugs --- qutebrowser/app.py | 32 +++++++++++++---------------- qutebrowser/commands/userscripts.py | 3 +-- qutebrowser/utils/objreg.py | 1 - qutebrowser/utils/utilcmds.py | 6 +++--- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 8366c8904..792d716c5 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -250,7 +250,7 @@ class Application(QApplication): url = urlutils.fuzzy_url(urlstr) except urlutils.FuzzyUrlError as e: message.error(0, "Error when opening startpage: " - "{}".format(e)) + "{}".format(e)) tabbed_browser.tabopen(QUrl('about:blank')) else: tabbed_browser.tabopen(url) @@ -319,11 +319,14 @@ class Application(QApplication): output += self._get_registered_objects() return '\n'.join(output) - def _recover_pages(self): + def _recover_pages(self, forgiving=False): """Try to recover all open pages. Called from _exception_hook, so as forgiving as possible. + Args: + forgiving: Whether to ignore exceptions. + Return: A list of open pages, or an empty list. """ @@ -333,12 +336,15 @@ class Application(QApplication): window=win_id) for tab in tabbed_browser.widgets(): try: - url = tab.cur_url.toString( + urlstr = tab.cur_url.toString( QUrl.RemovePassword | QUrl.FullyEncoded) - if url: - pages.append(url) + if urlstr: + pages.append(urlstr) except Exception: # pylint: disable=broad-except - log.destroy.exception("Error while recovering tab") + if forgiving: + log.destroy.exception("Error while recovering tab") + else: + raise return pages def _save_geometry(self): @@ -396,7 +402,7 @@ class Application(QApplication): self._quit_status['crash'] = False try: - pages = self._recover_pages() + pages = self._recover_pages(forgiving=True) except Exception: log.destroy.exception("Error while recovering pages") pages = [] @@ -438,19 +444,9 @@ class Application(QApplication): @cmdutils.register(instance='app', ignore_args=True) def restart(self, shutdown=True, pages=None): """Restart qutebrowser while keeping existing tabs open.""" - # We don't use _recover_pages here as it's too forgiving when - # exceptions occur. # FIXME handle multiple windows correctly here if pages is None: - pages = [] - for win_id in objreg.window_registry: - tabbed_browser = objreg.get('tabbed-browser', scope='window', - window=win_id) - for tab in tabbed_browser.widgets(): - urlstr = tab.cur_url.toString( - QUrl.RemovePassword | QUrl.FullyEncoded) - if urlstr: - pages.append(urlstr) + pages = self._recover_pages() log.destroy.debug("sys.executable: {}".format(sys.executable)) log.destroy.debug("sys.path: {}".format(sys.path)) log.destroy.debug("sys.argv: {}".format(sys.argv)) diff --git a/qutebrowser/commands/userscripts.py b/qutebrowser/commands/userscripts.py index 62ba2b9c4..3554e94f6 100644 --- a/qutebrowser/commands/userscripts.py +++ b/qutebrowser/commands/userscripts.py @@ -23,12 +23,11 @@ import os import os.path import tempfile import select -import functools from PyQt5.QtCore import (pyqtSignal, QObject, QThread, QStandardPaths, QProcessEnvironment, QProcess, QUrl) -from qutebrowser.utils import message, log, utils +from qutebrowser.utils import message, log, utils, objreg from qutebrowser.commands import runners, cmdexc diff --git a/qutebrowser/utils/objreg.py b/qutebrowser/utils/objreg.py index e5315a387..bc0bc4d62 100644 --- a/qutebrowser/utils/objreg.py +++ b/qutebrowser/utils/objreg.py @@ -87,7 +87,6 @@ class ObjectRegistry(collections.UserDict): except KeyError: pass - def dump_objects(self): """Dump all objects as a list of strings.""" lines = [] diff --git a/qutebrowser/utils/utilcmds.py b/qutebrowser/utils/utilcmds.py index 6d6990b7d..32aad6af1 100644 --- a/qutebrowser/utils/utilcmds.py +++ b/qutebrowser/utils/utilcmds.py @@ -25,7 +25,7 @@ import types from PyQt5.QtCore import QCoreApplication from qutebrowser.utils import log, objreg, usertypes -from qutebrowser.commands import cmdutils, runners +from qutebrowser.commands import cmdutils, runners, cmdexc from qutebrowser.config import style @@ -45,8 +45,8 @@ def later(ms: int, *command, win_id): try: timer.setInterval(ms) except OverflowError: - raise cmdexc.CommandError("Numeric argument is too large for " - "internal int representation.") + raise cmdexc.CommandError("Numeric argument is too large for internal " + "int representation.") cmdline = ' '.join(command) commandrunner = runners.CommandRunner(win_id) timer.timeout.connect(