Changeset 132:1b19c49d30c2
- Timestamp:
- Aug 21, 2009, 2:46:18 PM (11 years ago)
- Branch:
- wokkel-muc-client-support-24
- Location:
- wokkel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/muc.py
r131 r132 352 352 353 353 @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} 355 355 356 356 @param body: The message you are sending. 357 @type body: L{unicode}357 @type body: C{unicode} 358 358 359 359 @param frm: The entity that is sending the message. 360 @param frm: L{unicode}360 @param frm: C{unicode} 361 361 """ 362 362 domish.Element.__init__(self, (None, 'message')) … … 374 374 375 375 class InviteMessage(domish.Element): 376 def __init__(self, bareRoomJID, invitee, reason=None):376 def __init__(self, roomJID, invitee, reason=None): 377 377 domish.Element.__init__(self, (None, 'message')) 378 self['to'] = unicode( bareRoomJID)378 self['to'] = unicode(roomJID) 379 379 x = self.addElement('x', NS_MUC_USER) 380 380 invite = x.addElement('invite') … … 468 468 469 469 @ivar roomIdentifier: The Room ID of the MUC room. 470 @type roomIdentifier: L{unicode}470 @type roomIdentifier: C{unicode} 471 471 472 472 @ivar service: The server where the MUC room is located. 473 @type service: L{unicode}473 @type service: C{unicode} 474 474 475 475 @ivar nick: The nick name for the client in this room. 476 @type nick: L{unicode}476 @type nick: C{unicode} 477 477 478 478 @ivar state: The status code of the room. 479 479 @type state: L{int} 480 480 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} 483 483 """ 484 484 self.state = state … … 488 488 self.status = 0 489 489 490 self. roomJID = self.refreshRoomJID()490 self.occupantJID = self.refreshOccupantJID() 491 491 492 492 self.roster = {} 493 493 494 494 495 def refresh RoomJID(self):495 def refreshOccupantJID(self): 496 496 """ 497 497 Refreshes the Room JID. … … 500 500 change. 501 501 """ 502 self. roomJID = jid.internJID(u"%s@%s/%s" % (self.roomIdentifier,502 self.occupantJID = jid.internJID(u"%s@%s/%s" % (self.roomIdentifier, 503 503 self.service, 504 504 self.nick)) 505 return self. roomJID505 return self.occupantJID 506 506 507 507 … … 532 532 533 533 @param nick: The nick for the user in the MUC room. 534 @type nick: L{unicode}534 @type nick: C{unicode} 535 535 """ 536 536 return self.roster.get(nick.lower()) … … 689 689 @note: An entity can only join a particular room once. 690 690 """ 691 bareRoomJID = room.roomJID.userhostJID()692 self._rooms[ bareRoomJID] = room693 694 695 def _getRoom(self, roomJID):691 roomJID = room.occupantJID.userhostJID() 692 self._rooms[roomJID] = room 693 694 695 def _getRoom(self, occupantJID): 696 696 """ 697 697 Grab a room from the room collection. … … 700 700 the L{Room} instance associated with it. 701 701 """ 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): 707 707 """ 708 708 Delete a room from the room collection. 709 709 """ 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] 713 713 714 714 … … 722 722 if not prs.hasAttribute('from'): 723 723 return 724 roomJID = jid.internJID(prs.getAttribute('from', ''))725 self._userLeavesRoom( roomJID)724 occupantJID = jid.internJID(prs.getAttribute('from', '')) 725 self._userLeavesRoom(occupantJID) 726 726 727 727 … … 733 733 if not prs.hasAttribute('from'): 734 734 return 735 roomJID = jid.internJID(prs.getAttribute('from', ''))735 occupantJID = jid.internJID(prs.getAttribute('from', '')) 736 736 # add an error hook here? 737 self._userLeavesRoom( roomJID)737 self._userLeavesRoom(occupantJID) 738 738 739 739 … … 750 750 751 751 752 def _userLeavesRoom(self, roomJID):752 def _userLeavesRoom(self, occupantJID): 753 753 # when a user leaves a room we need to update it 754 room = self._getRoom( roomJID)754 room = self._getRoom(occupantJID) 755 755 if room is None: 756 756 # not in the room yet 757 757 return 758 758 # check if user is in roster 759 user = room.getUser( roomJID.resource)759 user = room.getUser(occupantJID.resource) 760 760 if user is None: 761 761 return … … 771 771 if not prs.hasAttribute('from'): 772 772 return 773 roomJID = jid.internJID(prs.getAttribute('from', ''))773 occupantJID = jid.internJID(prs.getAttribute('from', '')) 774 774 775 775 status = getattr(prs, 'status', None) … … 777 777 778 778 # grab room 779 room = self._getRoom( roomJID)779 room = self._getRoom(occupantJID) 780 780 if room is None: 781 781 # not in the room yet 782 782 return 783 user = self._changeUserStatus(room, roomJID, status, show)783 user = self._changeUserStatus(room, occupantJID, status, show) 784 784 785 785 if room.inRoster(user): … … 804 804 # need to return an error here 805 805 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) 809 809 if room is None: 810 810 # not in the room yet 811 811 return 812 user = room.getUser( roomJID.resource)812 user = room.getUser(occupantJID.resource) 813 813 delay = None 814 814 # need to check for delay and x stanzas for delay namespace for backwards compatability … … 830 830 if not msg.hasAttribute('from'): 831 831 return 832 roomJID = jid.internJID(msg['from'])832 occupantJID = jid.internJID(msg['from']) 833 833 834 834 # grab room 835 room = self._getRoom( roomJID)835 room = self._getRoom(occupantJID) 836 836 if room is None: 837 837 # not in the room yet 838 838 return 839 839 840 self.receivedSubject( roomJID, unicode(msg.subject))840 self.receivedSubject(occupantJID, unicode(msg.subject)) 841 841 842 842 … … 853 853 We have presence that says we joined a room. 854 854 """ 855 roomJID = jid.internJID(prs['from'])855 occupantJID = jid.internJID(prs['from']) 856 856 857 857 # check for errors … … 860 860 else: 861 861 # change the state of the room 862 room = self._getRoom( roomJID)862 room = self._getRoom(occupantJID) 863 863 if room is None: 864 864 raise NotFound … … 877 877 We have presence that says we left a room. 878 878 """ 879 roomJID = jid.internJID(prs['from'])879 occupantJID = jid.internJID(prs['from']) 880 880 881 881 # check for errors … … 884 884 else: 885 885 # change the state of the room 886 room = self._getRoom( roomJID)886 room = self._getRoom(occupantJID) 887 887 if room is None: 888 888 raise NotFound 889 self._removeRoom( roomJID)889 self._removeRoom(occupantJID) 890 890 891 891 d.callback(True) … … 968 968 969 969 @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} 971 971 972 972 @param timeout: The number of seconds to wait before the deferred is timed out. … … 1001 1001 1002 1002 1003 def configure(self, bareRoomJID, fields=[]):1003 def configure(self, roomJID, fields=[]): 1004 1004 """ 1005 1005 Configure a room. 1006 1006 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} 1009 1009 1010 1010 @param fields: The fields we want to modify. … … 1012 1012 """ 1013 1013 request = ConfigureRequest(self.xmlstream, method='set', fields=fields) 1014 request['to'] = bareRoomJID1014 request['to'] = roomJID 1015 1015 1016 1016 return request.send() 1017 1017 1018 1018 1019 def getConfigureForm(self, bareRoomJID):1019 def getConfigureForm(self, roomJID): 1020 1020 """ 1021 1021 Grab the configuration form from the room. This sends an iq request to the room. 1022 1022 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} 1025 1025 """ 1026 1026 request = ConfigureRequest(self.xmlstream) 1027 request['to'] = bareRoomJID1027 request['to'] = roomJID 1028 1028 return request.send() 1029 1029 … … 1034 1034 1035 1035 @param server: The server where the room is located. 1036 @type server: L{unicode}1036 @type server: C{unicode} 1037 1037 1038 1038 @param room: The room name the entity is joining. 1039 @type room: L{unicode}1039 @type room: C{unicode} 1040 1040 1041 1041 @param nick: The nick name for the entitity joining the room. 1042 @type nick: L{unicode}1042 @type nick: C{unicode} 1043 1043 1044 1044 @param history: The maximum number of history stanzas you would like. … … 1050 1050 self._addRoom(room) 1051 1051 1052 p = BasicPresence(to=room. roomJID)1052 p = BasicPresence(to=room.occupantJID) 1053 1053 if history is not None: 1054 1054 p.x.addChild(history.toElement()) … … 1057 1057 1058 1058 # add observer for joining the room 1059 query = PRESENCE + u"[@from='%s']" % room. roomJID1059 query = PRESENCE + u"[@from='%s']" % room.occupantJID 1060 1060 self.xmlstream.addOnetimeObserver(query, self._joinedRoom, 1, d) 1061 1061 … … 1063 1063 1064 1064 1065 def _changeUserStatus(self, room, roomJID, status, show):1065 def _changeUserStatus(self, room, occupantJID, status, show): 1066 1066 """ 1067 1067 Change the user status in a room. … … 1069 1069 1070 1070 # check if user is in roster 1071 user = room.getUser( roomJID.resource)1071 user = room.getUser(occupantJID.resource) 1072 1072 if user is None: # create a user that does not exist 1073 user = User( roomJID.resource)1073 user = User(occupantJID.resource) 1074 1074 1075 1075 if status is not None: … … 1081 1081 1082 1082 1083 def _changed(self, d, roomJID, prs):1083 def _changed(self, d, occupantJID, prs): 1084 1084 """ 1085 1085 Callback for changing the nick and status. … … 1089 1089 show = getattr(prs, 'show', None) 1090 1090 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) 1094 1094 1095 1095 d.callback(room) 1096 1096 1097 1097 1098 def nick(self, bareRoomJID, new_nick):1098 def nick(self, roomJID, new_nick): 1099 1099 """ 1100 1100 Change an entities nick name in a MUC room. … … 1102 1102 See: http://xmpp.org/extensions/xep-0045.html#changenick 1103 1103 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} 1106 1106 1107 1107 @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 1167 1112 room = self._getRoom(roomJID) 1168 1113 if room is None: 1169 1114 raise NotFound 1170 1115 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) 1172 1172 if status is not None: 1173 1173 p.addElement('status', None, status) … … 1179 1179 1180 1180 # add observer for joining the room 1181 query = PRESENCE + u"[@from='%s']" % room. roomJID1182 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) 1183 1183 1184 1184 return d … … 1205 1205 1206 1206 1207 def chat(self, roomJID, message, children=None):1207 def chat(self, occupantJID, message, children=None): 1208 1208 """ 1209 1209 Send a private chat message to a user in a MUC room. … … 1211 1211 See: http://xmpp.org/extensions/xep-0045.html#privatemessage 1212 1212 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) 1218 1218 1219 1219 self._sendMessage(msg, children=children) 1220 1220 1221 1221 1222 def invite(self, bareRoomJID, reason=None, invitee=None):1222 def invite(self, roomJID, reason=None, invitee=None): 1223 1223 """ 1224 1224 Invite a xmpp entity to a MUC room. … … 1226 1226 See: http://xmpp.org/extensions/xep-0045.html#invite 1227 1227 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} 1230 1230 1231 1231 @param reason: The reason for the invite. 1232 @type reason: L{unicode}1232 @type reason: C{unicode} 1233 1233 1234 1234 @param invitee: The entity that is being invited. 1235 1235 @type invitee: L{jid.JID} 1236 1236 """ 1237 msg = InviteMessage( bareRoomJID, reason=reason, invitee=invitee)1237 msg = InviteMessage(roomJID, reason=reason, invitee=invitee) 1238 1238 self._sendMessage(msg) 1239 1239 1240 1240 1241 def password(self, bareRoomJID, password):1241 def password(self, roomJID, password): 1242 1242 """ 1243 1243 Send a password to a room so the entity can join. … … 1245 1245 See: http://xmpp.org/extensions/xep-0045.html#enter-pw 1246 1246 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} 1249 1249 1250 1250 @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) 1254 1254 1255 1255 self.xmlstream.send(p) 1256 1256 1257 1257 1258 def register(self, bareRoomJID, fields=[]):1258 def register(self, roomJID, fields=[]): 1259 1259 """ 1260 1260 Send a request to register for a room. 1261 1261 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} 1264 1264 1265 1265 @param fields: The fields you need to register. … … 1267 1267 """ 1268 1268 iq = RegisterRequest(self.xmlstream, method='set', fields=fields) 1269 iq['to'] = bareRoomJID.userhost()1269 iq['to'] = roomJID.userhost() 1270 1270 return iq.send() 1271 1271 1272 1272 1273 def _getAffiliationList(self, bareRoomJID, affiliation):1273 def _getAffiliationList(self, roomJID, affiliation): 1274 1274 """ 1275 1275 Send a request for an affiliation list in a room. … … 1279 1279 affiliation=affiliation, 1280 1280 ) 1281 iq['to'] = bareRoomJID.userhost()1281 iq['to'] = roomJID.userhost() 1282 1282 return iq.send() 1283 1283 1284 1284 1285 def _getRoleList(self, bareRoomJID, role):1285 def _getRoleList(self, roomJID, role): 1286 1286 """ 1287 1287 Send a role request. … … 1291 1291 role=role, 1292 1292 ) 1293 iq['to'] = bareRoomJID.full()1293 iq['to'] = roomJID.full() 1294 1294 return iq.send() 1295 1295 1296 1296 1297 def _setAffiliationList(self, iq, affiliation, roomJID):1297 def _setAffiliationList(self, iq, affiliation, occupantJID): 1298 1298 # set a rooms affiliation list 1299 room = self._getRoom( roomJID)1299 room = self._getRoom(occupantJID) 1300 1300 if room is not None: 1301 1301 affiliation_list = [] … … 1323 1323 1324 1324 1325 def getMemberList(self, bareRoomJID):1325 def getMemberList(self, roomJID): 1326 1326 """ 1327 1327 Get the member list of a room. 1328 1328 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) 1334 1334 return d 1335 1335 1336 1336 1337 def getAdminList(self, bareRoomJID):1337 def getAdminList(self, roomJID): 1338 1338 """ 1339 1339 Get the admin list of a room. 1340 1340 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) 1346 1346 return d 1347 1347 1348 1348 1349 def getBanList(self, bareRoomJID):1349 def getBanList(self, roomJID): 1350 1350 """ 1351 1351 Get an outcast list from a room. 1352 1352 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) 1358 1358 return d 1359 1359 1360 1360 1361 def getOwnerList(self, bareRoomJID):1361 def getOwnerList(self, roomJID): 1362 1362 """ 1363 1363 Get an owner list from a room. 1364 1364 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) 1370 1370 return d 1371 1371 … … 1383 1383 1384 1384 1385 def destroy(self, bareRoomJID, reason=None, alternate=None):1385 def destroy(self, roomJID, reason=None, alternate=None): 1386 1386 """ 1387 1387 Destroy a room. 1388 1388 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} 1391 1391 1392 1392 @param reason: The reason we are destroying the room. 1393 @type reason: L{unicode}1393 @type reason: C{unicode} 1394 1394 1395 1395 @param alternate: The bare JID of the room suggested as an alternate … … 1399 1399 """ 1400 1400 def destroyed(iq): 1401 self._removeRoom( bareRoomJID)1401 self._removeRoom(roomJID) 1402 1402 return True 1403 1403 1404 1404 iq = OwnerRequest(self.xmlstream, method='set') 1405 iq['to'] = bareRoomJID.userhost()1405 iq['to'] = roomJID.userhost() 1406 1406 d = iq.query.addElement('destroy') 1407 1407 … … 1414 1414 1415 1415 1416 def subject(self, bareRoomJID, subject):1416 def subject(self, roomJID, subject): 1417 1417 """ 1418 1418 Change the subject of a MUC room. … … 1420 1420 See: http://xmpp.org/extensions/xep-0045.html#subject-mod 1421 1421 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} 1424 1424 1425 1425 @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) 1429 1429 self.xmlstream.send(msg) 1430 1430 1431 1431 1432 def voice(self, bareRoomJID):1432 def voice(self, roomJID): 1433 1433 """ 1434 1434 Request voice for a moderated room. 1435 1435 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()) 1440 1440 self.xmlstream.send(msg) 1441 1441 1442 1442 1443 def history(self, bareRoomJID, messages):1443 def history(self, roomJID, messages): 1444 1444 """ 1445 1445 Send history to create a MUC based on a one on one chat. … … 1447 1447 See: http://xmpp.org/extensions/xep-0045.html#continue 1448 1448 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} 1451 1451 1452 1452 @param messages: The history to send to the room as an ordered list of … … 1469 1469 delay['from'] = sender 1470 1470 1471 stanza['to'] = bareRoomJID.userhost()1471 stanza['to'] = roomJID.userhost() 1472 1472 if stanza.hasAttribute('from'): 1473 1473 del stanza['from'] … … 1476 1476 1477 1477 1478 def _setAffiliation(self, bareRoomJID, entityOrNick, affiliation,1478 def _setAffiliation(self, roomJID, entityOrNick, affiliation, 1479 1479 reason=None, sender=None): 1480 1480 """ … … 1486 1486 affiliation=affiliation, 1487 1487 reason=reason) 1488 iq['to'] = bareRoomJID.userhost()1488 iq['to'] = roomJID.userhost() 1489 1489 if sender is not None: 1490 1490 iq['from'] = unicode(sender) … … 1493 1493 1494 1494 1495 def _setRole(self, bareRoomJID, entityOrNick, role,1495 def _setRole(self, roomJID, entityOrNick, role, 1496 1496 reason=None, sender=None): 1497 1497 # send a role request … … 1502 1502 reason=reason) 1503 1503 1504 iq['to'] = bareRoomJID.userhost()1504 iq['to'] = roomJID.userhost() 1505 1505 if sender is not None: 1506 1506 iq['from'] = unicode(sender) … … 1508 1508 1509 1509 1510 def modifyAffiliationList(self, frm, bareRoomJID, jid_list, affiliation):1510 def modifyAffiliationList(self, frm, roomJID, jid_list, affiliation): 1511 1511 """ 1512 1512 Modify an affiliation list. … … 1515 1515 @type frm: L{jid.JID} 1516 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. 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. 1522 1524 1523 1525 @param affiliation: The affilation to change. 1524 @type affiliation: L{unicode}1526 @type affiliation: C{unicode} 1525 1527 1526 1528 """ … … 1530 1532 ) 1531 1533 iq.items(jid_list) 1532 iq['to'] = bareRoomJID.userhost()1534 iq['to'] = roomJID.userhost() 1533 1535 iq['from'] = frm.full() 1534 1536 return iq.send() 1535 1537 1536 1538 1537 def grantVoice(self, bareRoomJID, nick, reason=None, sender=None):1539 def grantVoice(self, roomJID, nick, reason=None, sender=None): 1538 1540 """ 1539 1541 Grant voice to an entity. 1540 1542 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} 1546 1548 1547 1549 @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, 1554 1556 role='participant', 1555 1557 reason=reason, sender=sender) 1556 1558 1557 1559 1558 def revokeVoice(self, bareRoomJID, nick, reason=None, sender=None):1560 def revokeVoice(self, roomJID, nick, reason=None, sender=None): 1559 1561 """ 1560 1562 Revoke voice from a participant. … … 1562 1564 This will disallow the entity to send messages to a moderated room. 1563 1565 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 tothe 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', 1577 1579 reason=reason, sender=sender) 1578 1580 1579 1581 1580 def grantModerator(self, frm, room_jid, reason=None, nick=None):1582 def grantModerator(self, roomJID, nick, reason=None, sender=None): 1581 1583 """ 1582 1584 Grant moderator priviledges to a MUC room. 1583 1585 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): 1594 1603 """ 1595 1604 Ban a user from a MUC room. 1596 1605 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} 1605 1611 1606 1612 @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', 1613 1619 reason=reason, sender=sender) 1614 1620 1615 1621 1616 def kick(self, bareRoomJID, entityOrNick, reason=None, sender=None):1622 def kick(self, roomJID, entityOrNick, reason=None, sender=None): 1617 1623 """ 1618 1624 Kick a user from a MUC room. 1619 1625 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} 1628 1631 1629 1632 @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 88 88 89 89 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') 92 93 93 94 … … 122 123 123 124 def cb(room): 124 self.assertEqual s(self.test_room, room.roomIdentifier)125 self.assertEqual(self.test_room, room.roomIdentifier) 125 126 126 127 d = self.protocol.join(self.test_srv, self.test_room, self.test_nick) … … 468 469 469 470 def cb(room): 470 self.assertEqual s(self.test_room, room.roomIdentifier)471 self.assertEqual s(test_nick, room.nick)471 self.assertEqual(self.test_room, room.roomIdentifier) 472 self.assertEqual(test_nick, room.nick) 472 473 473 474 d = self.protocol.nick(self.room_jid, test_nick) … … 519 520 520 521 def cb(room): 521 self.assertEqual s(self.test_room, room.roomIdentifier)522 self.assertEqual(self.test_room, room.roomIdentifier) 522 523 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') 526 527 527 528 d = self.protocol.status(self.room_jid, 'xa', 'testing MUC') … … 530 531 prs = self.stub.output[-1] 531 532 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') 534 535 535 536 # send back user presence, they joined … … 546 547 self.assertEqual(1, len(members)) 547 548 user = members[0] 548 self.assertEqual s(JID(u'hag66@shakespeare.lit'), user.entity)549 self.assertEqual s(u'thirdwitch', user.nick)550 self.assertEqual s(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) 551 552 552 553 self._createRoom() … … 558 559 query = iq.query 559 560 self.assertNotIdentical(None, query) 560 self.assertEqual s(NS_MUC_ADMIN, query.uri)561 self.assertEqual(NS_MUC_ADMIN, query.uri) 561 562 562 563 response = toResponse(iq, 'result')
Note: See TracChangeset
for help on using the changeset viewer.