comparison bot.py @ 211:3fe9fed07b64

created Bot.get_bridge(), it calls Bot.get_bridges() and raises exceptions when there are 0 or more than 1 matches Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Sat, 06 Mar 2010 18:32:46 +0100
parents a97a7e930697
children aa03c7ca53cb
comparison
equal deleted inserted replaced
210:fb0cf6bf9eab 211:3fe9fed07b64
757 if importance < 0 or importance >= len(say_levels.levels): 757 if importance < 0 or importance >= len(say_levels.levels):
758 raise Exception('[Internal Error] unknown message importance') 758 raise Exception('[Internal Error] unknown message importance')
759 return'['+str(say_levels.get(importance))+'] '+message 759 return'['+str(say_levels.get(importance))+'] '+message
760 760
761 761
762 def get_bridge(self, **kwargs):
763 """Calls self.get_bridges and raises exceptions when there are 0 or more than 1 matches
764
765 See Bot.get_bridges for the list of args"""
766
767 bridges = self.get_bridges(**kwargs)
768 if len(bridges) == 0:
769 raise Exception, 'no bridge matching '+str(kwargs)
770 elif len(bridges) > 1:
771 raise Exception, 'more than one bridge matching '+str(kwargs)+'\n'+'\n'.join([str(b) for b in bridges])
772 return bridges[0]
773
774
762 def get_bridges(self, irc_room=None, irc_server=None, xmpp_room_jid=None): 775 def get_bridges(self, irc_room=None, irc_server=None, xmpp_room_jid=None):
763 # TODO: lock self.bridges for thread safety 776 # TODO: lock self.bridges for thread safety
764 bridges = [b for b in self.bridges] 777 bridges = [b for b in self.bridges]
765 for bridge in [b for b in bridges]: 778 for bridge in [b for b in bridges]:
766 if irc_room != None and bridge.irc_room != irc_room: 779 if irc_room != None and bridge.irc_room != irc_room: