Changeset 138:8332717e2739
- Timestamp:
- Aug 4, 2011, 8:53:23 PM (11 years ago)
- Branch:
- wokkel-muc-client-support-24
- Location:
- wokkel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/muc.py
r137 r138 85 85 DEFER_TIMEOUT = 30 # basic timeout is 30 seconds 86 86 87 class JidMalformed(Exception):88 """89 A jid malformed error from the server.90 91 """92 condition = 'modify'93 mucCondition = 'jid-malformed'94 95 96 97 class NotAuthorized(Exception):98 """99 """100 condition = 'auth'101 mucCondition = 'not-authorized'102 103 104 105 class RegistrationRequired(Exception):106 """107 """108 condition = 'auth'109 mucCondition = 'registration-required'110 111 112 113 class Forbidden(Exception):114 """115 """116 condition = 'auth'117 mucCondition = 'forbidden'118 119 120 121 class Conflict(Exception):122 """123 """124 condition = 'cancel'125 mucCondition = 'conflict'126 127 128 129 87 class NotFound(Exception): 130 88 """ … … 132 90 condition = 'cancel' 133 91 mucCondition = 'not-found' 134 135 136 137 class ServiceUnavailable(Exception):138 """139 """140 condition = 'wait'141 mucCondition = 'service-unavailable'142 143 144 145 MUC_EXCEPTIONS = {146 'jid-malformed': JidMalformed,147 'forbidden': Forbidden,148 'not-authorized': NotAuthorized,149 'exception': Exception,150 'conflict': Conflict,151 'service-unavailable': ServiceUnavailable,152 'not-found': NotFound,153 }154 155 156 157 class MUCError(error.StanzaError):158 """159 Exception with muc specific condition.160 """161 def __init__(self, condition, mucCondition, type='error', feature=None, text=None):162 appCondition = domish.Element((NS_MUC, mucCondition))163 if feature:164 appCondition['feature'] = feature165 error.StanzaError.__init__(self, condition,166 type=type,167 text=text,168 appCondition=appCondition)169 170 171 172 class BadRequest(MUCError):173 """174 Bad request stanza error.175 """176 def __init__(self, mucCondition=None, text=None):177 MUCError.__init__(self, 'bad-request', mucCondition, text)178 179 180 181 class Unsupported(MUCError):182 def __init__(self, feature, text=None):183 MUCError.__init__(self, 'feature-not-implemented',184 'unsupported',185 feature,186 text)187 92 188 93 … … 736 641 # add an error hook here? 737 642 self._userLeavesRoom(occupantJID) 738 739 740 def _getExceptionFromElement(self, stanza):741 # find an exception based on the error stanza742 muc_condition = 'exception'743 744 error = getattr(stanza, 'error', None)745 if error is not None:746 for e in error.elements():747 muc_condition = e.name748 749 return MUC_EXCEPTIONS[muc_condition]750 751 643 752 644 def _userLeavesRoom(self, occupantJID): … … 857 749 # check for errors 858 750 if prs.hasAttribute('type') and prs['type'] == 'error': 859 d.errback( self._getExceptionFromElement(prs))751 d.errback(error.exceptionFromStanza(prs)) 860 752 else: 861 753 # change the state of the room … … 881 773 # check for errors 882 774 if prs.hasAttribute('type') and prs['type'] == 'error': 883 d.errback( self._getExceptionFromElement(prs))775 d.errback(error.exceptionFromStanza(prs)) 884 776 else: 885 777 # change the state of the room -
wokkel/test/test_muc.py
r137 r138 18 18 19 19 from twisted.words.protocols.jabber.xmlstream import toResponse 20 from twisted.words.protocols.jabber.error import StanzaError 20 21 21 22 NS_MUC_ADMIN = 'http://jabber.org/protocol/muc#admin' … … 158 159 159 160 def cb(error): 160 self.assertEquals('forbidden', error.value. mucCondition,161 self.assertEquals('forbidden', error.value.condition, 161 162 'Wrong muc condition') 162 163 … … 186 187 187 188 def cb(error): 188 self.assertEquals('jid-malformed', error.value. mucCondition,189 self.assertEquals('jid-malformed', error.value.condition, 189 190 'Wrong muc condition') 190 191
Note: See TracChangeset
for help on using the changeset viewer.