Mercurial > libervia-backend
diff src/plugins/plugin_xep_0045.py @ 594:e629371a28d3
Fix pep8 support in src/plugins.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 18 Jan 2013 17:55:35 +0100 |
parents | beaf6bec2fcd |
children | 98a962d0b23c |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0045.py Mon Jan 21 00:59:50 2013 +0100 +++ b/src/plugins/plugin_xep_0045.py Fri Jan 18 17:55:35 2013 +0100 @@ -36,53 +36,55 @@ from wokkel.subprotocols import XMPPHandler PLUGIN_INFO = { -"name": "XEP 0045 Plugin", -"import_name": "XEP-0045", -"type": "XEP", -"protocols": ["XEP-0045"], -"dependencies": [], -"main": "XEP_0045", -"handler": "yes", -"description": _("""Implementation of Multi-User Chat""") + "name": "XEP 0045 Plugin", + "import_name": "XEP-0045", + "type": "XEP", + "protocols": ["XEP-0045"], + "dependencies": [], + "main": "XEP_0045", + "handler": "yes", + "description": _("""Implementation of Multi-User Chat""") } + class UnknownRoom(Exception): pass + class XEP_0045(object): def __init__(self, host): info(_("Plugin XEP_0045 initialization")) self.host = host - self.clients={} + self.clients = {} host.bridge.addMethod("joinMUC", ".plugin", in_sign='ssa{ss}s', out_sign='', method=self._join) host.bridge.addMethod("mucNick", ".plugin", in_sign='sss', out_sign='', method=self.mucNick) host.bridge.addMethod("mucLeave", ".plugin", in_sign='ss', out_sign='', method=self.leave) host.bridge.addMethod("getRoomsJoined", ".plugin", in_sign='s', out_sign='a(sass)', method=self.getRoomsJoined) host.bridge.addMethod("getRoomsSubjects", ".plugin", in_sign='s', out_sign='a(ss)', method=self.getRoomsSubjects) host.bridge.addMethod("getUniqueRoomName", ".plugin", in_sign='s', out_sign='s', method=self.getUniqueName) - host.bridge.addSignal("roomJoined", ".plugin", signature='sasss') #args: room_jid, room_nicks, user_nick, profile - host.bridge.addSignal("roomLeft", ".plugin", signature='ss') #args: room_jid, profile - host.bridge.addSignal("roomUserJoined", ".plugin", signature='ssa{ss}s') #args: room_jid, user_nick, user_data, profile - host.bridge.addSignal("roomUserLeft", ".plugin", signature='ssa{ss}s') #args: room_jid, user_nick, user_data, profile - host.bridge.addSignal("roomUserChangedNick", ".plugin", signature='ssss') #args: room_jid, old_nick, new_nick, profile - host.bridge.addSignal("roomNewSubject", ".plugin", signature='sss') #args: room_jid, subject, profile - + host.bridge.addSignal("roomJoined", ".plugin", signature='sasss') # args: room_jid, room_nicks, user_nick, profile + host.bridge.addSignal("roomLeft", ".plugin", signature='ss') # args: room_jid, profile + host.bridge.addSignal("roomUserJoined", ".plugin", signature='ssa{ss}s') # args: room_jid, user_nick, user_data, profile + host.bridge.addSignal("roomUserLeft", ".plugin", signature='ssa{ss}s') # args: room_jid, user_nick, user_data, profile + host.bridge.addSignal("roomUserChangedNick", ".plugin", signature='ssss') # args: room_jid, old_nick, new_nick, profile + host.bridge.addSignal("roomNewSubject", ".plugin", signature='sss') # args: room_jid, subject, profile def __check_profile(self, profile): """check if profile is used and connected if profile known but disconnected, remove it from known profiles @param profile: profile to check @return: True if the profile is known and connected, else False""" - if not profile or not self.clients.has_key(profile) or not self.host.isConnected(profile): - error (_('Unknown or disconnected profile (%s)') % profile) - if self.clients.has_key(profile): + if not profile or profile not in self.clients or not self.host.isConnected(profile): + error(_('Unknown or disconnected profile (%s)') % profile) + if profile in self.clients: del self.clients[profile] return False return True def __room_joined(self, room, profile): """Called when the user is in the requested room""" + def _sendBridgeSignal(ignore=None): self.host.bridge.roomJoined(room.roomJID.userhost(), [user.nick for user in room.roster.values()], room.nick, profile) @@ -99,16 +101,15 @@ _sendBridgeSignal() return room - def __err_joining_room(self, failure, room_jid, nick, history_options, password, profile): """Called when something is going wrong when joining the room""" if failure.value.condition == 'conflict': # we have a nickname conflict, we try again with "_" suffixed to current nickname nick += '_' - return self.clients[profile].join(room_jid, nick, history_options, password).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile':profile}, errbackArgs=[room_jid, nick, history_options, password, profile]) + return self.clients[profile].join(room_jid, nick, history_options, password).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile': profile}, errbackArgs=[room_jid, nick, history_options, password, profile]) mess = _("Error when joining the room") - error (mess) + error(mess) self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile) raise failure @@ -128,7 +129,7 @@ @profile_key: profile @return: nick or empty string in case of error""" profile = self.host.memory.getProfileName(profile_key) - if not self.__check_profile(profile) or not self.clients[profile].joined_rooms.has_key(room_jid_s): + if not self.__check_profile(profile) or room_jid_s not in self.clients[profile].joined_rooms: return '' return self.clients[profile].joined_rooms[room_jid_s].nick @@ -137,7 +138,7 @@ profile = self.host.memory.getProfileName(profile) if not self.__check_profile(profile): raise exceptions.UnknownProfileError("Unknown or disconnected profile") - if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()): + if room_jid.userhost() not in self.clients[profile].joined_rooms: raise UnknownRoom("This room has not been joined") return self.clients[profile].joined_rooms[room_jid.userhost()].inRoster(nick) @@ -155,7 +156,7 @@ return uuid.uuid1() def join(self, room_jid, nick, options, profile_key='@DEFAULT@'): - def _errDeferred(exc_obj = Exception, txt='Error while joining room'): + def _errDeferred(exc_obj=Exception, txt='Error while joining room'): d = defer.Deferred() d.errback(exc_obj(txt)) return d @@ -163,15 +164,15 @@ profile = self.host.memory.getProfileName(profile_key) if not self.__check_profile(profile): return _errDeferred() - if self.clients[profile].joined_rooms.has_key(room_jid.userhost()): - warning(_('%(profile)s is already in room %(room_jid)s') % {'profile':profile, 'room_jid':room_jid.userhost()}) + if room_jid.userhost() in self.clients[profile].joined_rooms: + warning(_('%(profile)s is already in room %(room_jid)s') % {'profile': profile, 'room_jid': room_jid.userhost()}) return _errDeferred() - info (_("[%(profile)s] is joining room %(room)s with nick %(nick)s") % {'profile':profile,'room':room_jid.userhost(), 'nick':nick}) + info(_("[%(profile)s] is joining room %(room)s with nick %(nick)s") % {'profile': profile, 'room': room_jid.userhost(), 'nick': nick}) - history_options = options["history"] == "True" if options.has_key("history") else None - password = options["password"] if options.has_key("password") else None + history_options = options["history"] == "True" if "history" in options else None + password = options["password"] if "password" in options else None - return self.clients[profile].join(room_jid, nick, history_options, password).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile':profile}, errbackArgs=[room_jid, nick, history_options, password, profile]) + return self.clients[profile].join(room_jid, nick, history_options, password).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile': profile}, errbackArgs=[room_jid, nick, history_options, password, profile]) def _join(self, room_jid_s, nick, options={}, profile_key='@DEFAULT@'): """join method used by bridge: use the _join method, but doesn't return any deferred""" @@ -186,13 +187,13 @@ self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile) return d = self.join(room_jid, nick, options, profile) - d.addErrback(lambda x: warning(_('Error while joining room'))) #TODO: error management + signal in bridge + d.addErrback(lambda x: warning(_('Error while joining room'))) # TODO: error management + signal in bridge def nick(self, room_jid, nick, profile_key): profile = self.host.memory.getProfileName(profile_key) if not self.__check_profile(profile): raise exceptions.UnknownProfileError("Unknown or disconnected profile") - if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()): + if room_jid.userhost() not in self.clients[profile].joined_rooms: raise UnknownRoom("This room has not been joined") return self.clients[profile].nick(room_jid, nick) @@ -200,7 +201,7 @@ profile = self.host.memory.getProfileName(profile_key) if not self.__check_profile(profile): raise exceptions.UnknownProfileError("Unknown or disconnected profile") - if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()): + if room_jid.userhost() not in self.clients[profile].joined_rooms: raise UnknownRoom("This room has not been joined") return self.clients[profile].leave(room_jid) @@ -208,7 +209,7 @@ profile = self.host.memory.getProfileName(profile_key) if not self.__check_profile(profile): raise exceptions.UnknownProfileError("Unknown or disconnected profile") - if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()): + if room_jid.userhost() not in self.clients[profile].joined_rooms: raise UnknownRoom("This room has not been joined") return self.clients[profile].subject(room_jid, subject) @@ -232,9 +233,9 @@ self.plugin_parent = plugin_parent self.host = plugin_parent.host muc.MUCClient.__init__(self) - self.joined_rooms = {} #FIXME: seem to do the same thing as MUCClient's _rooms attribute, must be removed + self.joined_rooms = {} # FIXME: seem to do the same thing as MUCClient's _rooms attribute, must be removed self.rec_subjects = {} - self.__changing_nicks = set() # used to keep trace of who is changing nick, + self.__changing_nicks = set() # used to keep trace of who is changing nick, # and to discard userJoinedRoom signal in this case print "init SatMUCClient OK" @@ -271,35 +272,35 @@ if user.nick in self.__changing_nicks: self.__changing_nicks.remove(user.nick) else: - debug (_("user %(nick)s has joined room (%(room_id)s)") % {'nick':user.nick, 'room_id':room.occupantJID.userhost()}) + debug(_("user %(nick)s has joined room (%(room_id)s)") % {'nick': user.nick, 'room_id': room.occupantJID.userhost()}) if not self.host.trigger.point("MUC user joined", room, user, self.parent.profile): return - user_data={'entity':user.entity.full() if user.entity else '', 'affiliation':user.affiliation, 'role':user.role} + user_data = {'entity': user.entity.full() if user.entity else '', 'affiliation': user.affiliation, 'role': user.role} self.host.bridge.roomUserJoined(room.roomJID.userhost(), user.nick, user_data, self.parent.profile) def userLeftRoom(self, room, user): if user.nick == room.nick: # we left the room room_jid_s = room.roomJID.userhost() - info (_("Room [%(room)s] left (%(profile)s))") % { "room": room_jid_s, - "profile": self.parent.profile }) + info(_("Room [%(room)s] left (%(profile)s))") % {"room": room_jid_s, + "profile": self.parent.profile}) self.host.memory.delEntityCache(room.roomJID, self.parent.profile) del self.plugin_parent.clients[self.parent.profile].joined_rooms[room_jid_s] self.host.bridge.roomLeft(room.roomJID.userhost(), self.parent.profile) else: - debug (_("user %(nick)s left room (%(room_id)s)") % {'nick':user.nick, 'room_id':room.occupantJID.userhost()}) - user_data={'entity':user.entity.full() if user.entity else '', 'affiliation':user.affiliation, 'role':user.role} + debug(_("user %(nick)s left room (%(room_id)s)") % {'nick': user.nick, 'room_id': room.occupantJID.userhost()}) + user_data = {'entity': user.entity.full() if user.entity else '', 'affiliation': user.affiliation, 'role': user.role} self.host.bridge.roomUserLeft(room.roomJID.userhost(), user.nick, user_data, self.parent.profile) def userChangedNick(self, room, user, new_nick): - self.host.bridge.roomUserChangedNick(room.roomJID.userhost(), user.nick, new_nick, self.parent.profile) + self.host.bridge.roomUserChangedNick(room.roomJID.userhost(), user.nick, new_nick, self.parent.profile) def userUpdatedStatus(self, room, user, show, status): print("FIXME: MUC status not managed yet") #FIXME: def receivedSubject(self, room, user, subject): - debug (_("New subject for room (%(room_id)s): %(subject)s") % {'room_id':room.roomJID.full(),'subject':subject}) + debug(_("New subject for room (%(room_id)s): %(subject)s") % {'room_id': room.roomJID.full(), 'subject': subject}) self.rec_subjects[room.roomJID.userhost()] = (room.roomJID.userhost(), subject) self.host.bridge.roomNewSubject(room.roomJID.userhost(), subject, self.parent.profile) @@ -311,4 +312,3 @@ #def getDiscoItems(self, requestor, target, nodeIdentifier=''): #return [] -