Changeset 131:d72d60360630


Ignore:
Timestamp:
Jun 14, 2009, 8:42:38 PM (11 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
wokkel-muc-client-support-24
Message:

More renames, argument consistency.

Location:
wokkel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wokkel/muc.py

    r130 r131  
    8989    A jid malformed error from the server.
    9090
    91 
    9291    """
    9392    condition = 'modify'
     
    219218    @ivar method: Type attribute of the IQ request. Either C{'set'} or C{'get'}
    220219    @type method: C{str}
    221 
    222220    """
    223221
     
    239237class AdminRequest(xmlstream.IQ):
    240238    """
    241     A basic admin iq request
     239    A basic admin iq request.
    242240
    243241    @ivar method: Type attribute of the IQ request. Either C{'set'} or C{'get'}
    244242    @type method: C{str}
    245 
    246243    """
    247244
     
    254251class OwnerRequest(xmlstream.IQ):
    255252    """
    256     A basic owner iq request
     253    A basic owner iq request.
    257254
    258255    @ivar method: Type attribute of the IQ request. Either C{'set'} or C{'get'}
    259256    @type method: C{str}
    260 
    261257    """
    262258
     
    276272    @ivar affiliation: The affiliation type to send to room.
    277273    @type affiliation: C{str}
    278 
    279     """
    280 
    281     def __init__(self, xs, method='get', affiliation='none', a_jid=None, reason=None, nick=None):
     274    """
     275
     276    def __init__(self, xs, method='get', affiliation='none',
     277                       entityOrNick=None, reason=None):
    282278        AdminRequest.__init__(self, xs, method)
    283279
    284280        self.affiliation = affiliation
    285         if a_jid is not None or nick is not None:
    286             i = self.query.addElement('item')
    287             i['affiliation'] = affiliation
    288 
    289         if a_jid:
    290             i['jid'] = a_jid.full()
    291 
    292         if nick:
    293             i['nick'] = nick
     281        self.reason = reason
     282        if entityOrNick:
     283            self.items([entityOrNick])
     284
     285    def items(self, entities=None):
     286        """
     287        Set or Get the items list for this affiliation request.
     288        """
     289        if entities:
     290            for entityOrNick in entities:
     291                item = self.query.addElement('item')
     292                item['affiliation'] = self.affiliation
     293                try:
     294                    item['jid'] = entityOrNick.full()
     295                except AttributeError:
     296                    item['nick'] = entityOrNick
     297
     298                if self.reason:
     299                    item.addElement('reason', content=self.reason)
     300
     301        return self.query.elements()
     302
     303
     304
     305class RoleRequest(AdminRequest):
     306    def __init__(self, xs, method='get', role='none',
     307                       entityOrNick=None, reason=None):
     308        AdminRequest.__init__(self, xs, method)
     309
     310        item = self.query.addElement('item')
     311        item['role'] = role
     312        try:
     313            item['jid'] = entityOrNick.full()
     314        except AttributeError:
     315            item['nick'] = entityOrNick
    294316
    295317        if reason:
    296             i.addElement('reason', None, reason)
    297 
    298 
    299     def items(self, jid_list=None):
    300         """
    301         Set or Get the items list for this affiliation request.
    302         """
    303         if jid_list:
    304             for j in jid_list:
    305                 i = self.query.addElement('item')
    306                 i['affiliation'] = self.affiliation
    307                 if isinstance(j, jid.JID):
    308                     i['jid'] = j.full()
    309                 else:
    310                     i['nick'] = j
    311 
    312         return self.query.elements()
    313 
    314 
    315 
    316 class RoleRequest(AdminRequest):
    317     def __init__(self, xs, method='get', role='none', a_jid=None, reason=None, nick=None):
    318         AdminRequest.__init__(self, xs, method)
    319         i = self.query.addElement('item')
    320 
    321         i['role'] = role
    322         if a_jid:
    323             i['jid'] = a_jid.full()
    324         if nick:
    325             i['nick'] = nick
    326 
    327         if reason:
    328             i.addElement('reason', None, reason)
     318            item.addElement('reason', content=self.reason)
    329319
    330320
     
    334324        A message stanza of type groupchat. Used to send a message to a MUC room that will be
    335325    broadcasted to people in the room.
    336 
    337326    """
    338327    def __init__(self, to, body=None, subject=None, frm=None):
     
    363352
    364353        @param to: The xmpp entity you are sending this chat to.
    365         @type  to: L{unicode} or L{jid.JID}
     354        @type to: L{unicode} or L{jid.JID}
    366355
    367356        @param body: The message you are sending.
    368         @type  body: L{unicode}
     357        @type body: L{unicode}
    369358
    370359        @param frm: The entity that is sending the message.
    371360        @param frm: L{unicode}
    372 
    373361        """
    374362        domish.Element.__init__(self, (None, 'message'))
     
    426414    @ivar  since: Send only the messages received since the datetime specified (which MUST conform to the DateTime profile specified in XMPP Date and Time Profiles [14]).
    427415    @type since: L{datetime.datetime}
    428 
    429416    """
    430417    attributes = ['maxchars', 'maxstanzas', 'seconds', 'since']
     
    494481        @ivar roomJID: The JID of the occupant in the room. Generated from roomIdentifier, service, and nick.
    495482        @type roomJID: L{jid.JID}
    496 
    497483        """
    498484        self.state = state
     
    525511
    526512        @param user: The user object that is being added to the room.
    527         @type  user: L{User}
    528 
     513        @type user: L{User}
    529514        """
    530515        self.roster[user.nick.lower()] = user
     
    536521
    537522        @param user: The user object to check.
    538         @type  user: L{User}
    539 
     523        @type user: L{User}
    540524        """
    541525
     
    548532
    549533        @param nick: The nick for the user in the MUC room.
    550         @type  nick: L{unicode}
    551 
     534        @type nick: L{unicode}
    552535        """
    553536        return self.roster.get(nick.lower())
     
    559542
    560543        @param user: The user object to check.
    561         @type  user: L{User}
    562 
     544        @type user: L{User}
    563545        """
    564546        if self.inRoster(user):
     
    570552    """
    571553    This behaves like an object providing L{domish.IElement}.
    572 
    573554    """
    574555
     
    583564    """
    584565    This behaves like an object providing L{domish.IElement}.
    585 
    586566    """
    587567
     
    602582    """
    603583    This behaves like an object providing L{domish.IElement}.
    604 
    605584    """
    606585
     
    647626    """
    648627    This behaves like an object providing L{domish.IElement}.
    649 
    650628    """
    651629
     
    744722        if not prs.hasAttribute('from'):
    745723            return
    746         room_jid = jid.internJID(prs.getAttribute('from', ''))
    747         self._userLeavesRoom(room_jid)
     724        roomJID = jid.internJID(prs.getAttribute('from', ''))
     725        self._userLeavesRoom(roomJID)
    748726
    749727
     
    755733        if not prs.hasAttribute('from'):
    756734            return
    757         room_jid = jid.internJID(prs.getAttribute('from', ''))
     735        roomJID = jid.internJID(prs.getAttribute('from', ''))
    758736        # add an error hook here?
    759         self._userLeavesRoom(room_jid)
     737        self._userLeavesRoom(roomJID)
    760738
    761739
     
    772750
    773751
    774     def _userLeavesRoom(self, room_jid):
     752    def _userLeavesRoom(self, roomJID):
    775753        # when a user leaves a room we need to update it
    776         room = self._getRoom(room_jid)
     754        room = self._getRoom(roomJID)
    777755        if room is None:
    778756            # not in the room yet
    779757            return
    780758        # check if user is in roster
    781         user = room.getUser(room_jid.resource)
     759        user = room.getUser(roomJID.resource)
    782760        if user is None:
    783761            return
     
    793771        if not prs.hasAttribute('from'):
    794772            return
    795         room_jid = jid.internJID(prs.getAttribute('from', ''))
     773        roomJID = jid.internJID(prs.getAttribute('from', ''))
    796774
    797775        status = getattr(prs, 'status', None)
     
    799777
    800778        # grab room
    801         room = self._getRoom(room_jid)
     779        room = self._getRoom(roomJID)
    802780        if room is None:
    803781            # not in the room yet
    804782            return
    805         user = self._changeUserStatus(room, room_jid, status, show)
     783        user = self._changeUserStatus(room, roomJID, status, show)
    806784
    807785        if room.inRoster(user):
     
    826804            # need to return an error here
    827805            return
    828         room_jid = jid.internJID(msg.getAttribute('from', ''))
    829 
    830         room = self._getRoom(room_jid)
     806        roomJID = jid.internJID(msg.getAttribute('from', ''))
     807
     808        room = self._getRoom(roomJID)
    831809        if room is None:
    832810            # not in the room yet
    833811            return
    834         user = room.getUser(room_jid.resource)
     812        user = room.getUser(roomJID.resource)
    835813        delay = None
    836814        # need to check for delay and x stanzas for delay namespace for backwards compatability
     
    852830        if not msg.hasAttribute('from'):
    853831            return
    854         room_jid = jid.internJID(msg['from'])
     832        roomJID = jid.internJID(msg['from'])
    855833
    856834        # grab room
    857         room = self._getRoom(room_jid)
     835        room = self._getRoom(roomJID)
    858836        if room is None:
    859837            # not in the room yet
    860838            return
    861839
    862         self.receivedSubject(room_jid, unicode(msg.subject))
     840        self.receivedSubject(roomJID, unicode(msg.subject))
    863841
    864842
     
    929907
    930908        @param room: The room the user has joined.
    931         @type  room: L{Room}
     909        @type room: L{Room}
    932910
    933911        @param user: The user that joined the MUC room.
    934         @type  user: L{User}
    935 
     912        @type user: L{User}
    936913        """
    937914        pass
     
    946923
    947924        @param room: The room the user has joined.
    948         @type  room: L{Room}
     925        @type room: L{Room}
    949926
    950927        @param user: The user that joined the MUC room.
    951         @type  user: L{User}
    952 
     928        @type user: L{User}
    953929        """
    954930        pass
     
    957933    def userUpdatedStatus(self, room, user, show, status):
    958934        """
    959         User Presence has been received
     935        User Presence has been received.
    960936
    961937        This method will need to be modified inorder for clients to
    962938        do something when this event occurs.
    963 
    964939        """
    965940        pass
     
    970945        This method will need to be modified inorder for clients to
    971946        do something when this event occurs.
    972 
    973947        """
    974948        pass
     
    994968
    995969        @param obj: The object to send over the wire.
    996         @type  obj: L{domish.Element} or L{unicode}
     970        @type obj: L{domish.Element} or L{unicode}
    997971
    998972        @param timeout: The number of seconds to wait before the deferred is timed out.
    999         @type  timeout: L{int}
     973        @type timeout: L{int}
    1000974
    1001975        The deferred object L{defer.Deferred} is returned.
     
    10271001
    10281002
    1029     def configure(self, room_jid, fields=[]):
    1030         """
    1031         Configure a room
    1032 
    1033         @param room_jid: The room jabber/xmpp entity id for the requested configuration form.
    1034         @type  room_jid: L{jid.JID}
     1003    def configure(self, bareRoomJID, fields=[]):
     1004        """
     1005        Configure a room.
     1006
     1007        @param bareRoomJID: The bare JID of the room.
     1008        @type bareRoomJID: L{jid.JID}
    10351009
    10361010        @param fields: The fields we want to modify.
    1037         @type  fields: A L{list} or L{dataform.Field}
    1038 
     1011        @type fields: A L{list} or L{dataform.Field}
    10391012        """
    10401013        request = ConfigureRequest(self.xmlstream, method='set', fields=fields)
    1041         request['to'] = room_jid
     1014        request['to'] = bareRoomJID
    10421015
    10431016        return request.send()
    10441017
    10451018
    1046     def getConfigureForm(self, room_jid):
     1019    def getConfigureForm(self, bareRoomJID):
    10471020        """
    10481021        Grab the configuration form from the room. This sends an iq request to the room.
    10491022
    1050         @param room_jid: The room jabber/xmpp entity id for the requested configuration form.
    1051         @type  room_jid: L{jid.JID}
    1052 
     1023        @param bareRoomJID: The bare JID of the room.
     1024        @type bareRoomJID: L{jid.JID}
    10531025        """
    10541026        request = ConfigureRequest(self.xmlstream)
    1055         request['to'] = room_jid
     1027        request['to'] = bareRoomJID
    10561028        return request.send()
    10571029
     
    10621034
    10631035        @param server: The server where the room is located.
    1064         @type  server: L{unicode}
     1036        @type server: L{unicode}
     1037
    10651038        @param room: The room name the entity is joining.
    1066         @type  room: L{unicode}
     1039        @type room: L{unicode}
     1040
    10671041        @param nick: The nick name for the entitity joining the room.
    1068         @type  nick: L{unicode}
     1042        @type nick: L{unicode}
     1043
    10691044        @param history: The maximum number of history stanzas you would like.
    10701045
     
    11321107        @param new_nick: The nick name for the entitity joining the room.
    11331108        @type new_nick: L{unicode}
    1134 
    11351109        """
    11361110
     
    11631137        @param roomJID: The Room JID of the room to leave.
    11641138        @type roomJID: L{jid.JID}
    1165 
    11661139        """
    11671140        room = self._getRoom(roomJID)
     
    11841157
    11851158        @param roomJID: The room jabber/xmpp entity id for the requested configuration form.
    1186         @type  roomJID: L{jid.JID}
     1159        @type roomJID: L{jid.JID}
    11871160
    11881161        @param show: The availability of the entity. Common values are xa, available, etc
    1189         @type  show: L{unicode}
     1162        @type show: L{unicode}
    11901163
    11911164        @param show: The current status of the entity.
    1192         @type  show: L{unicode}
    1193 
     1165        @type show: L{unicode}
    11941166        """
    11951167        room = self._getRoom(roomJID)
     
    12261198    def groupChat(self, to, message, children=None):
    12271199        """
    1228         Send a groupchat message
     1200        Send a groupchat message.
    12291201        """
    12301202        msg = GroupChat(to, body=message)
     
    12331205
    12341206
    1235     def chat(self, room_jid, message, children=None):
     1207    def chat(self, roomJID, message, children=None):
    12361208        """
    12371209        Send a private chat message to a user in a MUC room.
     
    12391211        See: http://xmpp.org/extensions/xep-0045.html#privatemessage
    12401212
    1241         @param room_jid: The room entity id.
    1242         @type  room_jid: L{jid.JID}
    1243 
    1244         """
    1245 
    1246         msg = PrivateChat(room_jid, body=message)
     1213        @param roomJID: The Room JID of the other user.
     1214        @type roomJID: L{jid.JID}
     1215        """
     1216
     1217        msg = PrivateChat(roomJID, body=message)
    12471218
    12481219        self._sendMessage(msg, children=children)
     
    12571228        @param bareRoomJID: The bare JID of the room.
    12581229        @type bareRoomJID: L{jid.JID}
     1230
    12591231        @param reason: The reason for the invite.
    12601232        @type reason: L{unicode}
     1233
    12611234        @param invitee: The entity that is being invited.
    12621235        @type invitee: L{jid.JID}
    1263 
    12641236        """
    12651237        msg = InviteMessage(bareRoomJID, reason=reason, invitee=invitee)
     
    12671239
    12681240
    1269     def password(self, room_jid, password):
     1241    def password(self, bareRoomJID, password):
    12701242        """
    12711243        Send a password to a room so the entity can join.
     
    12731245        See: http://xmpp.org/extensions/xep-0045.html#enter-pw
    12741246
    1275         @param room_jid: The room entity id.
    1276         @type  room_jid: L{jid.JID}
     1247        @param bareRoomJID: The bare JID of the room.
     1248        @type bareRoomJID: L{jid.JID}
    12771249
    12781250        @param password: The MUC room password.
    1279         @type  password: L{unicode}
    1280 
    1281         """
    1282         p = PasswordPresence(room_jid, password)
     1251        @type password: L{unicode}
     1252        """
     1253        p = PasswordPresence(bareRoomJID, password)
    12831254
    12841255        self.xmlstream.send(p)
    12851256
    12861257
    1287     def register(self, room_jid, fields=[]):
     1258    def register(self, bareRoomJID, fields=[]):
    12881259        """
    12891260        Send a request to register for a room.
    12901261
    1291         @param room_jid: The room entity id.
    1292         @type  room_jid: L{jid.JID}
     1262        @param bareRoomJID: The bare JID of the room.
     1263        @type bareRoomJID: L{jid.JID}
    12931264
    12941265        @param fields: The fields you need to register.
    1295         @type  fields: L{list} of L{dataform.Field}
    1296 
     1266        @type fields: L{list} of L{dataform.Field}
    12971267        """
    12981268        iq = RegisterRequest(self.xmlstream, method='set', fields=fields)
    1299         iq['to'] = room_jid.userhost()
     1269        iq['to'] = bareRoomJID.userhost()
    13001270        return iq.send()
    13011271
    13021272
    1303     def _getAffiliationList(self, room_jid, affiliation):
    1304         # send a request for an affiliation list in a room.
     1273    def _getAffiliationList(self, bareRoomJID, affiliation):
     1274        """
     1275        Send a request for an affiliation list in a room.
     1276        """
    13051277        iq = AffiliationRequest(self.xmlstream,
    13061278                                method='get',
    13071279                                affiliation=affiliation,
    13081280                                )
    1309         iq['to'] = room_jid.full()
     1281        iq['to'] = bareRoomJID.userhost()
    13101282        return iq.send()
    13111283
    13121284
    1313     def _getRoleList(self, room_jid, role):
    1314         # send a role request
     1285    def _getRoleList(self, bareRoomJID, role):
     1286        """
     1287        Send a role request.
     1288        """
    13151289        iq = RoleRequest(self.xmlstream,
    1316                                 method='get',
    1317                                 role=role,
    1318                                 )
    1319         iq['to'] = room_jid.full()
     1290                         method='get',
     1291                         role=role,
     1292                         )
     1293        iq['to'] = bareRoomJID.full()
    13201294        return iq.send()
    13211295
     
    13541328
    13551329        @param bareRoomJID: The bare JID of the room.
    1356         @type  bareRoomJID: L{jid.JID}
    1357 
     1330        @type bareRoomJID: L{jid.JID}
    13581331        """
    13591332        d = self._getAffiliationList(bareRoomJID, 'member')
     
    13671340
    13681341        @param bareRoomJID: The bare JID of the room.
    1369         @type  bareRoomJID: L{jid.JID}
    1370 
     1342        @type bareRoomJID: L{jid.JID}
    13711343        """
    13721344        d = self._getAffiliationList(bareRoomJID, 'admin')
     
    13801352
    13811353        @param bareRoomJID: The bare JID of the room.
    1382         @type  bareRoomJID: L{jid.JID}
    1383 
     1354        @type bareRoomJID: L{jid.JID}
    13841355        """
    13851356        d = self._getAffiliationList(bareRoomJID, 'outcast')
     
    13931364
    13941365        @param bareRoomJID: The room jabber/xmpp entity id for the requested member list.
    1395         @type  bareRoomJID: L{jid.JID}
    1396 
     1366        @type bareRoomJID: L{jid.JID}
    13971367        """
    13981368        d = self._getAffiliationList(bareRoomJID, 'owner')
     
    14061376
    14071377        @param room: The room jabber/xmpp entity id for the requested registration form.
    1408         @type  room: L{jid.JID}
    1409 
     1378        @type room: L{jid.JID}
    14101379        """
    14111380        iq = RegisterRequest(self.xmlstream)
     
    14141383
    14151384
    1416     def destroy(self, room_jid, reason=None):
     1385    def destroy(self, bareRoomJID, reason=None, alternate=None):
    14171386        """
    14181387        Destroy a room.
    14191388
    1420         @param room_jid: The room jabber/xmpp entity id.
    1421         @type  room_jid: L{jid.JID}
    1422 
    1423         @ivar reason: The reason we are destroying the room.
     1389        @param bareRoomJID: The bare JID of the room.
     1390        @type bareRoomJID: L{jid.JID}
     1391
     1392        @param reason: The reason we are destroying the room.
    14241393        @type reason: L{unicode}
    14251394
     1395        @param alternate: The bare JID of the room suggested as an alternate
     1396                          venue.
     1397        @type alternate: L{jid.JID}
     1398
    14261399        """
    14271400        def destroyed(iq):
    1428             self._removeRoom(room_jid)
     1401            self._removeRoom(bareRoomJID)
    14291402            return True
    14301403
    14311404        iq = OwnerRequest(self.xmlstream, method='set')
     1405        iq['to'] = bareRoomJID.userhost()
    14321406        d = iq.query.addElement('destroy')
    1433         d['jid'] = room_jid.userhost()
     1407
     1408        if alternate is not None:
     1409            d['jid'] = alternate.userhost()
    14341410        if reason is not None:
    14351411            d.addElement('reason', None, reason)
     
    14381414
    14391415
    1440     def subject(self, room_jid, subject):
     1416    def subject(self, bareRoomJID, subject):
    14411417        """
    14421418        Change the subject of a MUC room.
     
    14441420        See: http://xmpp.org/extensions/xep-0045.html#subject-mod
    14451421
    1446         @param room_jid: The room jabber/xmpp entity id.
    1447         @type  room_jid: L{jid.JID}
     1422        @param bareRoomJID: The bare JID of the room.
     1423        @type bareRoomJID: L{jid.JID}
    14481424
    14491425        @param subject: The subject you want to set.
    1450         @type  subject: L{unicode}
    1451 
    1452         """
    1453         msg = GroupChat(room_jid, subject=subject)
     1426        @type subject: L{unicode}
     1427        """
     1428        msg = GroupChat(bareRoomJID.userhostJID(), subject=subject)
    14541429        self.xmlstream.send(msg)
    14551430
    14561431
    1457     def voice(self, room_jid):
     1432    def voice(self, bareRoomJID):
    14581433        """
    14591434        Request voice for a moderated room.
    14601435
    1461         @param room_jid: The room jabber/xmpp entity id.
    1462         @type  room_jid: L{jid.JID}
    1463 
    1464         """
    1465         msg = MessageVoice(to=room_jid)
     1436        @param bareRoomJID: The room jabber/xmpp entity id.
     1437        @type bareRoomJID: L{jid.JID}
     1438        """
     1439        msg = MessageVoice(to=bareRoomJID.userhostJID())
    14661440        self.xmlstream.send(msg)
    14671441
    14681442
    1469     def history(self, room_jid, message_list):
     1443    def history(self, bareRoomJID, messages):
    14701444        """
    14711445        Send history to create a MUC based on a one on one chat.
     
    14731447        See: http://xmpp.org/extensions/xep-0045.html#continue
    14741448
    1475         @param room_jid: The room jabber/xmpp entity id.
    1476         @type  room_jid: L{jid.JID}
    1477 
    1478         @param message_list: A list of history to send to the room.
    1479         @type  message_list: L{list} of L{domish.Element}
    1480 
    1481         """
    1482 
    1483         for m in message_list:
    1484             m['type'] = 'groupchat'
    1485             mto = m['to']
    1486             frm = m.getAttribute('from', None)
    1487             m['to'] = room_jid.userhost()
    1488 
    1489             d = m.addElement('delay', NS_DELAY)
    1490             d['stamp'] = self._makeTimeStamp()
    1491             d['from'] = mto
    1492 
    1493             self.xmlstream.send(m)
    1494 
    1495 
    1496     def _setAffiliation(self, frm, room_jid, affiliation, reason=None, a_jid=None, nick=None):
    1497         # Send an affiliation request to change an entities affiliation to a MUC room.
     1449        @param bareRoomJID: The room jabber/xmpp entity id.
     1450        @type bareRoomJID: L{jid.JID}
     1451
     1452        @param messages: The history to send to the room as an ordered list of
     1453                         message, represented by a dictionary with the keys
     1454                         C{'stanza'}, holding the original stanza a
     1455                         L{domish.Element}, and C{'timestamp'} with the
     1456                         timestamp.
     1457        @type messages: L{list} of L{domish.Element}
     1458        """
     1459
     1460        for message in messages:
     1461            stanza = message['stanza']
     1462            stanza['type'] = 'groupchat'
     1463
     1464            delay = stanza.addElement('delay', NS_DELAY)
     1465            delay['stamp'] = message['timestamp']
     1466
     1467            sender = stanza.getAttribute('from', None)
     1468            if sender is not None:
     1469                delay['from'] = sender
     1470
     1471            stanza['to'] = bareRoomJID.userhost()
     1472            if stanza.hasAttribute('from'):
     1473                del stanza['from']
     1474
     1475            self.xmlstream.send(stanza)
     1476
     1477
     1478    def _setAffiliation(self, bareRoomJID, entityOrNick, affiliation,
     1479                              reason=None, sender=None):
     1480        """
     1481        Send a request to change an entity's affiliation to a MUC room.
     1482        """
    14981483        iq = AffiliationRequest(self.xmlstream,
    14991484                                method='set',
     1485                                entityOrNick=entityOrNick,
    15001486                                affiliation=affiliation,
    1501                                 a_jid=a_jid,
    1502                                 nick=nick,
    15031487                                reason=reason)
    1504         iq['to'] = room_jid.userhost() # this is a room jid, only send to room
    1505         iq['from'] = frm.full()
     1488        iq['to'] = bareRoomJID.userhost()
     1489        if sender is not None:
     1490            iq['from'] = unicode(sender)
     1491
    15061492        return iq.send()
    15071493
    15081494
    1509     def _setRole(self, frm, room_jid, a_jid=None, reason=None, role='none', nick=None):
     1495    def _setRole(self, bareRoomJID, entityOrNick, role,
     1496                       reason=None, sender=None):
    15101497        # send a role request
    15111498        iq = RoleRequest(self.xmlstream,
    15121499                         method='set',
    1513                          a_jid=a_jid,
    15141500                         role=role,
    1515                          nick=nick,
     1501                         entityOrNick=entityOrNick,
    15161502                         reason=reason)
    15171503
    1518         iq['to'] = room_jid.userhost() # this is a room jid, only send to room
    1519         iq['from'] = frm.full()
     1504        iq['to'] = bareRoomJID.userhost()
     1505        if sender is not None:
     1506            iq['from'] = unicode(sender)
    15201507        return iq.send()
    15211508
    15221509
    1523     def _cbRequest(self, room_jid, iq):
    1524         r = self._getRoom(room_jid)
    1525         if r is None:
    1526             raise NotFound
    1527 
    1528         return r
    1529 
    1530 
    1531     def modifyAffiliationList(self, frm, room_jid, jid_list, affiliation):
     1510    def modifyAffiliationList(self, frm, bareRoomJID, jid_list, affiliation):
    15321511        """
    15331512        Modify an affiliation list.
    15341513
    15351514        @param frm: The entity sending the request.
    1536         @type  frm: L{jid.JID}
    1537 
    1538         @param room_jid: The room jabber/xmpp entity id.
    1539         @type  room_jid: L{jid.JID}
    1540 
    1541         @param jid_list: The list of jabber ids to change in a room. This can be a nick or a full jid.
    1542         @type  jid_list: L{list} of L{unicode} for nicks. L{list} of L{jid.JID} for jids.
     1515        @type frm: L{jid.JID}
     1516
     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.
    15431522
    15441523        @param affiliation: The affilation to change.
    1545         @type  affiliation: L{unicode}
    1546 
     1524        @type affiliation: L{unicode}
    15471525
    15481526        """
     
    15521530                                )
    15531531        iq.items(jid_list)
    1554         iq['to'] = room_jid.userhost() # this is a room jid, only send to room
     1532        iq['to'] = bareRoomJID.userhost()
    15551533        iq['from'] = frm.full()
    15561534        return iq.send()
    15571535
    15581536
    1559     def grantVoice(self, frm, room_jid, voice_jid=None, reason=None, nick=None):
     1537    def grantVoice(self, bareRoomJID, nick, reason=None, sender=None):
    15601538        """
    15611539        Grant voice to an entity.
    15621540
    15631541        @param frm: The entity sending the request.
    1564         @type  frm: L{jid.JID}
     1542        @type frm: L{jid.JID}
    15651543
    15661544        @param room_jid: The room jabber/xmpp entity id.
    1567         @type  room_jid: L{jid.JID}
     1545        @type room_jid: L{jid.JID}
    15681546
    15691547        @param reason: The reason for granting voice to the entity.
    1570         @type  reason: L{unicode}
     1548        @type reason: L{unicode}
    15711549
    15721550        @param nick: The nick name for the client in this room.
    1573         @type  nick: L{unicode}
    1574 
    1575         """
    1576         return self._setRole(frm, room_jid, role='participant', a_jid=voice_jid, nick=nick, reason=reason)
    1577 
    1578 
    1579     def grantVisitor(self, frm, room_jid, reason=None, nick=None):
    1580         """
    1581         Change a participant to a visitor. This will disallow the entity to send messages to a moderated room.
     1551        @type nick: L{unicode}
     1552        """
     1553        return self._setRole(bareRoomJID, entityOrNick=nick,
     1554                             role='participant',
     1555                             reason=reason, sender=sender)
     1556
     1557
     1558    def revokeVoice(self, bareRoomJID, nick, reason=None, sender=None):
     1559        """
     1560        Revoke voice from a participant.
     1561
     1562        This will disallow the entity to send messages to a moderated room.
     1563
    15821564        @param frm: The entity sending the request.
    1583         @type  frm: L{jid.JID}
     1565        @type frm: L{jid.JID}
    15841566
    15851567        @param room_jid: The room jabber/xmpp entity id.
    1586         @type  room_jid: L{jid.JID}
     1568        @type room_jid: L{jid.JID}
    15871569
    15881570        @param reason: The reason for granting voice to the entity.
    1589         @type  reason: L{unicode}
     1571        @type reason: L{unicode}
    15901572
    15911573        @param nick: The nick name for the client in this room.
    1592         @type  nick: L{unicode}
    1593 
    1594         """
    1595         return self._setRole(frm, room_jid, role='visitor', reason=reason, nick=nick)
     1574        @type nick: L{unicode}
     1575        """
     1576        return self._setRole(bareRoomJID, entityOrNick=nick, role='visitor',
     1577                             reason=reason, sender=sender)
    15961578
    15971579
     
    16011583
    16021584        @param frm: The entity sending the request.
    1603         @type  frm: L{jid.JID}
     1585        @type frm: L{jid.JID}
    16041586
    16051587        @param room_jid: The room jabber/xmpp entity id.
    1606         @type  room_jid: L{jid.JID}
    1607 
     1588        @type room_jid: L{jid.JID}
    16081589        """
    16091590        return self._setRole(frm, room_jid, role='moderator', reason=reason, nick=nick)
    16101591
    16111592
    1612     def ban(self, room_jid, ban_jid, frm, reason=None, nick=None):
     1593    def ban(self, bareRoomJID, entity, reason=None, sender=None):
    16131594        """
    16141595        Ban a user from a MUC room.
    16151596
    16161597        @param room_jid: The room jabber/xmpp entity id.
    1617         @type  room_jid: L{jid.JID}
     1598        @type room_jid: L{jid.JID}
    16181599
    16191600        @param ban_jid: The room jabber/xmpp entity id.
    1620         @type  ban_jid: L{jid.JID}
     1601        @type ban_jid: L{jid.JID}
    16211602
    16221603        @param frm: The entity sending the request.
    1623         @type  frm: L{jid.JID}
     1604        @type frm: L{jid.JID}
    16241605
    16251606        @param reason: The reason for banning the entity.
    1626         @type  reason: L{unicode}
     1607        @type reason: L{unicode}
    16271608
    16281609        @param nick: The nick name for the client in this room.
    1629         @type  nick: L{unicode}
    1630 
    1631         """
    1632         return self._setAffiliation(frm, room_jid, 'outcast', nick=nick, a_jid=ban_jid, reason=reason)
    1633 
    1634 
    1635     def kick(self, room_jid, kick_jid, frm, reason=None, nick=None):
     1610        @type nick: L{unicode}
     1611        """
     1612        return self._setAffiliation(bareRoomJID, entity, 'outcast',
     1613                                    reason=reason, sender=sender)
     1614
     1615
     1616    def kick(self, bareRoomJID, entityOrNick, reason=None, sender=None):
    16361617        """
    16371618        Kick a user from a MUC room.
    16381619
    16391620        @param room_jid: The room jabber/xmpp entity id.
    1640         @type  room_jid: L{jid.JID}
     1621        @type room_jid: L{jid.JID}
    16411622
    16421623        @param kick_jid: The room jabber/xmpp entity id.
    1643         @type  kick_jid: L{jid.JID}
     1624        @type kick_jid: L{jid.JID}
    16441625
    16451626        @param frm: The entity sending the request.
    1646         @type  frm: L{jid.JID}
     1627        @type frm: L{jid.JID}
    16471628
    16481629        @param reason: The reason given for the kick.
    1649         @type  reason: L{unicode}
     1630        @type reason: L{unicode}
    16501631
    16511632        @param nick: The nick for the user in the MUC room.
    1652         @type  nick: L{unicode}
    1653 
    1654         """
    1655         return self._setAffiliation(frm, room_jid, 'none', a_jid=kick_jid, nick=nick, reason=reason)
     1633        @type nick: L{unicode}
     1634        """
     1635        return self._setAffiliation(bareRoomJID, entityOrNick, 'none', reason=reason, sender=sender)
  • wokkel/test/test_muc.py

    r130 r131  
    227227        self._createRoom()
    228228        # add user to room
    229         u = muc.User(self.room_jid.resource)
     229        user = muc.User(self.room_jid.resource)
    230230
    231231        room = self.protocol._getRoom(self.room_jid)
    232         room.addUser(u)
     232        room.addUser(user)
    233233
    234234        def userPresence(room, user):
     
    250250
    251251
    252         d = self.protocol.ban(self.room_jid, banned, self.user_jid, reason='Spam')
     252        d = self.protocol.ban(self.room_jid, banned, reason='Spam',
     253                              sender=self.user_jid)
    253254        d.addCallback(cb)
    254255
     
    268269        Kick an entity from a room.
    269270        """
    270         kicked = JID('kick@jabber.org/TroubleMakger')
     271        nick = 'TroubleMakger'
     272
    271273        def cb(kicked):
    272274            self.failUnless(kicked, 'Did not kick user')
    273275
    274 
    275         d = self.protocol.kick(self.room_jid, kicked, self.user_jid, reason='Spam')
     276        d = self.protocol.kick(self.room_jid, nick, reason='Spam',
     277                               sender=self.user_jid)
    276278        d.addCallback(cb)
    277279
     
    331333        msg.addElement('thread', None, thread)
    332334
    333         archive.append(msg)
     335        archive.append({'stanza': msg, 'timestamp': '2002-10-13T23:58:37Z'})
    334336
    335337        msg = domish.Element((None, 'message'))
     
    339341        msg.addElement('thread', None, thread)
    340342
    341         archive.append(msg)
     343        archive.append({'stanza': msg, 'timestamp': '2002-10-13T23:58:43Z'})
    342344
    343345        self.protocol.history(self.room_jid, archive)
     
    405407        Client requesting voice for a room.
    406408        """
    407         self.protocol.voice(self.room_jid.userhost())
     409        self.protocol.voice(self.room_jid)
    408410
    409411        m = self.stub.output[-1]
     
    488490
    489491        """
    490         give_voice = JID('voice@jabber.org/TroubleMakger')
     492        nick = 'TroubleMakger'
    491493        def cb(give_voice):
    492494            self.failUnless(give_voice, 'Did not give voice user')
    493495
    494496
    495         d = self.protocol.grantVoice(self.user_jid, self.room_jid, give_voice)
     497        d = self.protocol.grantVoice(self.room_jid, nick, sender=self.user_jid)
    496498        d.addCallback(cb)
    497499
     
    512514        """
    513515        self._createRoom()
    514         r = self.protocol._getRoom(self.room_jid)
    515         u = muc.User(self.room_jid.resource)
    516         r.addUser(u)
     516        room = self.protocol._getRoom(self.room_jid)
     517        user = muc.User(self.room_jid.resource)
     518        room.addUser(user)
    517519
    518520        def cb(room):
    519521            self.assertEquals(self.test_room, room.roomIdentifier)
    520             u = room.getUser(self.room_jid.resource)
    521             self.failUnless(u is not None, 'User not found')
    522             self.failUnless(u.status == 'testing MUC', 'Wrong status')
    523             self.failUnless(u.show == 'xa', 'Wrong show')
     522            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')
    524526
    525527        d = self.protocol.status(self.room_jid, 'xa', 'testing MUC')
Note: See TracChangeset for help on using the changeset viewer.