comparison bot.py @ 100:6289ac5a2db7

Reconnect when a connection is closed Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Sun, 04 Oct 2009 23:47:09 +0200
parents 5390e9abfa44
children 29d3b85c6286
comparison
equal deleted inserted replaced
99:5390e9abfa44 100:6289ac5a2db7
103 pass 103 pass
104 except (xml.parsers.expat.ExpatError, xmpp.protocol.XMLNotWellFormed): 104 except (xml.parsers.expat.ExpatError, xmpp.protocol.XMLNotWellFormed):
105 self.error('=> Debug: invalid stanza', debug=True) 105 self.error('=> Debug: invalid stanza', debug=True)
106 unlock = True 106 unlock = True
107 except xmpp.Conflict: 107 except xmpp.Conflict:
108 c.reconnectAndReauth() 108 self.reopen_xmpp_connection(c)
109 for m in c.mucs:
110 m.rejoin()
111 unlock = True 109 unlock = True
112 except: 110 except:
113 error = '[Error] Unkonwn exception on XMPP thread:\n' 111 error = '[Error] Unkonwn exception on XMPP thread:\n'
114 error += traceback.format_exc() 112 error += traceback.format_exc()
115 self.error(error, send_to_admins=True) 113 self.error(error, send_to_admins=True)
641 c.sendInitPresence() 639 c.sendInitPresence()
642 c.lock.release() 640 c.lock.release()
643 return c 641 return c
644 642
645 643
644 def reopen_xmpp_connection(self, c):
645 if not isinstance(c, xmpp.client.Client):
646 return
647 mucs = c.mucs
648 nickname = c.nickname
649 used_by = c.used_by
650 participants = []
651 for b in self.bridges:
652 for p in b.participants:
653 if p.xmpp_c == c:
654 participants.append(p)
655 p.xmpp_c = None
656 self.error('===> Debug: reopening XMPP connection for "'+nickname+'"', debug=True)
657 self.xmpp_connections.pop(nickname)
658 c.send(xmpp.protocol.Presence(typ='unavailable'))
659 del c
660 c = self.get_xmpp_connection(nickname)
661 c.used_by = used_by
662 for p in participants:
663 p.xmpp_c = c
664 c.mucs = mucs
665 for m in c.mucs:
666 m.rejoin()
667
668
646 def close_xmpp_connection(self, nickname): 669 def close_xmpp_connection(self, nickname):
647 if not self.xmpp_connections.has_key(nickname): 670 if not self.xmpp_connections.has_key(nickname):
648 return 671 return
649 c = self.xmpp_connections[nickname] 672 c = self.xmpp_connections[nickname]
650 c.lock.acquire() 673 c.lock.acquire()