From 63b9b61e753458306b2581b4788e0da5f08c6de5 Mon Sep 17 00:00:00 2001 From: Jan Verbeek Date: Wed, 10 Aug 2016 12:33:01 +0200 Subject: [PATCH] Add ClipboardError superexception --- qutebrowser/browser/commands.py | 2 +- qutebrowser/commands/runners.py | 2 +- qutebrowser/misc/miscwidgets.py | 3 +-- qutebrowser/utils/utils.py | 9 +++++++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index f8dbc0413..37ce914ed 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -855,7 +855,7 @@ class CommandDispatcher: sel = False try: text = utils.get_clipboard(selection=sel) - except utils.ClipboardEmptyError as e: + except utils.ClipboardError as e: raise cmdexc.CommandError(e) text_urls = [u for u in text.split('\n') if u.strip()] if (len(text_urls) > 1 and not urlutils.is_url(text_urls[0]) and diff --git a/qutebrowser/commands/runners.py b/qutebrowser/commands/runners.py index 33bed1d1e..6a132598d 100644 --- a/qutebrowser/commands/runners.py +++ b/qutebrowser/commands/runners.py @@ -70,7 +70,7 @@ def replace_variables(win_id, arglist): values[var] = func() arg = arg.replace(var, values[var]) args.append(arg) - except utils.ClipboardEmptyError as e: + except utils.ClipboardError as e: raise cmdexc.CommandError(e) return args diff --git a/qutebrowser/misc/miscwidgets.py b/qutebrowser/misc/miscwidgets.py index 7e84300d2..ba21e541a 100644 --- a/qutebrowser/misc/miscwidgets.py +++ b/qutebrowser/misc/miscwidgets.py @@ -47,8 +47,7 @@ class MinimalLineEditMixin: if e.key() == Qt.Key_Insert and e.modifiers() == Qt.ShiftModifier: try: text = utils.get_clipboard(selection=True) - except (utils.SelectionUnsupportedError, - utils.ClipboardEmptyError): + except utils.ClipboardError: pass else: e.accept() diff --git a/qutebrowser/utils/utils.py b/qutebrowser/utils/utils.py index 32696aacf..72d6f83e2 100644 --- a/qutebrowser/utils/utils.py +++ b/qutebrowser/utils/utils.py @@ -43,12 +43,17 @@ fake_clipboard = None log_clipboard = False -class SelectionUnsupportedError(Exception): +class ClipboardError(Exception): + + """Raised if the clipboard contents are unavailable for some reason.""" + + +class SelectionUnsupportedError(ClipboardError): """Raised if [gs]et_clipboard is used and selection=True is unsupported.""" -class ClipboardEmptyError(Exception): +class ClipboardEmptyError(ClipboardError): """Raised if get_clipboard is used and the clipboard is empty."""