def __exit__(self, exc_type, exc_val, exc_tb): """ Destroy the context, pop itself from context stack and unbind all events. """ _context_stacks.setdefault(get_context_id(), []).pop() self.unbind_events() self.cleanup()
def get_current_store_manager(cls) -> 'StoreManager': """ Find the current :class:`StoreManager` in context stack if any. else :exc:`.ContextError` will be raised. """ try: return _context_stacks.setdefault(get_context_id(), [])[-1] except IndexError: raise ContextError('Not in store manager context.')
def __enter__(self): """ Enters the context: bind events and push itself into context stack. :return: self """ self.bind_events() _context_stacks.setdefault(get_context_id(), []).append(self) return self