Changeset 125:edb21c02197b for wokkel
- Timestamp:
- Oct 21, 2008, 12:32:00 AM (14 years ago)
- Branch:
- wokkel-muc-client-support-24
- Convert:
- svn:b33ecbfc-034c-dc11-8662-000475d9059e/branches/wokkel-muc-client-support-24@121
- Location:
- wokkel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/muc.py
r124 r125 282 282 def __init__(self, xs, method='get', role='none', a_jid=None, reason=None): 283 283 AdminRequest.__init__(self, xs, method) 284 285 284 i = self.query.addElement('item') 286 285 … … 291 290 if reason: 292 291 i.addElement('reason', None, reason) 293 292 294 293 class GroupChat(domish.Element): 295 294 """ … … 660 659 661 660 def _onGroupChat(self, msg): 662 """ 661 """ A group chat message has been received from a MUC room. 662 663 There are a few event methods that may get called here. receviedGroupChat and receivedHistory 663 664 """ 664 665 if not msg.hasAttribute('from'): … … 686 687 687 688 def _onSubject(self, msg): 688 """ 689 """A subject has been sent from a MUC room. 689 690 """ 690 691 if not msg.hasAttribute('from'): … … 702 703 703 704 def _makeTimeStamp(self, stamp=None): 705 # create a timestamp 704 706 if stamp is None: 705 707 stamp = datetime.datetime.now() … … 754 756 755 757 def userJoinedRoom(self, room, user): 756 """User has joined a room 758 """User has joined a MUC room. 759 760 This method will need to be modified inorder for clients to 761 do something when this event occurs. 762 763 @param room: The room the user has joined. 764 @type room: L{Room} 765 766 @param user: The user that joined the MUC room. 767 @type user: L{User} 768 757 769 """ 758 770 pass 759 771 760 772 def userLeftRoom(self, room, user): 761 """User has left a room 773 """User has left a room. 774 775 This method will need to be modified inorder for clients to 776 do something when this event occurs. 777 778 @param room: The room the user has joined. 779 @type room: L{Room} 780 781 @param user: The user that joined the MUC room. 782 @type user: L{User} 783 762 784 """ 763 785 pass … … 766 788 def userUpdatedStatus(self, room, user, show, status): 767 789 """User Presence has been received 790 791 This method will need to be modified inorder for clients to 792 do something when this event occurs. 793 768 794 """ 769 795 pass … … 772 798 def receivedSubject(self, room, subject): 773 799 """ 800 This method will need to be modified inorder for clients to 801 do something when this event occurs. 802 774 803 """ 775 804 pass … … 778 807 def receivedHistory(self, room, user, message, history, frm=None): 779 808 """ 809 This method will need to be modified inorder for clients to 810 do something when this event occurs. 780 811 """ 781 812 pass … … 790 821 def sendDeferred(self, obj, timeout): 791 822 """ Send data or a domish element, adding a deferred with a timeout. 823 824 @param obj: The object to send over the wire. 825 @type obj: L{domish.Element} or L{unicode} 826 827 @param timeout: The number of seconds to wait before the deferred is timed out. 828 @type timeout: L{int} 829 830 The deferred object L{defer.Deferred} is returned. 792 831 """ 793 832 d = defer.Deferred() … … 817 856 818 857 def disco(self, entity, type='info'): 819 """Send disco queries to a XMPP entity 858 """Send disco queries to a XMPP entity. 859 860 @param entity: The server or entity where we want discovery information from. 861 @type entity: L{jid.JID} 862 863 @param type: The optional disco type. 864 @type type: L{unicode} 865 820 866 """ 821 867 … … 831 877 @param room_jid: The room jabber/xmpp entity id for the requested configuration form. 832 878 @type room_jid: L{jid.JID} 879 880 @param fields: The fields we want to modify. 881 @type fields: A L{list} or L{dataform.Field} 833 882 834 883 """ … … 977 1026 978 1027 def _sendMessage(self, msg, children=None): 979 1028 # send a message 980 1029 if children: 981 1030 for c in children: … … 991 1040 self._sendMessage(msg, children=children) 992 1041 993 def chat(self, to, message, children=None): 994 msg = PrivateChat(to, body=message) 1042 def chat(self, room_jid, message, children=None): 1043 """Send a private chat message to a user in a MUC room. 1044 1045 See: http://xmpp.org/extensions/xep-0045.html#privatemessage 1046 1047 @param room_jid: The room entity id. 1048 @type room_jid: L{jid.JID} 1049 1050 """ 1051 1052 msg = PrivateChat(room_jid, body=message) 995 1053 996 1054 self._sendMessage(msg, children=children) 997 1055 998 def invite(self, to, reason=None, full_jid=None): 999 """ 1000 """ 1001 msg = InviteMessage(to, reason=reason, full_jid=full_jid) 1056 def invite(self, room_jid, reason=None, full_jid=None): 1057 """Invite a xmpp entity to a MUC room. 1058 1059 See: http://xmpp.org/extensions/xep-0045.html#invite 1060 1061 @param room_jid: The room entity id. 1062 @type room_jid: L{jid.JID} 1063 1064 @param reason: The reason for the invite. 1065 @type reason: L{unicode} 1066 1067 @param full_jid: The xmpp user's entity id. 1068 @type full_jid: L{jid.JID} 1069 1070 """ 1071 msg = InviteMessage(room_jid, reason=reason, full_jid=full_jid) 1002 1072 self._sendMessage(msg) 1003 1073 1004 1074 1005 def password(self, to, password): 1006 p = PasswordPresence(to, password) 1075 def password(self, room_jid, password): 1076 """Send a password to a room so the entity can join. 1077 1078 See: http://xmpp.org/extensions/xep-0045.html#enter-pw 1079 1080 @param room_jid: The room entity id. 1081 @type room_jid: L{jid.JID} 1082 1083 @param password: The MUC room password. 1084 @type password: L{unicode} 1085 1086 """ 1087 p = PasswordPresence(room_jid, password) 1007 1088 1008 1089 self.xmlstream.send(p) 1009 1090 1010 1091 def register(self, to, fields=[]): 1092 """ 1093 """ 1011 1094 iq = RegisterRequest(self.xmlstream, method='set', fields=fields) 1012 1095 iq['to'] = to … … 1024 1107 1025 1108 def _getRoleList(self, room_jid, role): 1109 # send a role request 1026 1110 iq = RoleRequest(self.xmlstream, 1027 1111 method='get', … … 1033 1117 1034 1118 def _setAffiliationList(self, affiliation, room_jid, iq): 1119 # set a rooms affiliation list 1035 1120 r = self._getRoom(room_jid) 1036 1121 if r is not None: … … 1175 1260 role=role, 1176 1261 reason=reason) 1262 1177 1263 iq['to'] = room_jid.userhost() # this is a room jid, only send to room 1178 1264 iq['from'] = frm.full() … … 1186 1272 return r 1187 1273 1188 def grantVoice(self, frm, room_jid, reason=None):1189 return self._setRole(frm, room_jid, role='participant', reason=reason)1274 def grantVoice(self, frm, room_jid, voice_jid=None, reason=None): 1275 return self._setRole(frm, room_jid, role='participant', a_jid=voice_jid, reason=reason) 1190 1276 1191 1277 def grantVisitor(self, frm, room_jid, reason=None): -
wokkel/test/test_muc.py
r120 r125 74 74 def test_userJoinedRoom(self): 75 75 """The client receives presence from an entity joining the room. 76 77 This tests the class L{muc.UserPresence} and the userJoinedRoom event method. 78 79 The test sends the user presence and tests if the event method is called. 80 76 81 """ 77 82 p = muc.UserPresence() … … 184 189 self.stub.send(response) 185 190 return d 191 192 193 def test_joinRoomBadJid(self): 194 """Client joining a room and getting a forbidden error. 195 """ 196 197 def cb(error): 198 199 self.failUnless(error.value.mucCondition=='jid-malformed','Wrong muc condition') 200 201 202 203 d = self.protocol.join(self.test_srv, self.test_room, self.test_nick) 204 d.addBoth(cb) 205 206 prs = self.stub.output[-1] 207 self.failUnless(prs.name=='presence', "Need to be presence") 208 self.failUnless(getattr(prs, 'x', None), 'No muc x element') 209 # send back user presence, they joined 210 211 response = muc.PresenceError(error=muc.MUCError('modify', 212 'jid-malformed' 213 ), 214 frm=self.room_jid.full()) 215 self.stub.send(response) 216 return d 217 218 186 219 187 220 def test_partRoom(self): … … 442 475 return d 443 476 444 477 def test_grantVoice(self): 478 """Test granting voice to a user. 479 480 """ 481 give_voice = JID('ban@jabber.org/TroubleMakger') 482 def cb(give_voice): 483 self.failUnless(give_voice, 'Did not give voice user') 484 485 486 d = self.protocol.grantVoice(self.user_jid, self.room_jid, give_voice) 487 d.addCallback(cb) 488 489 iq = self.stub.output[-1] 490 491 self.failUnless(xpath.matches("/iq[@type='set' and @to='%s']/query/item[@role='participant']" % (self.room_jid.userhost(),), iq), 'Wrong voice stanza') 492 493 response = toResponse(iq, 'result') 494 495 self.stub.send(response) 496 497 return d 498 499
Note: See TracChangeset
for help on using the changeset viewer.