Changeset 120:9548851ca5ac for wokkel
- Timestamp:
- Oct 20, 2008, 9:54:28 PM (14 years ago)
- Branch:
- wokkel-muc-client-support-24
- Convert:
- svn:b33ecbfc-034c-dc11-8662-000475d9059e/branches/wokkel-muc-client-support-24@116
- Location:
- wokkel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/muc.py
r119 r120 89 89 DEFER_TIMEOUT = 30 # basic timeout is 30 seconds 90 90 91 class JidMalformed(Exception): 92 """ 93 A jid malformed error from the server. 94 95 96 """ 97 condition = 'modify' 98 mucCondition = 'jid-malformed' 99 100 class NotAuthorized(Exception): 101 """ 102 """ 103 condition = 'auth' 104 mucCondition = 'not-authorized' 105 106 class RegistrationRequired(Exception): 107 """ 108 """ 109 condition = 'auth' 110 mucCondition = 'registration-required' 111 112 113 class Forbidden(Exception): 114 """ 115 """ 116 condition = 'auth' 117 mucCondition = 'forbidden' 118 119 120 MUC_EXCEPTIONS = { 121 'jid-malformed': JidMalformed, 122 'forbidden': Forbidden, 123 'not-authorized': NotAuthorized, 124 'exception': Exception, 125 } 126 91 127 class MUCError(error.StanzaError): 92 128 """ 93 129 Exception with muc specific condition. 94 130 """ 95 def __init__(self, condition, mucCondition, feature=None, text=None):131 def __init__(self, condition, mucCondition, type='error', feature=None, text=None): 96 132 appCondition = domish.Element((NS_MUC, mucCondition)) 97 133 if feature: 98 134 appCondition['feature'] = feature 99 135 error.StanzaError.__init__(self, condition, 136 type=type, 100 137 text=text, 101 138 appCondition=appCondition) … … 421 458 # add muc elements 422 459 x = self.addElement('x', NS_MUC) 460 423 461 # add error 424 self.addChild(error) 462 e = error.getElement() 463 self.addChild(e) 425 464 426 465 … … 476 515 # add an error hook here? 477 516 self._userLeavesRoom(room_jid) 517 518 def _getExceptionFromPresence(self, prs): 519 muc_condition = 'exception' 520 521 error = getattr(prs, 'error', None) 522 if error is not None: 523 for e in error.elements(): 524 muc_condition = e.name 525 526 return MUC_EXCEPTIONS[muc_condition] 478 527 479 528 def _userLeavesRoom(self, room_jid): … … 580 629 # check for errors 581 630 if prs.hasAttribute('type') and prs['type'] == 'error': 582 d.errback( prs)631 d.errback(self._getExceptionFromPresence(prs)) 583 632 else: 584 633 # change the state of the room … … 867 916 return iq.send() 868 917 869 def getMemberList(self, room_jid): 870 """ Get a member list from a room. 871 872 @param room_jid: The room jabber/xmpp entity id for the requested member list. 873 @type room_jid: L{jid.JID} 874 875 """ 918 919 def _getAffiliationList(self, room_jid, affiliation): 876 920 iq = AffiliationRequest(self.xmlstream, 877 921 method='get', 878 affiliation= 'member',922 affiliation=affiliation, 879 923 ) 880 924 iq['to'] = room_jid.full() 881 925 return iq.send() 882 926 927 928 929 def getMemberList(self, room_jid): 930 """ Get a member list from a room. 931 932 @param room_jid: The room jabber/xmpp entity id for the requested member list. 933 @type room_jid: L{jid.JID} 934 935 """ 936 return self._getAffiliationList(room_jid, 'member') 937 938 939 def getAdminList(self, room_jid): 940 """ Get an admin list from a room. 941 942 @param room_jid: The room jabber/xmpp entity id for the requested member list. 943 @type room_jid: L{jid.JID} 944 945 """ 946 return self._getAffiliationList(room_jid, 'admin') 947 948 def getBanList(self, room_jid): 949 """ Get an outcast list from a room. 950 951 @param room_jid: The room jabber/xmpp entity id for the requested member list. 952 @type room_jid: L{jid.JID} 953 954 """ 955 return self._getAffiliationList(room_jid, 'outcast') 956 957 def getOwnerList(self, room_jid): 958 """ Get an owner list from a room. 959 960 @param room_jid: The room jabber/xmpp entity id for the requested member list. 961 @type room_jid: L{jid.JID} 962 963 """ 964 return self._getAffiliationList(room_jid, 'owner') 965 883 966 884 967 def getRegisterForm(self, room): … … 892 975 iq['to'] = room.userhost() 893 976 return iq.send() 977 978 def destroy(self, room_jid, reason=None): 979 """ Destroy a room. 980 981 @param room_jid: The room jabber/xmpp entity id. 982 @type room_jid: L{jid.JID} 983 984 """ 985 def destroyed(iq): 986 self._removeRoom(room_jid) 987 return True 988 989 iq = OwnerRequest(self.xmlstream, method='set') 990 d = iq.query.addElement('destroy') 991 d['jid'] = room_jid.userhost() 992 if reason is not None: 993 d.addElement('reason', None, reason) 994 995 return iq.send().addCallback(destroyed) 894 996 895 997 def subject(self, to, subject): -
wokkel/test/test_muc.py
r118 r120 158 158 return d 159 159 160 160 161 161 162 def test_joinRoomForbidden(self): … … 164 165 165 166 def cb(error): 166 self.failUnless(isinstance(error.value,muc.PresenceError), 'Wrong type') 167 self.failUnless(error.value['type']=='error', 'Not an error returned') 167 168 self.failUnless(error.value.mucCondition=='forbidden','Wrong muc condition') 169 168 170 169 171
Note: See TracChangeset
for help on using the changeset viewer.