def remove_handler(self, handler): if handler not in self._handlerobjects.keys(): raise MissingHandlerObject(handler) if self._handlerobjects[handler] > 0: raise LingeringDependency(handler) del self._handlerobjects[handler] dependencies, h_funcs = util.get_handler_properties(handler) for dep in dependencies: sat = self.dependency_satisfier(dep) if not sat: raise InvalidDependencyTree(dep) else: # Decrement refcount. self._handlerobjects[sat] -= 1 if self._handlerobjects[sat] < 0: raise InvalidDependencyTree(sat) for h_name in h_funcs.iterkeys(): self._handlers[h_name] -= set([h_funcs[h_name]]) # If there aren't any handler functions left, remove that event entirely. if not self._handlers[h_name]: del self._handlers[h_name] # Special - spawn just this instance of client_unload. if h_funcs.has_key('client_unload'): self._group.spawn(h_funcs['client_unload'], self)
def add_handler(self, handler): if handler in self._handlerobjects.keys(): raise DuplicateHandlerObject(item) dependencies, h_funcs = util.get_handler_properties(handler) for dep in dependencies: sat = self.dependency_satisfier(dep) if not sat: raise UnsatisfiedDependency(dep) else: # Increment refcount. self._handlerobjects[sat] += 1 self._handlerobjects[handler] = 0 for h_name in h_funcs.iterkeys(): if self._handlers.has_key(h_name): self._handlers[h_name].add(h_funcs[h_name]) else: self._handlers[h_name] = set([h_funcs[h_name]]) # Special - spawn just this instance, not all "client_load" handlers. if h_funcs.has_key('client_load'): self._group.spawn(h_funcs['client_load'], self)