+ def hooknum(self, word, handler):
+ try:
+ self.numhandlers[word].append(handler)
+ except:
+ self.numhandlers[word] = [handler]
+ def unhooknum(self, word, handler):
+ if word in self.numhandlers and handler in self.numhandlers[word]:
+ self.numhandlers[word].remove(handler)
+ def hasnumhook(self, word):
+ return word in self.numhandlers and len(self.numhandlers[word]) != 0
+ def getnumhook(self, word):
+ return self.numhandlers[word]
+
+ def hookchan(self, chan, handler):
+ try:
+ self.chanhandlers[chan].append(handler)
+ except:
+ self.chanhandlers[chan] = [handler]
+ def unhookchan(self, chan, handler):
+ if chan in self.chanhandlers and handler in self.chanhandlers[chan]:
+ self.chanhandlers[chan].remove(handler)
+ def haschanhook(self, chan):
+ return chan in self.chanhandlers and len(self.chanhandlers[chan]) != 0
+ def getchanhook(self, chan):
+ return self.chanhandlers[chan]
+
+
+class MyCursor(MySQLdb.cursors.DictCursor):
+ def execute(self, *args, **kwargs):
+ if 'norecurse' in kwargs:
+ norecurse = kwargs['norecurse']
+ del kwargs['norecurse']
+ else:
+ norecurse = False
+ main.log("[SQL]", "?", "MyCursor.execute(self, %s, %s)" % (', '.join([repr(i) for i in args]), ', '.join([str(key)+"="+repr(kwargs[key]) for key in kwargs])))
+# print "%09.3f [SQL] [#] MyCursor.execute(self, %s, %s)" % (time.time() % 100000, ', '.join([repr(i) for i in args]), ', '.join([str(key)+"="+repr(kwargs[key]) for key in kwargs]))
+ try:
+ return super(self.__class__, self).execute(*args, **kwargs)
+ except MySQLdb.MySQLError as e:
+ main.log("[SQL]", "!", "MySQL error! %r" % (e))
+# print "%09.3f [SQL] [!] MySQL error! %r" % (time.time() % 100000, e)
+ if not norecurse:
+ dbsetup()
+ return self.execute(norecurse=True, *args, **kwargs)
+ return False
+ return True
+
+
+def dbsetup():
+ main.db = None
+ main.db = MySQLdb.connect(host=cfg.dbhost, user=cfg.dbuser, passwd=cfg.dbpass, db=cfg.dbname, cursorclass=MyCursor)
+