self.hooks = {}
self.numhooks = {}
self.chanhooks = {}
+ self.exceptionhooks = []
self.helps = []
self.parent = None
#"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:
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:
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