Changeset 132:1b19c49d30c2 for wokkel


Ignore:
Timestamp:
Aug 21, 2009, 2:46:18 PM (11 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
wokkel-muc-client-support-24
Message:

More renames.

Location:
wokkel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wokkel/muc.py

    r131 r132  
    352352
    353353        @param to: The xmpp entity you are sending this chat to.
    354         @type to: L{unicode} or L{jid.JID}
     354        @type to: C{unicode} or L{jid.JID}
    355355
    356356        @param body: The message you are sending.
    357         @type body: L{unicode}
     357        @type body: C{unicode}
    358358
    359359        @param frm: The entity that is sending the message.
    360         @param frm: L{unicode}
     360        @param frm: C{unicode}
    361361        """
    362362        domish.Element.__init__(self, (None, 'message'))
     
    374374
    375375class InviteMessage(domish.Element):
    376     def __init__(self, bareRoomJID, invitee, reason=None):
     376    def __init__(self, roomJID, invitee, reason=None):
    377377        domish.Element.__init__(self, (None, 'message'))
    378         self['to'] = unicode(bareRoomJID)
     378        self['to'] = unicode(roomJID)
    379379        x = self.addElement('x', NS_MUC_USER)
    380380        invite = x.addElement('invite')
     
    468468
    469469        @ivar roomIdentifier: The Room ID of the MUC room.
    470         @type roomIdentifier: L{unicode}
     470        @type roomIdentifier: C{unicode}
    471471
    472472        @ivar service: The server where the MUC room is located.
    473         @type service: L{unicode}
     473        @type service: C{unicode}
    474474
    475475        @ivar nick: The nick name for the client in this room.
    476         @type nick: L{unicode}
     476        @type nick: C{unicode}
    477477
    478478        @ivar state: The status code of the room.
    479479        @type state: L{int}
    480480
    481         @ivar roomJID: The JID of the occupant in the room. Generated from roomIdentifier, service, and nick.
    482         @type roomJID: L{jid.JID}
     481        @ivar occupantJID: The JID of the occupant in the room. Generated from roomIdentifier, service, and nick.
     482        @type occupantJID: L{jid.JID}
    483483        """
    484484        self.state = state
     
    488488        self.status = 0
    489489
    490         self.roomJID = self.refreshRoomJID()
     490        self.occupantJID = self.refreshOccupantJID()
    491491
    492492        self.roster = {}
    493493
    494494
    495     def refreshRoomJID(self):
     495    def refreshOccupantJID(self):
    496496        """
    497497        Refreshes the Room JID.
     
    500500        change.
    501501        """
    502         self.roomJID = jid.internJID(u"%s@%s/%s" % (self.roomIdentifier,
     502        self.occupantJID = jid.internJID(u"%s@%s/%s" % (self.roomIdentifier,
    503503                                                    self.service,
    504504                                                    self.nick))
    505         return self.roomJID
     505        return self.occupantJID
    506506
    507507
     
    532532
    533533        @param nick: The nick for the user in the MUC room.
    534         @type nick: L{unicode}
     534        @type nick: C{unicode}
    535535        """
    536536        return self.roster.get(nick.lower())
     
    689689        @note: An entity can only join a particular room once.
    690690        """
    691         bareRoomJID = room.roomJID.userhostJID()
    692         self._rooms[bareRoomJID] = room
    693 
    694 
    695     def _getRoom(self, roomJID):
     691        roomJID = room.occupantJID.userhostJID()
     692        self._rooms[roomJID] = room
     693
     694
     695    def _getRoom(self, occupantJID):
    696696        """
    697697        Grab a room from the room collection.
     
    700700        the L{Room} instance associated with it.
    701701        """
    702         bareRoomJID = roomJID.userhostJID()
    703         return self._rooms.get(bareRoomJID)
    704 
    705 
    706     def _removeRoom(self, roomJID):
     702        roomJID = occupantJID.userhostJID()
     703        return self._rooms.get(roomJID)
     704
     705
     706    def _removeRoom(self, occupantJID):
    707707        """
    708708        Delete a room from the room collection.
    709709        """
    710         bareRoomJID = roomJID.userhostJID()
    711         if bareRoomJID in self._rooms:
    712             del self._rooms[bareRoomJID]
     710        roomJID = occupantJID.userhostJID()
     711        if roomJID in self._rooms:
     712            del self._rooms[roomJID]
    713713
    714714
     
    722722        if not prs.hasAttribute('from'):
    723723            return
    724         roomJID = jid.internJID(prs.getAttribute('from', ''))
    725         self._userLeavesRoom(roomJID)
     724        occupantJID = jid.internJID(prs.getAttribute('from', ''))
     725        self._userLeavesRoom(occupantJID)
    726726
    727727
     
    733733        if not prs.hasAttribute('from'):
    734734            return
    735         roomJID = jid.internJID(prs.getAttribute('from', ''))
     735        occupantJID = jid.internJID(prs.getAttribute('from', ''))
    736736        # add an error hook here?
    737         self._userLeavesRoom(roomJID)
     737        self._userLeavesRoom(occupantJID)
    738738
    739739
     
    750750
    751751
    752     def _userLeavesRoom(self, roomJID):
     752    def _userLeavesRoom(self, occupantJID):
    753753        # when a user leaves a room we need to update it
    754         room = self._getRoom(roomJID)
     754        room = self._getRoom(occupantJID)
    755755        if room is None:
    756756            # not in the room yet
    757757            return
    758758        # check if user is in roster
    759         user = room.getUser(roomJID.resource)
     759        user = room.getUser(occupantJID.resource)
    760760        if user is None:
    761761            return
     
    771771        if not prs.hasAttribute('from'):
    772772            return
    773         roomJID = jid.internJID(prs.getAttribute('from', ''))
     773        occupantJID = jid.internJID(prs.getAttribute('from', ''))
    774774
    775775        status = getattr(prs, 'status', None)
     
    777777
    778778        # grab room
    779         room = self._getRoom(roomJID)
     779        room = self._getRoom(occupantJID)
    780780        if room is None:
    781781            # not in the room yet
    782782            return
    783         user = self._changeUserStatus(room, roomJID, status, show)
     783        user = self._changeUserStatus(room, occupantJID, status, show)
    784784
    785785        if room.inRoster(user):
     
    804804            # need to return an error here
    805805            return
    806         roomJID = jid.internJID(msg.getAttribute('from', ''))
    807 
    808         room = self._getRoom(roomJID)
     806        occupantJID = jid.internJID(msg.getAttribute('from', ''))
     807
     808        room = self._getRoom(occupantJID)
    809809        if room is None:
    810810            # not in the room yet
    811811            return
    812         user = room.getUser(roomJID.resource)
     812        user = room.getUser(occupantJID.resource)
    813813        delay = None
    814814        # need to check for delay and x stanzas for delay namespace for backwards compatability
     
    830830        if not msg.hasAttribute('from'):
    831831            return
    832         roomJID = jid.internJID(msg['from'])
     832        occupantJID = jid.internJID(msg['from'])
    833833
    834834        # grab room
    835         room = self._getRoom(roomJID)
     835        room = self._getRoom(occupantJID)
    836836        if room is None:
    837837            # not in the room yet
    838838            return
    839839
    840         self.receivedSubject(roomJID, unicode(msg.subject))
     840        self.receivedSubject(occupantJID, unicode(msg.subject))
    841841
    842842
     
    853853        We have presence that says we joined a room.
    854854        """
    855         roomJID = jid.internJID(prs['from'])
     855        occupantJID = jid.internJID(prs['from'])
    856856
    857857        # check for errors
     
    860860        else:
    861861            # change the state of the room
    862             room = self._getRoom(roomJID)
     862            room = self._getRoom(occupantJID)
    863863            if room is None:
    864864                raise NotFound
     
    877877        We have presence that says we left a room.
    878878        """
    879         roomJID = jid.internJID(prs['from'])
     879        occupantJID = jid.internJID(prs['from'])
    880880
    881881        # check for errors
     
    884884        else:
    885885            # change the state of the room
    886             room = self._getRoom(roomJID)
     886            room = self._getRoom(occupantJID)
    887887            if room is None:
    888888                raise NotFound
    889             self._removeRoom(roomJID)
     889            self._removeRoom(occupantJID)
    890890
    891891            d.callback(True)
     
    968968
    969969        @param obj: The object to send over the wire.
    970         @type obj: L{domish.Element} or L{unicode}
     970        @type obj: L{domish.Element} or C{unicode}
    971971
    972972        @param timeout: The number of seconds to wait before the deferred is timed out.
     
    10011001
    10021002
    1003     def configure(self, bareRoomJID, fields=[]):
     1003    def configure(self, roomJID, fields=[]):
    10041004        """
    10051005        Configure a room.
    10061006
    1007         @param bareRoomJID: The bare JID of the room.
    1008         @type bareRoomJID: L{jid.JID}
     1007        @param roomJID: The bare JID of the room.
     1008        @type roomJID: L{jid.JID}
    10091009
    10101010        @param fields: The fields we want to modify.
     
    10121012        """
    10131013        request = ConfigureRequest(self.xmlstream, method='set', fields=fields)
    1014         request['to'] = bareRoomJID
     1014        request['to'] = roomJID
    10151015
    10161016        return request.send()
    10171017
    10181018
    1019     def getConfigureForm(self, bareRoomJID):
     1019    def getConfigureForm(self, roomJID):
    10201020        """
    10211021        Grab the configuration form from the room. This sends an iq request to the room.
    10221022
    1023         @param bareRoomJID: The bare JID of the room.
    1024         @type bareRoomJID: L{jid.JID}
     1023        @param roomJID: The bare JID of the room.
     1024        @type roomJID: L{jid.JID}
    10251025        """
    10261026        request = ConfigureRequest(self.xmlstream)
    1027         request['to'] = bareRoomJID
     1027        request['to'] = roomJID
    10281028        return request.send()
    10291029
     
    10341034
    10351035        @param server: The server where the room is located.
    1036         @type server: L{unicode}
     1036        @type server: C{unicode}
    10371037
    10381038        @param room: The room name the entity is joining.
    1039         @type room: L{unicode}
     1039        @type room: C{unicode}
    10401040
    10411041        @param nick: The nick name for the entitity joining the room.
    1042         @type nick: L{unicode}
     1042        @type nick: C{unicode}
    10431043
    10441044        @param history: The maximum number of history stanzas you would like.
     
    10501050        self._addRoom(room)
    10511051
    1052         p = BasicPresence(to=room.roomJID)
     1052        p = BasicPresence(to=room.occupantJID)
    10531053        if history is not None:
    10541054            p.x.addChild(history.toElement())
     
    10571057
    10581058        # add observer for joining the room
    1059         query = PRESENCE + u"[@from='%s']" % room.roomJID
     1059        query = PRESENCE + u"[@from='%s']" % room.occupantJID
    10601060        self.xmlstream.addOnetimeObserver(query, self._joinedRoom, 1, d)
    10611061
     
    10631063
    10641064
    1065     def _changeUserStatus(self, room, roomJID, status, show):
     1065    def _changeUserStatus(self, room, occupantJID, status, show):
    10661066        """
    10671067        Change the user status in a room.
     
    10691069
    10701070        # check if user is in roster
    1071         user = room.getUser(roomJID.resource)
     1071        user = room.getUser(occupantJID.resource)
    10721072        if user is None: # create a user that does not exist
    1073             user = User(roomJID.resource)
     1073            user = User(occupantJID.resource)
    10741074
    10751075        if status is not None:
     
    10811081
    10821082
    1083     def _changed(self, d, roomJID, prs):
     1083    def _changed(self, d, occupantJID, prs):
    10841084        """
    10851085        Callback for changing the nick and status.
     
    10891089        show = getattr(prs, 'show', None)
    10901090
    1091         room = self._getRoom(roomJID)
    1092 
    1093         user = self._changeUserStatus(room, roomJID, status, show)
     1091        room = self._getRoom(occupantJID)
     1092
     1093        user = self._changeUserStatus(room, occupantJID, status, show)
    10941094
    10951095        d.callback(room)
    10961096
    10971097
    1098     def nick(self, bareRoomJID, new_nick):
     1098    def nick(self, roomJID, new_nick):
    10991099        """
    11001100        Change an entities nick name in a MUC room.
     
    11021102        See: http://xmpp.org/extensions/xep-0045.html#changenick
    11031103
    1104         @param bareRoomJID: The JID of the room, i.e. without a resource.
    1105         @type bareRoomJID: L{jid.JID}
     1104        @param roomJID: The JID of the room, i.e. without a resource.
     1105        @type roomJID: L{jid.JID}
    11061106
    11071107        @param new_nick: The nick name for the entitity joining the room.
    1108         @type new_nick: L{unicode}
    1109         """
    1110 
    1111 
    1112         room = self._getRoom(bareRoomJID)
    1113         if room is None:
    1114             raise NotFound
    1115 
    1116         # Change the nickname
    1117         room.nick = new_nick
    1118         room.refreshRoomJID()
    1119 
    1120         # Create presence
    1121         p = BasicPresence(to=room.roomJID)
    1122         d = self.sendDeferred(p, timeout=DEFER_TIMEOUT)
    1123 
    1124         # Add observer for joining the room
    1125         query = PRESENCE+"[@from='%s']" % (room.roomJID.full())
    1126         self.xmlstream.addOnetimeObserver(query, self._changed, 1, d, bareRoomJID)
    1127 
    1128         return d
    1129 
    1130 
    1131     def leave(self, roomJID):
    1132         """
    1133         Leave a MUC room.
    1134 
    1135         See: http://xmpp.org/extensions/xep-0045.html#exit
    1136 
    1137         @param roomJID: The Room JID of the room to leave.
    1138         @type roomJID: L{jid.JID}
    1139         """
    1140         room = self._getRoom(roomJID)
    1141 
    1142         p = xmppim.UnavailablePresence(to=room.roomJID)
    1143 
    1144         d = self.sendDeferred(p, timeout=DEFER_TIMEOUT)
    1145         # add observer for joining the room
    1146         query = PRESENCE + u"[@from='%s' and @type='unavailable']" % (room.roomJID)
    1147         self.xmlstream.addOnetimeObserver(query, self._leftRoom, 1, d)
    1148 
    1149         return d
    1150 
    1151 
    1152     def status(self, roomJID, show=None, status=None):
    1153         """
    1154         Change user status.
    1155 
    1156         See: http://xmpp.org/extensions/xep-0045.html#changepres
    1157 
    1158         @param roomJID: The room jabber/xmpp entity id for the requested configuration form.
    1159         @type roomJID: L{jid.JID}
    1160 
    1161         @param show: The availability of the entity. Common values are xa, available, etc
    1162         @type show: L{unicode}
    1163 
    1164         @param show: The current status of the entity.
    1165         @type show: L{unicode}
    1166         """
     1108        @type new_nick: C{unicode}
     1109        """
     1110
     1111
    11671112        room = self._getRoom(roomJID)
    11681113        if room is None:
    11691114            raise NotFound
    11701115
    1171         p = BasicPresence(to=room.roomJID)
     1116        # Change the nickname
     1117        room.nick = new_nick
     1118        room.refreshOccupantJID()
     1119
     1120        # Create presence
     1121        p = BasicPresence(to=room.occupantJID)
     1122        d = self.sendDeferred(p, timeout=DEFER_TIMEOUT)
     1123
     1124        # Add observer for joining the room
     1125        query = PRESENCE+"[@from='%s']" % (room.occupantJID.full())
     1126        self.xmlstream.addOnetimeObserver(query, self._changed, 1, d, roomJID)
     1127
     1128        return d
     1129
     1130
     1131    def leave(self, occupantJID):
     1132        """
     1133        Leave a MUC room.
     1134
     1135        See: http://xmpp.org/extensions/xep-0045.html#exit
     1136
     1137        @param occupantJID: The Room JID of the room to leave.
     1138        @type occupantJID: L{jid.JID}
     1139        """
     1140        room = self._getRoom(occupantJID)
     1141
     1142        p = xmppim.UnavailablePresence(to=room.occupantJID)
     1143
     1144        d = self.sendDeferred(p, timeout=DEFER_TIMEOUT)
     1145        # add observer for joining the room
     1146        query = PRESENCE + u"[@from='%s' and @type='unavailable']" % (room.occupantJID)
     1147        self.xmlstream.addOnetimeObserver(query, self._leftRoom, 1, d)
     1148
     1149        return d
     1150
     1151
     1152    def status(self, occupantJID, show=None, status=None):
     1153        """
     1154        Change user status.
     1155
     1156        See: http://xmpp.org/extensions/xep-0045.html#changepres
     1157
     1158        @param occupantJID: The room jabber/xmpp entity id for the requested configuration form.
     1159        @type occupantJID: L{jid.JID}
     1160
     1161        @param show: The availability of the entity. Common values are xa, available, etc
     1162        @type show: C{unicode}
     1163
     1164        @param show: The current status of the entity.
     1165        @type show: C{unicode}
     1166        """
     1167        room = self._getRoom(occupantJID)
     1168        if room is None:
     1169            raise NotFound
     1170
     1171        p = BasicPresence(to=room.occupantJID)
    11721172        if status is not None:
    11731173            p.addElement('status', None, status)
     
    11791179
    11801180        # add observer for joining the room
    1181         query = PRESENCE + u"[@from='%s']" % room.roomJID
    1182         self.xmlstream.addOnetimeObserver(query, self._changed, 1, d, roomJID)
     1181        query = PRESENCE + u"[@from='%s']" % room.occupantJID
     1182        self.xmlstream.addOnetimeObserver(query, self._changed, 1, d, occupantJID)
    11831183
    11841184        return d
     
    12051205
    12061206
    1207     def chat(self, roomJID, message, children=None):
     1207    def chat(self, occupantJID, message, children=None):
    12081208        """
    12091209        Send a private chat message to a user in a MUC room.
     
    12111211        See: http://xmpp.org/extensions/xep-0045.html#privatemessage
    12121212
    1213         @param roomJID: The Room JID of the other user.
    1214         @type roomJID: L{jid.JID}
    1215         """
    1216 
    1217         msg = PrivateChat(roomJID, body=message)
     1213        @param occupantJID: The Room JID of the other user.
     1214        @type occupantJID: L{jid.JID}
     1215        """
     1216
     1217        msg = PrivateChat(occupantJID, body=message)
    12181218
    12191219        self._sendMessage(msg, children=children)
    12201220
    12211221
    1222     def invite(self, bareRoomJID, reason=None, invitee=None):
     1222    def invite(self, roomJID, reason=None, invitee=None):
    12231223        """
    12241224        Invite a xmpp entity to a MUC room.
     
    12261226        See: http://xmpp.org/extensions/xep-0045.html#invite
    12271227
    1228         @param bareRoomJID: The bare JID of the room.
    1229         @type bareRoomJID: L{jid.JID}
     1228        @param roomJID: The bare JID of the room.
     1229        @type roomJID: L{jid.JID}
    12301230
    12311231        @param reason: The reason for the invite.
    1232         @type reason: L{unicode}
     1232        @type reason: C{unicode}
    12331233
    12341234        @param invitee: The entity that is being invited.
    12351235        @type invitee: L{jid.JID}
    12361236        """
    1237         msg = InviteMessage(bareRoomJID, reason=reason, invitee=invitee)
     1237        msg = InviteMessage(roomJID, reason=reason, invitee=invitee)
    12381238        self._sendMessage(msg)
    12391239
    12401240
    1241     def password(self, bareRoomJID, password):
     1241    def password(self, roomJID, password):
    12421242        """
    12431243        Send a password to a room so the entity can join.
     
    12451245        See: http://xmpp.org/extensions/xep-0045.html#enter-pw
    12461246
    1247         @param bareRoomJID: The bare JID of the room.
    1248         @type bareRoomJID: L{jid.JID}
     1247        @param roomJID: The bare JID of the room.
     1248        @type roomJID: L{jid.JID}
    12491249
    12501250        @param password: The MUC room password.
    1251         @type password: L{unicode}
    1252         """
    1253         p = PasswordPresence(bareRoomJID, password)
     1251        @type password: C{unicode}
     1252        """
     1253        p = PasswordPresence(roomJID, password)
    12541254
    12551255        self.xmlstream.send(p)
    12561256
    12571257
    1258     def register(self, bareRoomJID, fields=[]):
     1258    def register(self, roomJID, fields=[]):
    12591259        """
    12601260        Send a request to register for a room.
    12611261
    1262         @param bareRoomJID: The bare JID of the room.
    1263         @type bareRoomJID: L{jid.JID}
     1262        @param roomJID: The bare JID of the room.
     1263        @type roomJID: L{jid.JID}
    12641264
    12651265        @param fields: The fields you need to register.
     
    12671267        """
    12681268        iq = RegisterRequest(self.xmlstream, method='set', fields=fields)
    1269         iq['to'] = bareRoomJID.userhost()
     1269        iq['to'] = roomJID.userhost()
    12701270        return iq.send()
    12711271
    12721272
    1273     def _getAffiliationList(self, bareRoomJID, affiliation):
     1273    def _getAffiliationList(self, roomJID, affiliation):
    12741274        """
    12751275        Send a request for an affiliation list in a room.
     
    12791279                                affiliation=affiliation,
    12801280                                )
    1281         iq['to'] = bareRoomJID.userhost()
     1281        iq['to'] = roomJID.userhost()
    12821282        return iq.send()
    12831283
    12841284
    1285     def _getRoleList(self, bareRoomJID, role):
     1285    def _getRoleList(self, roomJID, role):
    12861286        """
    12871287        Send a role request.
     
    12911291                         role=role,
    12921292                         )
    1293         iq['to'] = bareRoomJID.full()
     1293        iq['to'] = roomJID.full()
    12941294        return iq.send()
    12951295
    12961296
    1297     def _setAffiliationList(self, iq, affiliation, roomJID):
     1297    def _setAffiliationList(self, iq, affiliation, occupantJID):
    12981298        # set a rooms affiliation list
    1299         room = self._getRoom(roomJID)
     1299        room = self._getRoom(occupantJID)
    13001300        if room is not None:
    13011301            affiliation_list = []
     
    13231323
    13241324
    1325     def getMemberList(self, bareRoomJID):
     1325    def getMemberList(self, roomJID):
    13261326        """
    13271327        Get the member list of a room.
    13281328
    1329         @param bareRoomJID: The bare JID of the room.
    1330         @type bareRoomJID: L{jid.JID}
    1331         """
    1332         d = self._getAffiliationList(bareRoomJID, 'member')
    1333         d.addCallback(self._setAffiliationList, 'members', bareRoomJID)
     1329        @param roomJID: The bare JID of the room.
     1330        @type roomJID: L{jid.JID}
     1331        """
     1332        d = self._getAffiliationList(roomJID, 'member')
     1333        d.addCallback(self._setAffiliationList, 'members', roomJID)
    13341334        return d
    13351335
    13361336
    1337     def getAdminList(self, bareRoomJID):
     1337    def getAdminList(self, roomJID):
    13381338        """
    13391339        Get the admin list of a room.
    13401340
    1341         @param bareRoomJID: The bare JID of the room.
    1342         @type bareRoomJID: L{jid.JID}
    1343         """
    1344         d = self._getAffiliationList(bareRoomJID, 'admin')
    1345         d.addCallback(self._setAffiliationList, 'admin', bareRoomJID)
     1341        @param roomJID: The bare JID of the room.
     1342        @type roomJID: L{jid.JID}
     1343        """
     1344        d = self._getAffiliationList(roomJID, 'admin')
     1345        d.addCallback(self._setAffiliationList, 'admin', roomJID)
    13461346        return d
    13471347
    13481348
    1349     def getBanList(self, bareRoomJID):
     1349    def getBanList(self, roomJID):
    13501350        """
    13511351        Get an outcast list from a room.
    13521352
    1353         @param bareRoomJID: The bare JID of the room.
    1354         @type bareRoomJID: L{jid.JID}
    1355         """
    1356         d = self._getAffiliationList(bareRoomJID, 'outcast')
    1357         d.addCallback(self._setAffiliationList, 'outcast', bareRoomJID)
     1353        @param roomJID: The bare JID of the room.
     1354        @type roomJID: L{jid.JID}
     1355        """
     1356        d = self._getAffiliationList(roomJID, 'outcast')
     1357        d.addCallback(self._setAffiliationList, 'outcast', roomJID)
    13581358        return d
    13591359
    13601360
    1361     def getOwnerList(self, bareRoomJID):
     1361    def getOwnerList(self, roomJID):
    13621362        """
    13631363        Get an owner list from a room.
    13641364
    1365         @param bareRoomJID: The room jabber/xmpp entity id for the requested member list.
    1366         @type bareRoomJID: L{jid.JID}
    1367         """
    1368         d = self._getAffiliationList(bareRoomJID, 'owner')
    1369         d.addCallback(self._setAffiliationList, 'owner', bareRoomJID)
     1365        @param roomJID: The room jabber/xmpp entity id for the requested member list.
     1366        @type roomJID: L{jid.JID}
     1367        """
     1368        d = self._getAffiliationList(roomJID, 'owner')
     1369        d.addCallback(self._setAffiliationList, 'owner', roomJID)
    13701370        return d
    13711371
     
    13831383
    13841384
    1385     def destroy(self, bareRoomJID, reason=None, alternate=None):
     1385    def destroy(self, roomJID, reason=None, alternate=None):
    13861386        """
    13871387        Destroy a room.
    13881388
    1389         @param bareRoomJID: The bare JID of the room.
    1390         @type bareRoomJID: L{jid.JID}
     1389        @param roomJID: The bare JID of the room.
     1390        @type roomJID: L{jid.JID}
    13911391
    13921392        @param reason: The reason we are destroying the room.
    1393         @type reason: L{unicode}
     1393        @type reason: C{unicode}
    13941394
    13951395        @param alternate: The bare JID of the room suggested as an alternate
     
    13991399        """
    14001400        def destroyed(iq):
    1401             self._removeRoom(bareRoomJID)
     1401            self._removeRoom(roomJID)
    14021402            return True
    14031403
    14041404        iq = OwnerRequest(self.xmlstream, method='set')
    1405         iq['to'] = bareRoomJID.userhost()
     1405        iq['to'] = roomJID.userhost()
    14061406        d = iq.query.addElement('destroy')
    14071407
     
    14141414
    14151415
    1416     def subject(self, bareRoomJID, subject):
     1416    def subject(self, roomJID, subject):
    14171417        """
    14181418        Change the subject of a MUC room.
     
    14201420        See: http://xmpp.org/extensions/xep-0045.html#subject-mod
    14211421
    1422         @param bareRoomJID: The bare JID of the room.
    1423         @type bareRoomJID: L{jid.JID}
     1422        @param roomJID: The bare JID of the room.
     1423        @type roomJID: L{jid.JID}
    14241424
    14251425        @param subject: The subject you want to set.
    1426         @type subject: L{unicode}
    1427         """
    1428         msg = GroupChat(bareRoomJID.userhostJID(), subject=subject)
     1426        @type subject: C{unicode}
     1427        """
     1428        msg = GroupChat(roomJID.userhostJID(), subject=subject)
    14291429        self.xmlstream.send(msg)
    14301430
    14311431
    1432     def voice(self, bareRoomJID):
     1432    def voice(self, roomJID):
    14331433        """
    14341434        Request voice for a moderated room.
    14351435
    1436         @param bareRoomJID: The room jabber/xmpp entity id.
    1437         @type bareRoomJID: L{jid.JID}
    1438         """
    1439         msg = MessageVoice(to=bareRoomJID.userhostJID())
     1436        @param roomJID: The room jabber/xmpp entity id.
     1437        @type roomJID: L{jid.JID}
     1438        """
     1439        msg = MessageVoice(to=roomJID.userhostJID())
    14401440        self.xmlstream.send(msg)
    14411441
    14421442
    1443     def history(self, bareRoomJID, messages):
     1443    def history(self, roomJID, messages):
    14441444        """
    14451445        Send history to create a MUC based on a one on one chat.
     
    14471447        See: http://xmpp.org/extensions/xep-0045.html#continue
    14481448
    1449         @param bareRoomJID: The room jabber/xmpp entity id.
    1450         @type bareRoomJID: L{jid.JID}
     1449        @param roomJID: The room jabber/xmpp entity id.
     1450        @type roomJID: L{jid.JID}
    14511451
    14521452        @param messages: The history to send to the room as an ordered list of
     
    14691469                delay['from'] = sender
    14701470
    1471             stanza['to'] = bareRoomJID.userhost()
     1471            stanza['to'] = roomJID.userhost()
    14721472            if stanza.hasAttribute('from'):
    14731473                del stanza['from']
     
    14761476
    14771477
    1478     def _setAffiliation(self, bareRoomJID, entityOrNick, affiliation,
     1478    def _setAffiliation(self, roomJID, entityOrNick, affiliation,
    14791479                              reason=None, sender=None):
    14801480        """
     
    14861486                                affiliation=affiliation,
    14871487                                reason=reason)
    1488         iq['to'] = bareRoomJID.userhost()
     1488        iq['to'] = roomJID.userhost()
    14891489        if sender is not None:
    14901490            iq['from'] = unicode(sender)
     
    14931493
    14941494
    1495     def _setRole(self, bareRoomJID, entityOrNick, role,
     1495    def _setRole(self, roomJID, entityOrNick, role,
    14961496                       reason=None, sender=None):
    14971497        # send a role request
     
    15021502                         reason=reason)
    15031503
    1504         iq['to'] = bareRoomJID.userhost()
     1504        iq['to'] = roomJID.userhost()
    15051505        if sender is not None:
    15061506            iq['from'] = unicode(sender)
     
    15081508
    15091509
    1510     def modifyAffiliationList(self, frm, bareRoomJID, jid_list, affiliation):
     1510    def modifyAffiliationList(self, frm, roomJID, jid_list, affiliation):
    15111511        """
    15121512        Modify an affiliation list.
     
    15151515        @type frm: L{jid.JID}
    15161516
    1517         @param bareRoomJID: The bare JID of the room.
    1518         @type bareRoomJID: L{jid.JID}
    1519 
    1520         @param entities: The list of entities to change in a room. This can be a nick or a full jid.
    1521         @type jid_list: L{list} of L{unicode} for nicks. L{list} of L{jid.JID} for jids.
     1517        @param roomJID: The bare JID of the room.
     1518        @type roomJID: L{jid.JID}
     1519
     1520        @param entities: The list of entities to change in a room. This can be
     1521            a nick or a full jid.
     1522        @type jid_list: L{list} of C{unicode} for nicks. L{list} of L{jid.JID}
     1523            for jids.
    15221524
    15231525        @param affiliation: The affilation to change.
    1524         @type affiliation: L{unicode}
     1526        @type affiliation: C{unicode}
    15251527
    15261528        """
     
    15301532                                )
    15311533        iq.items(jid_list)
    1532         iq['to'] = bareRoomJID.userhost()
     1534        iq['to'] = roomJID.userhost()
    15331535        iq['from'] = frm.full()
    15341536        return iq.send()
    15351537
    15361538
    1537     def grantVoice(self, bareRoomJID, nick, reason=None, sender=None):
     1539    def grantVoice(self, roomJID, nick, reason=None, sender=None):
    15381540        """
    15391541        Grant voice to an entity.
    15401542
    1541         @param frm: The entity sending the request.
    1542         @type frm: L{jid.JID}
    1543 
    1544         @param room_jid: The room jabber/xmpp entity id.
    1545         @type room_jid: L{jid.JID}
     1543        @param roomJID: The bare JID of the room.
     1544        @type roomJID: L{jid.JID}
     1545
     1546        @param nick: The nick name for the user in this room.
     1547        @type nick: C{unicode}
    15461548
    15471549        @param reason: The reason for granting voice to the entity.
    1548         @type reason: L{unicode}
    1549 
    1550         @param nick: The nick name for the client in this room.
    1551         @type nick: L{unicode}
    1552         """
    1553         return self._setRole(bareRoomJID, entityOrNick=nick,
     1550        @type reason: C{unicode}
     1551
     1552        @param sender: The entity sending the request.
     1553        @type sender: L{jid.JID}
     1554        """
     1555        return self._setRole(roomJID, entityOrNick=nick,
    15541556                             role='participant',
    15551557                             reason=reason, sender=sender)
    15561558
    15571559
    1558     def revokeVoice(self, bareRoomJID, nick, reason=None, sender=None):
     1560    def revokeVoice(self, roomJID, nick, reason=None, sender=None):
    15591561        """
    15601562        Revoke voice from a participant.
     
    15621564        This will disallow the entity to send messages to a moderated room.
    15631565
    1564         @param frm: The entity sending the request.
    1565         @type frm: L{jid.JID}
    1566 
    1567         @param room_jid: The room jabber/xmpp entity id.
    1568         @type room_jid: L{jid.JID}
    1569 
    1570         @param reason: The reason for granting voice to the entity.
    1571         @type reason: L{unicode}
    1572 
    1573         @param nick: The nick name for the client in this room.
    1574         @type nick: L{unicode}
    1575         """
    1576         return self._setRole(bareRoomJID, entityOrNick=nick, role='visitor',
     1566        @param roomJID: The bare JID of the room.
     1567        @type roomJID: L{jid.JID}
     1568
     1569        @param nick: The nick name for the user in this room.
     1570        @type nick: C{unicode}
     1571
     1572        @param reason: The reason for revoking voice from the entity.
     1573        @type reason: C{unicode}
     1574
     1575        @param sender: The entity sending the request.
     1576        @type sender: L{jid.JID}
     1577        """
     1578        return self._setRole(roomJID, entityOrNick=nick, role='visitor',
    15771579                             reason=reason, sender=sender)
    15781580
    15791581
    1580     def grantModerator(self, frm, room_jid, reason=None, nick=None):
     1582    def grantModerator(self, roomJID, nick, reason=None, sender=None):
    15811583        """
    15821584        Grant moderator priviledges to a MUC room.
    15831585
    1584         @param frm: The entity sending the request.
    1585         @type frm: L{jid.JID}
    1586 
    1587         @param room_jid: The room jabber/xmpp entity id.
    1588         @type room_jid: L{jid.JID}
    1589         """
    1590         return self._setRole(frm, room_jid, role='moderator', reason=reason, nick=nick)
    1591 
    1592 
    1593     def ban(self, bareRoomJID, entity, reason=None, sender=None):
     1586        @param roomJID: The bare JID of the room.
     1587        @type roomJID: L{jid.JID}
     1588
     1589        @param nick: The nick name for the user in this room.
     1590        @type nick: C{unicode}
     1591
     1592        @param reason: The reason for granting moderation to the entity.
     1593        @type reason: C{unicode}
     1594
     1595        @param sender: The entity sending the request.
     1596        @type sender: L{jid.JID}
     1597        """
     1598        return self._setRole(roomJID, entityOrNick=nick, role='moderator',
     1599                             reason=reason, sender=sender)
     1600
     1601
     1602    def ban(self, roomJID, entity, reason=None, sender=None):
    15941603        """
    15951604        Ban a user from a MUC room.
    15961605
    1597         @param room_jid: The room jabber/xmpp entity id.
    1598         @type room_jid: L{jid.JID}
    1599 
    1600         @param ban_jid: The room jabber/xmpp entity id.
    1601         @type ban_jid: L{jid.JID}
    1602 
    1603         @param frm: The entity sending the request.
    1604         @type frm: L{jid.JID}
     1606        @param roomJID: The bare JID of the room.
     1607        @type roomJID: L{jid.JID}
     1608
     1609        @param entity: The room jabber/xmpp entity id.
     1610        @type entity: L{jid.JID}
    16051611
    16061612        @param reason: The reason for banning the entity.
    1607         @type reason: L{unicode}
    1608 
    1609         @param nick: The nick name for the client in this room.
    1610         @type nick: L{unicode}
    1611         """
    1612         return self._setAffiliation(bareRoomJID, entity, 'outcast',
     1613        @type reason: C{unicode}
     1614
     1615        @param sender: The entity sending the request.
     1616        @type sender: L{jid.JID}
     1617        """
     1618        return self._setAffiliation(roomJID, entity, 'outcast',
    16131619                                    reason=reason, sender=sender)
    16141620
    16151621
    1616     def kick(self, bareRoomJID, entityOrNick, reason=None, sender=None):
     1622    def kick(self, roomJID, entityOrNick, reason=None, sender=None):
    16171623        """
    16181624        Kick a user from a MUC room.
    16191625
    1620         @param room_jid: The room jabber/xmpp entity id.
    1621         @type room_jid: L{jid.JID}
    1622 
    1623         @param kick_jid: The room jabber/xmpp entity id.
    1624         @type kick_jid: L{jid.JID}
    1625 
    1626         @param frm: The entity sending the request.
    1627         @type frm: L{jid.JID}
     1626        @param roomJID: The bare JID of the room.
     1627        @type roomJID: L{jid.JID}
     1628
     1629        @param entityOrNick: The occupant to be banned.
     1630        @type entityOrNick: L{jid.JID} or C{unicode}
    16281631
    16291632        @param reason: The reason given for the kick.
    1630         @type reason: L{unicode}
    1631 
    1632         @param nick: The nick for the user in the MUC room.
    1633         @type nick: L{unicode}
    1634         """
    1635         return self._setAffiliation(bareRoomJID, entityOrNick, 'none', reason=reason, sender=sender)
     1633        @type reason: C{unicode}
     1634
     1635        @param sender: The entity sending the request.
     1636        @type sender: L{jid.JID}
     1637        """
     1638        return self._setAffiliation(roomJID, entityOrNick, 'none',
     1639                                    reason=reason, sender=sender)
  • wokkel/test/test_muc.py

    r131 r132  
    8888
    8989        def userPresence(room, user):
    90             self.failUnless(room.roomIdentifier==self.test_room, 'Wrong room name')
    91             self.failUnless(room.inRoster(user), 'User not in roster')
     90            self.assertEqual(self.test_room, room.roomIdentifier,
     91                             'Wrong room name')
     92            self.assertTrue(room.inRoster(user), 'User not in roster')
    9293
    9394
     
    122123
    123124        def cb(room):
    124             self.assertEquals(self.test_room, room.roomIdentifier)
     125            self.assertEqual(self.test_room, room.roomIdentifier)
    125126
    126127        d = self.protocol.join(self.test_srv, self.test_room, self.test_nick)
     
    468469
    469470        def cb(room):
    470             self.assertEquals(self.test_room, room.roomIdentifier)
    471             self.assertEquals(test_nick, room.nick)
     471            self.assertEqual(self.test_room, room.roomIdentifier)
     472            self.assertEqual(test_nick, room.nick)
    472473
    473474        d = self.protocol.nick(self.room_jid, test_nick)
     
    519520
    520521        def cb(room):
    521             self.assertEquals(self.test_room, room.roomIdentifier)
     522            self.assertEqual(self.test_room, room.roomIdentifier)
    522523            user = room.getUser(self.room_jid.resource)
    523             self.failUnless(user is not None, 'User not found')
    524             self.failUnless(user.status == 'testing MUC', 'Wrong status')
    525             self.failUnless(user.show == 'xa', 'Wrong show')
     524            self.assertNotIdentical(None, user, 'User not found')
     525            self.assertEqual('testing MUC', user.status, 'Wrong status')
     526            self.assertEqual('xa', user.show, 'Wrong show')
    526527
    527528        d = self.protocol.status(self.room_jid, 'xa', 'testing MUC')
     
    530531        prs = self.stub.output[-1]
    531532
    532         self.failUnless(prs.name=='presence', "Need to be presence")
    533         self.failUnless(getattr(prs, 'x', None), 'No muc x element')
     533        self.assertEqual('presence', prs.name, "Need to be presence")
     534        self.assertTrue(getattr(prs, 'x', None), 'No muc x element')
    534535
    535536        # send back user presence, they joined
     
    546547            self.assertEqual(1, len(members))
    547548            user = members[0]
    548             self.assertEquals(JID(u'hag66@shakespeare.lit'), user.entity)
    549             self.assertEquals(u'thirdwitch', user.nick)
    550             self.assertEquals(u'participant', user.role)
     549            self.assertEqual(JID(u'hag66@shakespeare.lit'), user.entity)
     550            self.assertEqual(u'thirdwitch', user.nick)
     551            self.assertEqual(u'participant', user.role)
    551552
    552553        self._createRoom()
     
    558559        query = iq.query
    559560        self.assertNotIdentical(None, query)
    560         self.assertEquals(NS_MUC_ADMIN, query.uri)
     561        self.assertEqual(NS_MUC_ADMIN, query.uri)
    561562
    562563        response = toResponse(iq, 'result')
Note: See TracChangeset for help on using the changeset viewer.