]> jfr.im git - erebus.git/blobdiff - erebus.py
core - add exception hooks
[erebus.git] / erebus.py
index 42a2f416cefef07c20fdcfc3935431a63934ec9a..91e01bfad02c4e91e0ac47c924811315ef3882c4 100644 (file)
--- a/erebus.py
+++ b/erebus.py
@@ -18,6 +18,7 @@ class Erebus(object): #singleton to pass around
        numhandlers = {}
        msghandlers = {}
        chanhandlers = {}
+       exceptionhandlers = [] # list of (Exception_class, handler_function) tuples
        users = {}
        chans = {}
 
@@ -315,6 +316,15 @@ class Erebus(object): #singleton to pass around
        def getchanhook(self, chan):
                return self.chanhandlers[chan]
 
+       def hookexception(self, exc, handler):
+               self.exceptionhandlers.append((exc, handler))
+       def unhookexception(self, exc, handler):
+               self.exceptionhandlers.remove((exc, handler))
+       def hasexceptionhook(self, exc):
+               return any((True for x,h in self.exceptionhandlers if isinstance(exc, x)))
+       def getexceptionhook(self, exc):
+               return (h for x,h in self.exceptionhandlers if isinstance(exc, x))
+
 
 def dbsetup():
        main.db = None