Coverage for qutebrowser/utils/objreg.py : 69%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2014-2018 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/>.
"""Class for an unset object.
Only used (rather than object) so we can tell pylint to shut up about it. """
"""Exception raised when a certain registry does not exist yet."""
"""Exception raised by last_window if no window is available."""
"""A registry of long-living objects in qutebrowser.
Inspired by the eric IDE code (E5Gui/E5Application.py).
Attributes: _partial_objs: A dictionary of the connected partial objects. """
"""Register an object in the object registry.
Sets a slot to remove QObjects when they are destroyed. """ raise TypeError("Registering '{}' with name 'None'!".format(obj)) raise TypeError("Registering object None with name '{}'!".format( name))
"""Extend __delitem__ to disconnect the destroyed signal."""
"""Disconnect the destroyed slot if it was connected.""" except AttributeError: # This sometimes seems to happen on Travis during # test_history.test_adding_item_during_async_read # and I have no idea why... return # If C++ has deleted the object, the slot is already # disconnected.
"""Schedule removing of a destroyed QObject.
We don't remove the destroyed object immediately because it might still be destroying its children, which might still use the object registry. """
"""Remove a destroyed QObject.""" # This sometimes seems to happen on Travis during # test_history.test_adding_item_during_async_read # and I have no idea why...
"""Dump all objects as a list of strings.""" try: obj_repr = repr(obj) except RuntimeError: # Underlying object deleted probably obj_repr = '<deleted>' lines.append("{}: {}".format(name, obj_repr))
# The registry for global objects # The window registry.
"""Get the registry of a tab.""" raise ValueError("Got tab_id None (win_id {})".format(win_id)) app = get('app') window = app.activeWindow() if window is None or not hasattr(window, 'win_id'): raise RegistryUnavailableError('tab') win_id = window.win_id else: raise TypeError("window is None with scope tab!")
tabbed_browser = get('tabbed-browser', scope='window', window=win_id) tab = tabbed_browser.currentWidget() if tab is None: raise RegistryUnavailableError('window') tab_id = tab.tab_id except AttributeError: raise RegistryUnavailableError('tab')
"""Get the registry of a window.""" raise TypeError("window is None with scope window!") app = get('app') win = app.activeWindow() else: except (KeyError, NoWindow): win = None except AttributeError: raise RegistryUnavailableError('window')
"""Get the correct registry for a given scope.""" raise TypeError("window is set with scope {}".format(scope)) raise TypeError("tab is set with scope {}".format(scope)) else: raise ValueError("Invalid scope '{}'!".format(scope))
"""Helper function to get an object.
Args: default: A default to return if the object does not exist. """ else:
tab=None): """Helper function to register an object.
Args: name: The name the object will be registered as. obj: The object to register. update: If True, allows to update an already registered object. """ raise ValueError("scope ({}) and registry ({}) can't be given at the " "same time!".format(scope, registry)) else: raise KeyError("Object '{}' is already registered ({})!".format( name, repr(reg[name])))
"""Helper function to unregister an object."""
"""Get all registered objects in all registries as a string.""" registry = _get_registry('window', window=win_id) blocks.append(('window-{}'.format(win_id), registry.dump_objects())) tab_registry = get('tab-registry', scope='window', window=win_id) for tab_id, tab in tab_registry.items(): dump = tab.registry.dump_objects() data = [' ' + line for line in dump] blocks.append((' tab-{}'.format(tab_id), data)) name, len(data))) lines.append(" {}".format(line))
"""Get the last visible window, or the last focused window if none.""" try: return get('last-visible-main-window') except KeyError: return last_focused_window()
"""Get the last focused window, or the last window if none."""
"""Get the Nth opened window object.""" raise NoWindow() else: |