Ignore:
Timestamp:
Aug 4, 2011, 8:53:23 PM (9 years ago)
Author:
Goffi <goffi@…>
Branch:
wokkel-muc-client-support-24
Message:

Replace custom error classes by StanzaError?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/muc.py

    r137 r138  
    8585DEFER_TIMEOUT = 30 # basic timeout is 30 seconds
    8686
    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 
    12987class NotFound(Exception):
    13088    """
     
    13290    condition = 'cancel'
    13391    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'] = feature
    165         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)
    18792
    18893
     
    736641        # add an error hook here?
    737642        self._userLeavesRoom(occupantJID)
    738 
    739 
    740     def _getExceptionFromElement(self, stanza):
    741         # find an exception based on the error stanza
    742         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.name
    748 
    749         return MUC_EXCEPTIONS[muc_condition]
    750 
    751643
    752644    def _userLeavesRoom(self, occupantJID):
     
    857749        # check for errors
    858750        if prs.hasAttribute('type') and prs['type'] == 'error':
    859             d.errback(self._getExceptionFromElement(prs))
     751            d.errback(error.exceptionFromStanza(prs))
    860752        else:
    861753            # change the state of the room
     
    881773        # check for errors
    882774        if prs.hasAttribute('type') and prs['type'] == 'error':
    883             d.errback(self._getExceptionFromElement(prs))
     775            d.errback(error.exceptionFromStanza(prs))
    884776        else:
    885777            # change the state of the room
Note: See TracChangeset for help on using the changeset viewer.