def __init__(self, clazz): self.clazz = clazz flattened = AttrDict() self.flattened = flattened assert clazz is not None resolved_mro = inspect.getmro(clazz) for parentclass in reversed(resolved_mro): flattened.update(parentclass.__dict__) self._proxy_for = (clazz, ) init = flattened['__init__'] if _get_method_regs(init): raise NotInstantiableError( "%r: cannot register class %r for instantiation with listening __init__" % (self, clazz)) self.method_regs = set() self.registered = False for name, attribute in flattened.items(): regs = _get_method_regs(attribute) if regs: for reg in regs: self.method_regs.add((name, reg)) self.instance_methods = {} self.instances = {}
def fire(self, *contexts, **keywords): try: if not self.mainloop: return except AttributeError: raise AlreadyRunningError() from crow2.util import AttrDict event = AttrDict() for context in contexts + (keywords,): event.update(context) mainloop = self.mainloop # if a plugin tries to start the mainloop again, it should fail del self.mainloop mainloop(event) self.mainloop = mainloop
def _make_eventobj(self, *dicts, **keywords): """ Prepare the objects which will be passed into handlers """ event = AttrDict() for context_dict in dicts: event.update(context_dict) event.update(keywords) event.update({"calling_hook": self}) return event