def fire_event(self, event_name, ctx): """Run all the handlers for a given event name. :param event_name: The event identifier, indicated by the documentation. Usually, this is a string. :param handler: The method context. Event-related data is conventionally stored in ctx.event attribute. """ handlers = self.handlers.get(event_name, oset()) for handler in handlers: handler(ctx)
def add_listener(self, event_name, handler): """Register a handler for the given event name. :param event_name: The event identifier, indicated by the documentation. Usually, this is a string. :param handler: A static python function that receives a single MethodContext argument. """ handlers = self.handlers.get(event_name, oset()) handlers.add(handler) self.handlers[event_name] = handlers
def __get_base_event_handlers(self, cls_bases): handlers = {} for base in cls_bases: evmgr = getattr(base, 'event_manager', None) if evmgr is None: continue for k, v in evmgr.handlers.items(): handler=handlers.get(k, oset()) for h in v: handler.add(h) handlers[k]=handler return handlers
def __get_base_event_handlers(self, cls_bases): handlers = {} for base in cls_bases: evmgr = getattr(base, 'event_manager', None) if evmgr is None: continue for k, v in evmgr.handlers.items(): handler = handlers.get(k, oset()) for h in v: handler.add(h) handlers[k] = handler return handlers
def fire_event(self, event_name, ctx): handlers = self.handlers.get(event_name, oset()) for handler in handlers: handler(ctx)
def add_listener(self, event_name, handler): handlers = self.handlers.get(event_name, oset()) handlers.add(handler) self.handlers[event_name] = handlers