X-Git-Url: https://jfr.im/git/erebus.git/blobdiff_plain/25bf8fc584941be94d96d281f1a15d622e4e9b8f..92da6dea5d37a76b9ecfe5dec365c14c0574ddb0:/modlib.py diff --git a/modlib.py b/modlib.py index ae19fb5..b09272e 100644 --- a/modlib.py +++ b/modlib.py @@ -62,6 +62,7 @@ class modlib(object): self.hooks = {} self.numhooks = {} self.chanhooks = {} + self.exceptionhooks = [] self.helps = [] self.parent = None @@ -77,12 +78,14 @@ class modlib(object): #"specified" values will be printed. unspecified values will result in "OK" or "failed" self.parent = parent for cmd, func in self.hooks.items(): - self.parent.hook(cmd, func) - self.parent.hook("%s.%s" % (self.name, cmd), func) + parent.hook(cmd, func) + parent.hook("%s.%s" % (self.name, cmd), func) for num, func in self.numhooks.items(): - self.parent.hooknum(num, func) + parent.hooknum(num, func) for chan, func in self.chanhooks.items(): - self.parent.hookchan(chan, func) + parent.hookchan(chan, func) + for exc, func in self.exceptionhooks: + parent.hookexception(exc, func) for func, args, kwargs in self.helps: try: @@ -98,6 +101,8 @@ class modlib(object): parent.unhooknum(num, func) for chan, func in self.chanhooks.items(): parent.unhookchan(chan, func) + for exc, func in self.exceptionhooks: + parent.unhookexception(exc, func) for func, args, kwargs in self.helps: try: @@ -106,6 +111,14 @@ class modlib(object): pass return True + def hookexception(self, exc): + def realhook(func): + self.exceptionhooks.append((exc, func)) + if self.parent is not None: + self.parent.hookexception(exc, func) + return func + return realhook + def hooknum(self, num): def realhook(func): self.numhooks[str(num)] = func