Exemplo n.º 1
0
    def dispatch(self, el):
        """
        This function realize incoming data handling.
        
        There is a handling :
        
        -- returns callback/errorback value for result/error-type stanzas
        
        -- calls handlers for other stanzas and then send the results
        
        :param el: is an input stanza
        
        """
        results = []
        el = MyElement.makeFromElement(el)
        for cls in (Iq, Message, Presence):
            try:
                el = cls.createFromElement(el, dont_defer=True)
            except WrongElement:
                pass

        if el.type_ in ('result', 'error') and self._callbacks.has_key(el.id):
            # XXX: check sender here
            id = el.id
            deferred, result_class, error_class = self._callbacks[id]
            if result_class is not None and el.type_ == 'result':
                try:
                    el = result_class.createFromElement(el, host=None)
                # XXX: catch any exception here
                except (WrongElement, ElementParseError), e:
                    deferred.errback(e)
                else:
                    deferred.callback(el)
            elif result_class is None and el.type_ == 'result':
                deferred.callback(el)
            elif el.type_ == 'error':
                exception = None
                try:
                    err = error_class.createFromElement(el,
                                                        host=None,
                                                        dispatcher=self)
                except (WrongElement, ElementParseError), e:
                    exception = e
                if exception is None:
                    exception = errors.exception_by_condition(
                        err.error.condition)
                deferred.errback(exception)
Exemplo n.º 2
0
    def dispatch(self, el):
        """
        This function realize incoming data handling.
        
        There is a handling :
        
        -- returns callback/errorback value for result/error-type stanzas
        
        -- calls handlers for other stanzas and then send the results
        
        :param el: is an input stanza
        
        """
        results = []
        el = MyElement.makeFromElement(el)
        for cls in (Iq, Message, Presence):
            try:
                el = cls.createFromElement(el, dont_defer=True)
            except WrongElement:
                pass

        if el.type_ in ('result', 'error') and self._callbacks.has_key(el.id):
            # XXX: check sender here
            id = el.id
            deferred, result_class, error_class = self._callbacks[id]
            if result_class is not None and el.type_ == 'result':
                try:
                    el = result_class.createFromElement(el, host=None)
                # XXX: catch any exception here
                except (WrongElement, ElementParseError), e:
                    deferred.errback(e)
                else:
                    deferred.callback(el)
            elif result_class is None and el.type_ == 'result':
                deferred.callback(el)
            elif el.type_ == 'error':
                exception = None
                try:
                    err = error_class.createFromElement(el, host=None,
                                                        dispatcher=self)
                except (WrongElement, ElementParseError), e:
                    exception = e
                if exception is None:
                    exception = errors.exception_by_condition(err.error.condition)
                deferred.errback(exception)
Exemplo n.º 3
0
 def test_exception_by_condition(self):
     err = errors.exception_by_condition(
         ErrCondition('forbidden', 'content'))
     self.assertTrue(isinstance(err, errors.ForbiddenException))