Changeset 130:45c3ce4fe4eb for wokkel
- Timestamp:
- Jun 9, 2009, 7:33:41 PM (13 years ago)
- Branch:
- wokkel-muc-client-support-24
- Location:
- wokkel
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/disco.py
r128 r130 409 409 410 410 411 class DiscoRequest(xmlstream.IQ):412 """413 Disco request.414 415 @ivar namespace: Request namespace.416 @type namespace: C{str}417 @ivar method: Type attribute of the IQ request. Either C{'set'} or C{'get'}418 @type method: C{str}419 """420 421 def __init__(self, xs, namespace=NS, method='get'):422 xmlstream.IQ.__init__(self, xs, method)423 self.addElement((namespace, 'query'))424 425 426 427 411 class DiscoHandler(XMPPHandler, IQHandlerMixin): 428 412 """ -
wokkel/iwokkel.py
r128 r130 799 799 """ 800 800 801 802 def disco(entity, type='info'):803 """Send disco queries to a XMPP entity804 805 @param entity: A XMPP entity to send the disco request to.806 @type entity: C{unicode}807 808 @param type: Optional argument to determine the type of discovery being done.809 @type type: C{str}810 811 """812 813 814 801 815 802 def configure(room_jid, fields=[]): -
wokkel/muc.py
r129 r130 18 18 from twisted.words.xish import domish 19 19 20 from wokkel import d isco, data_form, xmppim20 from wokkel import data_form, xmppim 21 21 from wokkel.subprotocols import XMPPHandler 22 22 from wokkel.iwokkel import IMUCClient 23 23 24 24 # Multi User Chat namespaces 25 NS_MUC 26 NS_MUC_USER 27 NS_MUC_ADMIN 28 NS_MUC_OWNER 25 NS_MUC = 'http://jabber.org/protocol/muc' 26 NS_MUC_USER = NS_MUC + '#user' 27 NS_MUC_ADMIN = NS_MUC + '#admin' 28 NS_MUC_OWNER = NS_MUC + '#owner' 29 29 NS_MUC_ROOMINFO = NS_MUC + '#roominfo' 30 NS_MUC_CONFIG 31 NS_MUC_REQUEST 30 NS_MUC_CONFIG = NS_MUC + '#roomconfig' 31 NS_MUC_REQUEST = NS_MUC + '#request' 32 32 NS_MUC_REGISTER = NS_MUC + '#register' 33 33 34 NS_DELAY 34 NS_DELAY = 'urn:xmpp:delay' 35 35 NS_JABBER_DELAY = 'jabber:x:delay' 36 36 37 NS_REQUEST 37 NS_REQUEST = 'jabber:iq:register' 38 38 39 39 # Iq get and set XPath queries 40 IQ 40 IQ = '/iq' 41 41 IQ_GET = IQ+'[@type="get"]' 42 42 IQ_SET = IQ+'[@type="set"]' 43 43 44 44 IQ_RESULT = IQ+'[@type="result"]' 45 IQ_ERROR 46 47 IQ_QUERY 45 IQ_ERROR = IQ+'[@type="error"]' 46 47 IQ_QUERY = IQ+'/query' 48 48 IQ_GET_QUERY = IQ_GET + '/query' 49 49 IQ_SET_QUERY = IQ_SET + '/query' 50 50 51 IQ_COMMAND 51 IQ_COMMAND = IQ+'/command' 52 52 53 53 MUC_ADMIN = IQ_QUERY+'[@xmlns="' + NS_MUC_ADMIN + '"]' … … 57 57 58 58 59 MESSAGE 59 MESSAGE = '/message' 60 60 PRESENCE = '/presence' 61 61 62 62 CHAT_BODY = MESSAGE +'[@type="chat"]/body' 63 CHAT 64 65 GROUPCHAT 66 SUBJECT 63 CHAT = MESSAGE +'[@type="chat"]' 64 65 GROUPCHAT = MESSAGE +'[@type="groupchat"]/body' 66 SUBJECT = MESSAGE +'[@type="groupchat"]/subject' 67 67 MESSAGE_ERROR = MESSAGE +'[@type="error"]' 68 68 … … 91 91 92 92 """ 93 condition 93 condition = 'modify' 94 94 mucCondition = 'jid-malformed' 95 95 … … 99 99 """ 100 100 """ 101 condition 101 condition = 'auth' 102 102 mucCondition = 'not-authorized' 103 103 … … 107 107 """ 108 108 """ 109 condition 109 condition = 'auth' 110 110 mucCondition = 'registration-required' 111 111 … … 115 115 """ 116 116 """ 117 condition 117 condition = 'auth' 118 118 mucCondition = 'forbidden' 119 119 … … 123 123 """ 124 124 """ 125 condition 125 condition = 'cancel' 126 126 mucCondition = 'conflict' 127 127 … … 131 131 """ 132 132 """ 133 condition 133 condition = 'cancel' 134 134 mucCondition = 'not-found' 135 135 … … 139 139 """ 140 140 """ 141 condition 141 condition = 'wait' 142 142 mucCondition = 'service-unavailable' 143 143 … … 385 385 386 386 387 class InviteMessage( PrivateChat):388 def __init__(self, to, reason=None, full_jid=None, body=None, frm=None, password=None):389 PrivateChat.__init__(self, to, body=body, frm=frm)390 del self['type'] # remove type387 class InviteMessage(domish.Element): 388 def __init__(self, bareRoomJID, invitee, reason=None): 389 domish.Element.__init__(self, (None, 'message')) 390 self['to'] = unicode(bareRoomJID) 391 391 x = self.addElement('x', NS_MUC_USER) 392 392 invite = x.addElement('invite') 393 if full_jid: 394 invite['to'] = full_jid 393 invite['to'] = invitee 395 394 if reason: 396 395 invite.addElement('reason', None, reason) 397 if password:398 invite.addElement('password', None, password)399 396 400 397 … … 434 431 435 432 def __init__(self, maxchars=None, maxstanzas=None, seconds=None, since=None): 436 self.maxchars 433 self.maxchars = maxchars 437 434 self.maxstanzas = maxstanzas 438 self.seconds 439 self.since 435 self.seconds = seconds 436 self.since = since 440 437 441 438 … … 462 459 """ 463 460 464 def __init__(self, nick, user_jid=None):461 def __init__(self, nick, entity=None): 465 462 self.nick = nick 466 self. user_jid = user_jid463 self.entity = entity 467 464 self.affiliation = 'none' 468 465 self.role = 'none' 469 466 470 467 self.status = None 471 self.show 468 self.show = None 472 469 473 470 … … 479 476 480 477 481 def __init__(self, name, server, nick, state=None):478 def __init__(self, roomIdentifier, service, nick, state=None): 482 479 """ 483 480 Initialize the room. 484 481 485 @ivar name: The nameof the MUC room.486 @type name: L{unicode}487 488 @ivar serv er: The server where the MUC room is located.489 @type serv er: L{unicode}482 @ivar roomIdentifier: The Room ID of the MUC room. 483 @type roomIdentifier: L{unicode} 484 485 @ivar service: The server where the MUC room is located. 486 @type service: L{unicode} 490 487 491 488 @ivar nick: The nick name for the client in this room. … … 495 492 @type state: L{int} 496 493 497 @ivar entity_id: The jid of the room. Generated from name, server, and nick.498 @type entity_id: L{jid.JID}499 500 """ 501 self.state 502 self. name = name503 self.serv er = server504 self.nick 494 @ivar roomJID: The JID of the occupant in the room. Generated from roomIdentifier, service, and nick. 495 @type roomJID: L{jid.JID} 496 497 """ 498 self.state = state 499 self.roomIdentifier = roomIdentifier 500 self.service = service 501 self.nick = nick 505 502 self.status = 0 506 503 507 self. entity_id = self.entityId()504 self.roomJID = self.refreshRoomJID() 508 505 509 506 self.roster = {} 510 507 511 508 512 def entityId(self): 513 """ 514 Creates the L{jid.JID} for the room. If name, server, or nick change then this method 515 should be called. 516 517 """ 518 self.entity_id = jid.internJID(self.name+'@'+self.server+'/'+self.nick) 519 520 return self.entity_id 509 def refreshRoomJID(self): 510 """ 511 Refreshes the Room JID. 512 513 This method should be called whenever roomIdentifier, service, or nick 514 change. 515 """ 516 self.roomJID = jid.internJID(u"%s@%s/%s" % (self.roomIdentifier, 517 self.service, 518 self.nick)) 519 return self.roomJID 521 520 522 521 … … 666 665 class MUCClient(XMPPHandler): 667 666 """ 668 Multi-User chat client protocol. This is a subclass of L{XMPPHandler} and implements L{IMUCCLient}. 669 667 Multi-User Chat client protocol. 668 669 This is a subclass of L{XMPPHandler} and implements L{IMUCCLient}. 670 671 @ivar _rooms: Collection of occupied rooms, keyed by the bare JID of the 672 room. Note that a particular entity can only join a room once 673 at a time. 674 @type _rooms: C{dict} 670 675 """ 671 676 672 677 implements(IMUCClient) 673 678 674 rooms = {}675 676 679 timeout = None 677 680 678 _deferreds = [] 681 def __init__(self): 682 XMPPHandler.__init__(self) 683 684 self._rooms = {} 685 self._deferreds = [] 686 679 687 680 688 def connectionInitialized(self): … … 694 702 695 703 696 def _ setRoom(self, room):704 def _addRoom(self, room): 697 705 """ 698 706 Add a room to the room collection. 699 """ 700 self.rooms[room.entity_id.userhost().lower()] = room 701 702 703 def _getRoom(self, room_jid): 707 708 Rooms are stored by the JID of the room itself. I.e. it uses the Room 709 ID and service parts of the Room JID. 710 711 @note: An entity can only join a particular room once. 712 """ 713 bareRoomJID = room.roomJID.userhostJID() 714 self._rooms[bareRoomJID] = room 715 716 717 def _getRoom(self, roomJID): 704 718 """ 705 719 Grab a room from the room collection. 706 """ 707 return self.rooms.get(room_jid.userhost().lower()) 708 709 710 def _removeRoom(self, room_jid): 720 721 This uses the Room ID and service parts of the given JID to look up 722 the L{Room} instance associated with it. 723 """ 724 bareRoomJID = roomJID.userhostJID() 725 return self._rooms.get(bareRoomJID) 726 727 728 def _removeRoom(self, roomJID): 711 729 """ 712 730 Delete a room from the room collection. 713 731 """ 714 if self.rooms.has_key(room_jid.userhost().lower()): 715 del self.rooms[room_jid.userhost().lower()] 732 bareRoomJID = roomJID.userhostJID() 733 if bareRoomJID in self._rooms: 734 del self._rooms[bareRoomJID] 716 735 717 736 … … 777 796 778 797 status = getattr(prs, 'status', None) 779 show 798 show = getattr(prs, 'show', None) 780 799 781 800 # grab room … … 819 838 if e.uri == NS_DELAY or e.uri == NS_JABBER_DELAY: 820 839 delay = e 821 body 840 body = unicode(msg.body) 822 841 # grab room 823 842 if delay is None: … … 856 875 We have presence that says we joined a room. 857 876 """ 858 room _jid= jid.internJID(prs['from'])877 roomJID = jid.internJID(prs['from']) 859 878 860 879 # check for errors … … 863 882 else: 864 883 # change the state of the room 865 r = self._getRoom(room_jid)866 if r is None:884 room = self._getRoom(roomJID) 885 if room is None: 867 886 raise NotFound 868 r .state = 'joined'887 room.state = 'joined' 869 888 870 889 # grab status 871 status = getattr(prs.x, 'status',None)890 status = getattr(prs.x, 'status', None) 872 891 if status: 873 r .status = status.getAttribute('code', None)874 875 d.callback(r )892 room.status = status.getAttribute('code', None) 893 894 d.callback(room) 876 895 877 896 878 897 def _leftRoom(self, d, prs): 879 898 """ 880 We have presence that says we joineda room.881 """ 882 room _jid= jid.internJID(prs['from'])899 We have presence that says we left a room. 900 """ 901 roomJID = jid.internJID(prs['from']) 883 902 884 903 # check for errors … … 887 906 else: 888 907 # change the state of the room 889 r = self._getRoom(room_jid)890 if r is None:908 room = self._getRoom(roomJID) 909 if room is None: 891 910 raise NotFound 892 self._removeRoom(room _jid)911 self._removeRoom(roomJID) 893 912 894 913 d.callback(True) … … 1008 1027 1009 1028 1010 def disco(self, entity, type='info'):1011 """1012 Send disco queries to a XMPP entity.1013 1014 @param entity: The server or entity where we want discovery information from.1015 @type entity: L{jid.JID}1016 1017 @param type: The optional disco type.1018 @type type: L{unicode}1019 1020 """1021 1022 iq = disco.DiscoRequest(self.xmlstream, disco.NS_INFO, 'get')1023 iq['to'] = entity1024 1025 return iq.send().addBoth(self._cbDisco)1026 1027 1028 1029 def configure(self, room_jid, fields=[]): 1029 1030 """ … … 1056 1057 1057 1058 1058 def join(self, server, room, nick, history = None): 1059 """ 1060 Join a MUC room by sending presence to it. Returns a defered that is called when 1061 the entity is in the room or an error has occurred. 1059 def join(self, service, roomIdentifier, nick, history=None): 1060 """ 1061 Join a MUC room by sending presence to it. 1062 1062 1063 1063 @param server: The server where the room is located. 1064 1064 @type server: L{unicode} 1065 1066 1065 @param room: The room name the entity is joining. 1067 1066 @type room: L{unicode} 1068 1069 1067 @param nick: The nick name for the entitity joining the room. 1070 1068 @type nick: L{unicode} 1071 1072 1069 @param history: The maximum number of history stanzas you would like. 1073 1070 1074 """ 1075 r = Room(room, server, nick, state='joining') 1076 self._setRoom(r) 1077 1078 p = BasicPresence(to=r.entity_id) 1071 @return: A deferred that fires when the entity is in the room or an 1072 error has occurred. 1073 """ 1074 room = Room(roomIdentifier, service, nick, state='joining') 1075 self._addRoom(room) 1076 1077 p = BasicPresence(to=room.roomJID) 1079 1078 if history is not None: 1080 1079 p.x.addChild(history.toElement()) … … 1083 1082 1084 1083 # add observer for joining the room 1085 self.xmlstream.addOnetimeObserver(PRESENCE+"[@from='%s']" % (r.entity_id.full()),1086 1084 query = PRESENCE + u"[@from='%s']" % room.roomJID 1085 self.xmlstream.addOnetimeObserver(query, self._joinedRoom, 1, d) 1087 1086 1088 1087 return d 1089 1088 1090 1089 1091 def _changeUserStatus(self, r, room_jid, status, show): 1092 # change the user status in a room. 1090 def _changeUserStatus(self, room, roomJID, status, show): 1091 """ 1092 Change the user status in a room. 1093 """ 1093 1094 1094 1095 # check if user is in roster 1095 user = r .getUser(room_jid.resource)1096 user = room.getUser(roomJID.resource) 1096 1097 if user is None: # create a user that does not exist 1097 user = User(room _jid.resource)1098 user = User(roomJID.resource) 1098 1099 1099 1100 if status is not None: 1100 user.status = str(status)1101 user.status = unicode(status) 1101 1102 if show is not None: 1102 user.show = str(show)1103 user.show = unicode(show) 1103 1104 1104 1105 return user 1105 1106 1106 1107 1107 def _changed(self, d, room _jid, prs):1108 def _changed(self, d, roomJID, prs): 1108 1109 """ 1109 1110 Callback for changing the nick and status. … … 1111 1112 1112 1113 status = getattr(prs, 'status', None) 1113 show 1114 1115 r = self._getRoom(room_jid)1116 1117 user = self._changeUserStatus(r , room_jid, status, show)1118 1119 d.callback(r )1120 1121 1122 def nick(self, room_jid, new_nick):1114 show = getattr(prs, 'show', None) 1115 1116 room = self._getRoom(roomJID) 1117 1118 user = self._changeUserStatus(room, roomJID, status, show) 1119 1120 d.callback(room) 1121 1122 1123 def nick(self, bareRoomJID, new_nick): 1123 1124 """ 1124 1125 Change an entities nick name in a MUC room. … … 1126 1127 See: http://xmpp.org/extensions/xep-0045.html#changenick 1127 1128 1128 @param room_jid: The room jabber/xmpp entity id for the requested configuration form.1129 @type room_jid: L{jid.JID}1129 @param bareRoomJID: The JID of the room, i.e. without a resource. 1130 @type bareRoomJID: L{jid.JID} 1130 1131 1131 1132 @param new_nick: The nick name for the entitity joining the room. 1132 @type 1133 1134 """ 1135 1136 1137 r = self._getRoom(room_jid)1138 if r is None:1133 @type new_nick: L{unicode} 1134 1135 """ 1136 1137 1138 room = self._getRoom(bareRoomJID) 1139 if room is None: 1139 1140 raise NotFound 1140 r.nick = new_nick # change the nick 1141 # create presence 1142 # make sure we call the method to generate the new entity xmpp id 1143 p = BasicPresence(to=r.entityId()) 1141 1142 # Change the nickname 1143 room.nick = new_nick 1144 room.refreshRoomJID() 1145 1146 # Create presence 1147 p = BasicPresence(to=room.roomJID) 1144 1148 d = self.sendDeferred(p, timeout=DEFER_TIMEOUT) 1145 1149 1146 # add observer for joining the room1147 self.xmlstream.addOnetimeObserver(PRESENCE+"[@from='%s']" % (r.entity_id.full()),1148 self._changed, 1, d, room_jid)1150 # Add observer for joining the room 1151 query = PRESENCE+"[@from='%s']" % (room.roomJID.full()) 1152 self.xmlstream.addOnetimeObserver(query, self._changed, 1, d, bareRoomJID) 1149 1153 1150 1154 return d 1151 1155 1152 1156 1153 def leave(self, room _jid):1157 def leave(self, roomJID): 1154 1158 """ 1155 1159 Leave a MUC room. … … 1157 1161 See: http://xmpp.org/extensions/xep-0045.html#exit 1158 1162 1159 @param room _jid: The room entity id you want to exit.1160 @type room_jid: L{jid.JID}1161 1162 """ 1163 r = self._getRoom(room_jid)1164 1165 p = xmppim.UnavailablePresence(to=r .entity_id)1163 @param roomJID: The Room JID of the room to leave. 1164 @type roomJID: L{jid.JID} 1165 1166 """ 1167 room = self._getRoom(roomJID) 1168 1169 p = xmppim.UnavailablePresence(to=room.roomJID) 1166 1170 1167 1171 d = self.sendDeferred(p, timeout=DEFER_TIMEOUT) 1168 1172 # add observer for joining the room 1169 self.xmlstream.addOnetimeObserver(PRESENCE+"[@from='%s' and @type='unavailable']" % (r.entity_id.full()),1170 1173 query = PRESENCE + u"[@from='%s' and @type='unavailable']" % (room.roomJID) 1174 self.xmlstream.addOnetimeObserver(query, self._leftRoom, 1, d) 1171 1175 1172 1176 return d 1173 1177 1174 1178 1175 def status(self, room _jid, show=None, status=None):1179 def status(self, roomJID, show=None, status=None): 1176 1180 """ 1177 1181 Change user status. … … 1179 1183 See: http://xmpp.org/extensions/xep-0045.html#changepres 1180 1184 1181 @param room _jid: The room jabber/xmpp entity id for the requested configuration form.1182 @type room _jid: L{jid.JID}1185 @param roomJID: The room jabber/xmpp entity id for the requested configuration form. 1186 @type roomJID: L{jid.JID} 1183 1187 1184 1188 @param show: The availability of the entity. Common values are xa, available, etc … … 1189 1193 1190 1194 """ 1191 r = self._getRoom(room_jid)1192 if r is None:1195 room = self._getRoom(roomJID) 1196 if room is None: 1193 1197 raise NotFound 1194 1198 1195 p = BasicPresence(to=r .entityId())1199 p = BasicPresence(to=room.roomJID) 1196 1200 if status is not None: 1197 1201 p.addElement('status', None, status) … … 1203 1207 1204 1208 # add observer for joining the room 1205 self.xmlstream.addOnetimeObserver(PRESENCE+"[@from='%s']" % (r.entity_id.full()),1206 self._changed, 1, d, room_jid)1209 query = PRESENCE + u"[@from='%s']" % room.roomJID 1210 self.xmlstream.addOnetimeObserver(query, self._changed, 1, d, roomJID) 1207 1211 1208 1212 return d … … 1210 1214 1211 1215 def _sendMessage(self, msg, children=None): 1212 # send a message 1216 """ 1217 Send a message. 1218 """ 1213 1219 if children: 1214 for c in children:1215 msg.addChild(c )1220 for child in children: 1221 msg.addChild(child) 1216 1222 1217 1223 self.xmlstream.send(msg) … … 1243 1249 1244 1250 1245 def invite(self, room_jid, reason=None, full_jid=None):1251 def invite(self, bareRoomJID, reason=None, invitee=None): 1246 1252 """ 1247 1253 Invite a xmpp entity to a MUC room. … … 1249 1255 See: http://xmpp.org/extensions/xep-0045.html#invite 1250 1256 1251 @param room_jid: The room entity id. 1252 @type room_jid: L{jid.JID} 1253 1257 @param bareRoomJID: The bare JID of the room. 1258 @type bareRoomJID: L{jid.JID} 1254 1259 @param reason: The reason for the invite. 1255 @type reason: L{unicode} 1256 1257 @param full_jid: The xmpp user's entity id. 1258 @type full_jid: L{jid.JID} 1259 1260 """ 1261 msg = InviteMessage(room_jid, reason=reason, full_jid=full_jid) 1260 @type reason: L{unicode} 1261 @param invitee: The entity that is being invited. 1262 @type invitee: L{jid.JID} 1263 1264 """ 1265 msg = InviteMessage(bareRoomJID, reason=reason, invitee=invitee) 1262 1266 self._sendMessage(msg) 1263 1267 … … 1317 1321 1318 1322 1319 def _setAffiliationList(self, affiliation, room_jid, iq):1323 def _setAffiliationList(self, iq, affiliation, roomJID): 1320 1324 # set a rooms affiliation list 1321 r = self._getRoom(room_jid)1322 if r is not None:1325 room = self._getRoom(roomJID) 1326 if room is not None: 1323 1327 affiliation_list = [] 1324 setattr(r , affiliation, [])1328 setattr(room, affiliation, []) 1325 1329 1326 1330 for item in iq.query.elements(): 1327 nick 1331 nick = item.getAttribute('nick', None) 1328 1332 entity = item.getAttribute('jid', None) 1329 u = None 1333 role = item.getAttribute('role', None) 1334 user = None 1330 1335 if nick is None and entity is None: 1331 1336 raise Exception, 'bad attributes in item list' 1332 1337 if nick is not None: 1333 u = r.getUser(nick) 1334 if u is None: 1335 u = User(nick, user_jid=jid.internJID(entity)) 1336 u.affiliation = 'member' 1337 1338 affiliation_list.append(u) 1339 1340 setattr(r, affiliation, affiliation_list) 1341 return r 1342 1343 1344 def getMemberList(self, room_jid): 1345 """ 1346 Get a member list from a room. 1347 1348 @param room_jid: The room jabber/xmpp entity id for the requested member list. 1349 @type room_jid: L{jid.JID} 1350 1351 """ 1352 d = self._getAffiliationList(room_jid, 'member') 1353 d.addCallback(self._setAffiliationList, 'members', room_jid) 1338 user = room.getUser(nick) 1339 if user is None: 1340 user = User(nick, entity=jid.internJID(entity)) 1341 user.affiliation = 'member' 1342 if role is not None: 1343 user.role = role 1344 1345 affiliation_list.append(user) 1346 1347 setattr(room, affiliation, affiliation_list) 1348 return room 1349 1350 1351 def getMemberList(self, bareRoomJID): 1352 """ 1353 Get the member list of a room. 1354 1355 @param bareRoomJID: The bare JID of the room. 1356 @type bareRoomJID: L{jid.JID} 1357 1358 """ 1359 d = self._getAffiliationList(bareRoomJID, 'member') 1360 d.addCallback(self._setAffiliationList, 'members', bareRoomJID) 1354 1361 return d 1355 1362 1356 1363 1357 def getAdminList(self, room_jid):1358 """ 1359 Get an admin list froma room.1360 1361 @param room_jid: The room jabber/xmpp entity id for the requested member list.1362 @type room_jid: L{jid.JID}1363 1364 """ 1365 d = self._getAffiliationList( room_jid, 'admin')1366 d.addCallback(self._setAffiliationList, ' members', room_jid)1364 def getAdminList(self, bareRoomJID): 1365 """ 1366 Get the admin list of a room. 1367 1368 @param bareRoomJID: The bare JID of the room. 1369 @type bareRoomJID: L{jid.JID} 1370 1371 """ 1372 d = self._getAffiliationList(bareRoomJID, 'admin') 1373 d.addCallback(self._setAffiliationList, 'admin', bareRoomJID) 1367 1374 return d 1368 1375 1369 1376 1370 def getBanList(self, room_jid):1377 def getBanList(self, bareRoomJID): 1371 1378 """ 1372 1379 Get an outcast list from a room. 1373 1380 1374 @param room_jid: The room jabber/xmpp entity id for the requested member list.1375 @type room_jid: L{jid.JID}1376 1377 """ 1378 d = self._getAffiliationList( room_jid, 'outcast')1379 d.addCallback(self._setAffiliationList, ' members', room_jid)1381 @param bareRoomJID: The bare JID of the room. 1382 @type bareRoomJID: L{jid.JID} 1383 1384 """ 1385 d = self._getAffiliationList(bareRoomJID, 'outcast') 1386 d.addCallback(self._setAffiliationList, 'outcast', bareRoomJID) 1380 1387 return d 1381 1388 1382 1389 1383 def getOwnerList(self, room_jid):1390 def getOwnerList(self, bareRoomJID): 1384 1391 """ 1385 1392 Get an owner list from a room. 1386 1393 1387 @param room_jid: The room jabber/xmpp entity id for the requested member list.1388 @type room_jid: L{jid.JID}1389 1390 """ 1391 d = self._getAffiliationList( room_jid, 'owner')1392 d.addCallback(self._setAffiliationList, ' members', room_jid)1394 @param bareRoomJID: The room jabber/xmpp entity id for the requested member list. 1395 @type bareRoomJID: L{jid.JID} 1396 1397 """ 1398 d = self._getAffiliationList(bareRoomJID, 'owner') 1399 d.addCallback(self._setAffiliationList, 'owner', bareRoomJID) 1393 1400 return d 1394 1401 … … 1423 1430 1424 1431 iq = OwnerRequest(self.xmlstream, method='set') 1425 d 1432 d = iq.query.addElement('destroy') 1426 1433 d['jid'] = room_jid.userhost() 1427 1434 if reason is not None: -
wokkel/test/test_muc.py
r129 r130 18 18 from twisted.words.protocols.jabber.xmlstream import toResponse 19 19 20 NS_MUC_ADMIN = 'http://jabber.org/protocol/muc#admin' 20 21 21 22 def calledAsync(fn): … … 55 56 56 57 def _createRoom(self): 57 """A helper method to create a test room. 58 """ 59 A helper method to create a test room. 58 60 """ 59 61 # create a room 60 62 self.current_room = muc.Room(self.test_room, self.test_srv, self.test_nick) 61 self.protocol._ setRoom(self.current_room)63 self.protocol._addRoom(self.current_room) 62 64 63 65 … … 70 72 71 73 def test_userJoinedRoom(self): 72 """The client receives presence from an entity joining the room. 74 """ 75 The client receives presence from an entity joining the room. 73 76 74 77 This tests the class L{muc.UserPresence} and the userJoinedRoom event method. … … 85 88 86 89 def userPresence(room, user): 87 self.failUnless(room. name==self.test_room, 'Wrong room name')90 self.failUnless(room.roomIdentifier==self.test_room, 'Wrong room name') 88 91 self.failUnless(room.inRoster(user), 'User not in roster') 89 92 … … 95 98 96 99 def test_groupChat(self): 97 """The client receives a groupchat message from an entity in the room. 100 """ 101 The client receives a groupchat message from an entity in the room. 98 102 """ 99 103 m = muc.GroupChat('test@test.com',body='test') … … 104 108 def groupChat(room, user, message): 105 109 self.failUnless(message=='test', "Wrong group chat message") 106 self.failUnless(room. name==self.test_room, 'Wrong room name')110 self.failUnless(room.roomIdentifier==self.test_room, 'Wrong room name') 107 111 108 112 … … 112 116 113 117 114 def test_discoServerSupport(self):115 """Disco support from client to server.116 """117 test_srv = 'shakespeare.lit'118 119 def cb(query):120 # check namespace121 self.failUnless(query.uri==disco.NS_INFO, 'Wrong namespace')122 123 124 d = self.protocol.disco(test_srv)125 d.addCallback(cb)126 127 iq = self.stub.output[-1]128 129 # send back a response130 response = toResponse(iq, 'result')131 response.addElement('query', disco.NS_INFO)132 # need to add information to response133 response.query.addChild(disco.DiscoFeature(muc.NS_MUC))134 response.query.addChild(disco.DiscoIdentity(category='conference',135 name='Macbeth Chat Service',136 type='text'))137 138 self.stub.send(response)139 return d140 141 142 118 def test_joinRoom(self): 143 """Joining a room 119 """ 120 Joining a room 144 121 """ 145 122 146 123 def cb(room): 147 self.assertEquals(self.test_room, room. name)124 self.assertEquals(self.test_room, room.roomIdentifier) 148 125 149 126 d = self.protocol.join(self.test_srv, self.test_room, self.test_nick) … … 161 138 162 139 def test_joinRoomForbidden(self): 163 """Client joining a room and getting a forbidden error. 140 """ 141 Client joining a room and getting a forbidden error. 164 142 """ 165 143 … … 187 165 188 166 def test_joinRoomBadJid(self): 189 """Client joining a room and getting a forbidden error. 167 """ 168 Client joining a room and getting a forbidden error. 190 169 """ 191 170 … … 213 192 214 193 def test_partRoom(self): 215 """Client leaves a room 194 """ 195 Client leaves a room 216 196 """ 217 197 def cb(left): … … 219 199 220 200 201 self._createRoom() 221 202 d = self.protocol.leave(self.room_jid) 222 203 d.addCallback(cb) … … 235 216 236 217 def test_userPartsRoom(self): 237 """An entity leaves the room, a presence of type unavailable is received by the client. 218 """ 219 An entity leaves the room, a presence of type unavailable is received by the client. 238 220 """ 239 221 … … 251 233 252 234 def userPresence(room, user): 253 self.failUnless(room. name==self.test_room, 'Wrong room name')235 self.failUnless(room.roomIdentifier==self.test_room, 'Wrong room name') 254 236 self.failUnless(room.inRoster(user)==False, 'User in roster') 255 237 … … 260 242 261 243 def test_ban(self): 262 """Ban an entity in a room. 244 """ 245 Ban an entity in a room. 263 246 """ 264 247 banned = JID('ban@jabber.org/TroubleMakger') … … 282 265 283 266 def test_kick(self): 284 """Kick an entity from a room. 267 """ 268 Kick an entity from a room. 285 269 """ 286 270 kicked = JID('kick@jabber.org/TroubleMakger') … … 304 288 305 289 def test_password(self): 306 """Sending a password via presence to a password protected room. 290 """ 291 Sending a password via presence to a password protected room. 307 292 """ 308 293 … … 315 300 316 301 def test_history(self): 317 """Receiving history on room join. 302 """ 303 Receiving history on room join. 318 304 """ 319 305 m = muc.HistoryMessage(self.room_jid.userhost(), self.protocol._makeTimeStamp(), body='test') … … 333 319 334 320 def test_oneToOneChat(self): 335 """Converting a one to one chat to a multi-user chat. 321 """ 322 Converting a one to one chat to a multi-user chat. 336 323 """ 337 324 archive = [] … … 365 352 366 353 def test_invite(self): 367 """Invite a user to a room 368 """ 369 other_jid = 'test@jabber.org' 370 371 self.protocol.invite(other_jid, 'This is a test') 354 """ 355 Invite a user to a room 356 """ 357 bareRoomJID = self.room_jid.userhostJID() 358 invitee = JID('test@jabber.org') 359 360 self.protocol.invite(bareRoomJID, 'This is a test', invitee) 372 361 373 362 msg = self.stub.output[-1] 374 363 375 self.failUnless(xpath.matches("/message[@to='%s']/x/invite/reason" % (other_jid,), msg), 'Wrong message type') 364 query = u"/message[@to='%s']/x/invite/reason" % bareRoomJID 365 self.failUnless(xpath.matches(query, msg), 'Wrong message type') 376 366 377 367 378 368 def test_privateMessage(self): 379 """Send private messages to muc entities. 369 """ 370 Send private messages to muc entities. 380 371 """ 381 372 other_nick = self.room_jid.userhost()+'/OtherNick' … … 389 380 390 381 def test_register(self): 391 """Client registering with a room. http://xmpp.org/extensions/xep-0045.html#register 382 """ 383 Client registering with a room. http://xmpp.org/extensions/xep-0045.html#register 392 384 393 385 """ … … 410 402 411 403 def test_voice(self): 412 """ Client requesting voice for a room. 404 """ 405 Client requesting voice for a room. 413 406 """ 414 407 self.protocol.voice(self.room_jid.userhost()) … … 420 413 421 414 def test_roomConfigure(self): 422 """ Default configure and changing the room name. 415 """ 416 Default configure and changing the room name. 423 417 """ 424 418 … … 445 439 446 440 def test_roomDestroy(self): 447 """ Destroy a room. 441 """ 442 Destroy a room. 448 443 """ 449 444 … … 463 458 464 459 def test_nickChange(self): 465 """Send a nick change to the server. 460 """ 461 Send a nick change to the server. 466 462 """ 467 463 test_nick = 'newNick' … … 470 466 471 467 def cb(room): 472 self.assertEquals(self.test_room, room. name)468 self.assertEquals(self.test_room, room.roomIdentifier) 473 469 self.assertEquals(test_nick, room.nick) 474 470 … … 488 484 489 485 def test_grantVoice(self): 490 """Test granting voice to a user. 486 """ 487 Test granting voice to a user. 491 488 492 489 """ … … 511 508 512 509 def test_changeStatus(self): 513 """Change status 510 """ 511 Change status 514 512 """ 515 513 self._createRoom() … … 519 517 520 518 def cb(room): 521 self.assertEquals(self.test_room, room. name)519 self.assertEquals(self.test_room, room.roomIdentifier) 522 520 u = room.getUser(self.room_jid.resource) 523 521 self.failUnless(u is not None, 'User not found') … … 539 537 self.stub.send(response) 540 538 return d 539 540 541 def test_getMemberList(self): 542 def cb(room): 543 members = room.members 544 self.assertEqual(1, len(members)) 545 user = members[0] 546 self.assertEquals(JID(u'hag66@shakespeare.lit'), user.entity) 547 self.assertEquals(u'thirdwitch', user.nick) 548 self.assertEquals(u'participant', user.role) 549 550 self._createRoom() 551 bareRoomJID = self.room_jid.userhostJID() 552 d = self.protocol.getMemberList(bareRoomJID) 553 d.addCallback(cb) 554 555 iq = self.stub.output[-1] 556 query = iq.query 557 self.assertNotIdentical(None, query) 558 self.assertEquals(NS_MUC_ADMIN, query.uri) 559 560 response = toResponse(iq, 'result') 561 query = response.addElement((NS_MUC_ADMIN, 'query')) 562 item = query.addElement('item') 563 item['affiliation'] ='member' 564 item['jid'] = 'hag66@shakespeare.lit' 565 item['nick'] = 'thirdwitch' 566 item['role'] = 'participant' 567 self.stub.send(response) 568 569 return d 570 571
Note: See TracChangeset
for help on using the changeset viewer.