def __init__(self, name):
self.hooks = {}
- self.numhooks = {}
self.chanhooks = {}
+ self.exceptionhooks = []
+ self.numhooks = {}
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)
- for num, func in self.numhooks.items():
- self.parent.hooknum(num, func)
+ parent.hook(cmd, func)
+ parent.hook("%s.%s" % (self.name, cmd), 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 num, func in self.numhooks.items():
+ parent.hooknum(num, func)
for func, args, kwargs in self.helps:
try:
for cmd, func in self.hooks.items():
parent.unhook(cmd, func)
parent.unhook("%s.%s" % (self.name, cmd), func)
- for num, func in self.numhooks.items():
- 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 num, func in self.numhooks.items():
+ parent.unhooknum(num, func)
for func, args, kwargs in self.helps:
try:
pass
return True
- def hooknum(self, num):
- def realhook(func):
- self.numhooks[str(num)] = func
- if self.parent is not None:
- self.parent.hooknum(str(num), func)
- return func
- return realhook
-
- def hookchan(self, chan, glevel=ANYONE, clevel=PUBLIC):
- def realhook(func):
- self.chanhooks[chan] = func
- if self.parent is not None:
- self.parent.hookchan(chan, func)
- return func
- return realhook
-
def hook(self, cmd=None, needchan=True, glevel=ANYONE, clevel=PUBLIC, wantchan=None):
if wantchan is None: wantchan = needchan
_cmd = cmd #save this since it gets wiped out...
return func
return realhook
+ def hookchan(self, chan, glevel=ANYONE, clevel=PUBLIC):
+ def realhook(func):
+ self.chanhooks[chan] = func
+ if self.parent is not None:
+ self.parent.hookchan(chan, func)
+ return func
+ return realhook
+
+ 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
+ if self.parent is not None:
+ self.parent.hooknum(str(num), func)
+ return func
+ return realhook
+
def mod(self, modname):
if self.parent is not None:
return self.parent.module(modname)