comparison bridge.py @ 203:2a81c480439a

renamed camelCased functions Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Thu, 25 Feb 2010 23:29:39 +0100
parents de574314990e
children 85a8b457c4b4
comparison
equal deleted inserted replaced
202:2a1ee46f86af 203:2a81c480439a
99 self._join_irc_failed(reason) 99 self._join_irc_failed(reason)
100 100
101 101
102 def _RemoteServerNotFound_handler(self): 102 def _RemoteServerNotFound_handler(self):
103 server = xmpp.protocol.JID(self.xmpp_room_jid).getDomain() 103 server = xmpp.protocol.JID(self.xmpp_room_jid).getDomain()
104 bridges = self.bot.findBridges([server]) 104 bridges = self.bot.find_bridges([server])
105 error = [say_levels.warning, 'The MUC server '+server+' seems to be down, the bot will try to recreate all bridges related to this server in 5 minutes'] 105 error = [say_levels.warning, 'The MUC server '+server+' seems to be down, the bot will try to recreate all bridges related to this server in 5 minutes']
106 self.bot.restart_bridges_delayed(bridges, 300, error) 106 self.bot.restart_bridges_delayed(bridges, 300, error)
107 107
108 108
109 def _xmpp_join_callback(self, errors): 109 def _xmpp_join_callback(self, errors):
127 trace = traceback.format_exc() 127 trace = traceback.format_exc()
128 self.bot.error(say_levels.error, 'failed to connect to the XMPP room of bridge "'+str(self)+'", stopping bridge\n'+trace, send_to_admins=True) 128 self.bot.error(say_levels.error, 'failed to connect to the XMPP room of bridge "'+str(self)+'", stopping bridge\n'+trace, send_to_admins=True)
129 self.stop(message='Failed to connect to the XMPP room, stopping bridge') 129 self.stop(message='Failed to connect to the XMPP room, stopping bridge')
130 130
131 131
132 def addParticipant(self, from_protocol, nickname, real_jid=None, irc_id=None): 132 def add_participant(self, from_protocol, nickname, real_jid=None, irc_id=None):
133 """Add a participant to the bridge.""" 133 """Add a participant to the bridge."""
134 if (from_protocol == 'irc' and nickname == self.bot.nickname) or (from_protocol == 'xmpp' and nickname == self.bot.nickname): 134 if (from_protocol == 'irc' and nickname == self.bot.nickname) or (from_protocol == 'xmpp' and nickname == self.bot.nickname):
135 self.bot.error(3, 'not adding self ('+self.bot.nickname+') to bridge "'+str(self)+'"', debug=True) 135 self.bot.error(3, 'not adding self ('+self.bot.nickname+') to bridge "'+str(self)+'"', debug=True)
136 return 136 return
137 try: 137 try:
138 p = self.getParticipant(nickname) 138 p = self.get_participant(nickname)
139 if p.protocol != from_protocol: 139 if p.protocol != from_protocol:
140 if from_protocol == 'irc' and isinstance(p.irc_connection, ServerConnection) and p.irc_connection.really_connected == True and p.irc_connection.real_nickname == nickname or from_protocol == 'xmpp' and isinstance(p.xmpp_c, xmpp.client.Client) and isinstance(p.muc, xmpp.muc) and p.xmpp_c.nickname == nickname: 140 if from_protocol == 'irc' and isinstance(p.irc_connection, ServerConnection) and p.irc_connection.really_connected == True and p.irc_connection.real_nickname == nickname or from_protocol == 'xmpp' and isinstance(p.xmpp_c, xmpp.client.Client) and isinstance(p.muc, xmpp.muc) and p.xmpp_c.nickname == nickname:
141 if irc_id: 141 if irc_id:
142 p.irc_connection.irc_id = irc_id 142 p.irc_connection.irc_id = irc_id
143 return p 143 return p
164 elif self.mode == 'minimal' and from_protocol == 'irc': 164 elif self.mode == 'minimal' and from_protocol == 'irc':
165 self.show_participants_list_on(protocols=['xmpp']) 165 self.show_participants_list_on(protocols=['xmpp'])
166 return p 166 return p
167 167
168 168
169 def createDuplicatesOn(self, protocols): 169 def create_duplicates_on(self, protocols):
170 for p in self.participants: 170 for p in self.participants:
171 if p.protocol == 'xmpp' and 'irc' in protocols: 171 if p.protocol == 'xmpp' and 'irc' in protocols:
172 p.createDuplicateOnIRC() 172 p.create_duplicate_on_irc()
173 elif p.protocol == 'irc' and 'xmpp' in protocols: 173 elif p.protocol == 'irc' and 'xmpp' in protocols:
174 p.createDuplicateOnXMPP() 174 p.create_duplicate_on_xmpp()
175 175
176 176
177 def changeMode(self, new_mode): 177 def change_mode(self, new_mode):
178 if new_mode == self.mode: 178 if new_mode == self.mode:
179 return 'Mode is already equal to '+self.mode 179 return 'Mode is already equal to '+self.mode
180 180
181 old_mode = self.mode 181 old_mode = self.mode
182 self.mode = new_mode 182 self.mode = new_mode
185 185
186 if new_mode in ['normal', 'bypass']: 186 if new_mode in ['normal', 'bypass']:
187 187
188 if old_mode == 'limited': 188 if old_mode == 'limited':
189 # From limited to {normal,bypass} 189 # From limited to {normal,bypass}
190 self.createDuplicatesOn(['irc']) 190 self.create_duplicates_on(['irc'])
191 191
192 elif old_mode in ['minimal', 'normal']: 192 elif old_mode in ['minimal', 'normal']:
193 # From {minimal,normal} to {normal,bypass} 193 # From {minimal,normal} to {normal,bypass}
194 self.createDuplicatesOn(['irc', 'xmpp']) 194 self.create_duplicates_on(['irc', 'xmpp'])
195 195
196 elif old_mode == 'bypass': 196 elif old_mode == 'bypass':
197 # From bypass to normal 197 # From bypass to normal
198 pass # Handled below 198 pass # Handled below
199 199
202 unhandled = True 202 unhandled = True
203 203
204 elif new_mode == 'limited': 204 elif new_mode == 'limited':
205 205
206 if old_mode == 'minimal': 206 if old_mode == 'minimal':
207 self.createDuplicatesOn(['xmpp']) 207 self.create_duplicates_on(['xmpp'])
208 208
209 i = 0 209 i = 0
210 for p in self.participants: 210 for p in self.participants:
211 if p.protocol == 'xmpp': 211 if p.protocol == 'xmpp':
212 i += 1 212 i += 1
233 p.leave('Bridge is switching to '+new_mode+' mode') 233 p.leave('Bridge is switching to '+new_mode+' mode')
234 234
235 self.say(say_levels.notice, 'Bridge is switching from '+old_mode+' to '+new_mode+' mode.', log=True) 235 self.say(say_levels.notice, 'Bridge is switching from '+old_mode+' to '+new_mode+' mode.', log=True)
236 236
237 237
238 def getParticipant(self, nickname): 238 def get_participant(self, nickname):
239 """Returns a participant object if there is a participant using nickname in the bridge. Raises a NoSuchParticipantException otherwise.""" 239 """Returns a participant object if there is a participant using nickname in the bridge. Raises a NoSuchParticipantException otherwise."""
240 self.lock.acquire() 240 self.lock.acquire()
241 for p in self.participants: 241 for p in self.participants:
242 if nickname in [p.nickname, p.duplicate_nickname]: 242 if nickname in [p.nickname, p.duplicate_nickname]:
243 self.lock.release() 243 self.lock.release()
255 participants_nicknames.append('"'+p.nickname+'"') 255 participants_nicknames.append('"'+p.nickname+'"')
256 self.lock.release() 256 self.lock.release()
257 return participants_nicknames 257 return participants_nicknames
258 258
259 259
260 def hasParticipant(self, nickname): 260 def has_participant(self, nickname):
261 try: 261 try:
262 self.getParticipant(nickname) 262 self.get_participant(nickname)
263 return True 263 return True
264 except self.NoSuchParticipantException: 264 except self.NoSuchParticipantException:
265 return False 265 return False
266 266
267 267
268 def removeParticipant(self, left_protocol, nickname, leave_message): 268 def remove_participant(self, left_protocol, nickname, leave_message):
269 """Remove the participant using nickname from the bridge. Raises a NoSuchParticipantException if nickname is not used in the bridge.""" 269 """Remove the participant using nickname from the bridge. Raises a NoSuchParticipantException if nickname is not used in the bridge."""
270 270
271 was_on_both = None 271 was_on_both = None
272 p = self.getParticipant(nickname) 272 p = self.get_participant(nickname)
273 273
274 if p.left: 274 if p.left:
275 self.lock.acquire() 275 self.lock.acquire()
276 self.participants.remove(p) 276 self.participants.remove(p)
277 del p 277 del p
281 if p.protocol == 'xmpp': 281 if p.protocol == 'xmpp':
282 if p.irc_connection == 'both': 282 if p.irc_connection == 'both':
283 was_on_both = True 283 was_on_both = True
284 if left_protocol == 'xmpp': 284 if left_protocol == 'xmpp':
285 p.protocol = 'irc' 285 p.protocol = 'irc'
286 p.createDuplicateOnXMPP() 286 p.create_duplicate_on_xmpp()
287 elif left_protocol == 'irc': 287 elif left_protocol == 'irc':
288 p.createDuplicateOnIRC() 288 p.create_duplicate_on_irc()
289 else: 289 else:
290 if left_protocol == 'xmpp': 290 if left_protocol == 'xmpp':
291 was_on_both = False 291 was_on_both = False
292 elif left_protocol == 'irc': 292 elif left_protocol == 'irc':
293 # got disconnected somehow 293 # got disconnected somehow
295 p.irc_connection.join(self.irc_room) 295 p.irc_connection.join(self.irc_room)
296 else: 296 else:
297 c = self.bot.irc.get_connection(self.irc_server, self.irc_port, p.duplicate_nickname) 297 c = self.bot.irc.get_connection(self.irc_server, self.irc_port, p.duplicate_nickname)
298 if not (c and self.irc_room in c.left_channels): 298 if not (c and self.irc_room in c.left_channels):
299 p._close_irc_connection(leave_message) 299 p._close_irc_connection(leave_message)
300 p.createDuplicateOnIRC() 300 p.create_duplicate_on_irc()
301 return 301 return
302 302
303 elif p.protocol == 'irc': 303 elif p.protocol == 'irc':
304 if p.xmpp_c == 'both': 304 if p.xmpp_c == 'both':
305 was_on_both = True 305 was_on_both = True
306 if left_protocol == 'irc': 306 if left_protocol == 'irc':
307 p.protocol = 'xmpp' 307 p.protocol = 'xmpp'
308 p.createDuplicateOnIRC() 308 p.create_duplicate_on_irc()
309 elif left_protocol == 'xmpp': 309 elif left_protocol == 'xmpp':
310 p.createDuplicateOnXMPP() 310 p.create_duplicate_on_xmpp()
311 else: 311 else:
312 if left_protocol == 'irc': 312 if left_protocol == 'irc':
313 was_on_both = False 313 was_on_both = False
314 elif left_protocol == 'xmpp': 314 elif left_protocol == 'xmpp':
315 # got disconnected somehow 315 # got disconnected somehow