From 877d8148159a7e26bd94df041134d1d31b6c360e Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 21 Dec 2014 14:13:40 +0100 Subject: [PATCH] Clean up _get_window_registry. --- qutebrowser/utils/objreg.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/qutebrowser/utils/objreg.py b/qutebrowser/utils/objreg.py index d4a354448..b2d86b53d 100644 --- a/qutebrowser/utils/objreg.py +++ b/qutebrowser/utils/objreg.py @@ -171,25 +171,19 @@ def _get_window_registry(window): """Get the registry of a window.""" if window is None: raise TypeError("window is None with scope window!") - if window == 'current': - app = get('app') - win = app.activeWindow() - if win is None or not hasattr(win, 'win_id'): - raise RegistryUnavailableError('window') - elif window == 'last-focused': - try: - win = get('last-focused-main-window') - except KeyError: + try: + if window == 'current': + app = get('app') + win = app.activeWindow() + elif window == 'last-focused': try: + win = get('last-focused-main-window') + except KeyError: win = last_window() - except NoWindow: - raise RegistryUnavailableError('window') - assert hasattr(win, 'registry') - else: - try: + else: win = window_registry[window] - except KeyError: - raise RegistryUnavailableError('window') + except (KeyError, NoWindow): + win = None try: return win.registry except AttributeError: