当前位置: 首页>>代码示例>>Python>>正文


Python txaio.add_callbacks函数代码示例

本文整理汇总了Python中txaio.add_callbacks函数的典型用法代码示例。如果您正苦于以下问题:Python add_callbacks函数的具体用法?Python add_callbacks怎么用?Python add_callbacks使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了add_callbacks函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_errback

def test_errback(framework):
    f = txaio.create_future()
    exception = RuntimeError("it failed")
    errors = []

    def err(f):
        errors.append(f)
    txaio.add_callbacks(f, None, err)
    try:
        raise exception
    except:
        fail = txaio.create_failure()
    txaio.reject(f, fail)

    run_once()

    assert len(errors) == 1
    assert isinstance(errors[0], txaio.IFailedFuture)
    assert exception == errors[0].value
    assert txaio.failure_traceback(errors[0]) is not None

    tb = txaio.failure_format_traceback(errors[0])

    assert 'RuntimeError' in tb
    assert 'it failed' in tb
    assert txaio.failure_message(errors[0]) == 'RuntimeError: it failed'
    assert 'it failed' in str(errors[0])
开发者ID:harpomarx,项目名称:txaio,代码行数:27,代码来源:test_errback.py

示例2: test_as_future_exception

def test_as_future_exception(framework):
    '''
    Raises an exception from as_future
    '''
    errors = []
    results = []
    calls = []
    exception = RuntimeError("sadness")

    def method(*args, **kw):
        calls.append((args, kw))
        raise exception
    f = txaio.as_future(method, 1, 2, 3, key='word')

    def cb(x):
        results.append(x)

    def errback(f):
        errors.append(f)

    txaio.add_callbacks(f, cb, errback)

    run_once()

    assert len(results) == 0
    assert len(errors) == 1
    assert errors[0].value == exception
    assert calls[0] == ((1, 2, 3), dict(key='word'))
开发者ID:oberstet,项目名称:txaio,代码行数:28,代码来源:test_as_future.py

示例3: transport_check

        def transport_check(_):
            self.log.debug('Entering re-connect loop')

            if not self._can_reconnect():
                err_msg = u"Component failed: Exhausted all transport connect attempts"
                self.log.info(err_msg)
                try:
                    raise RuntimeError(err_msg)
                except RuntimeError as e:
                    txaio.reject(self._done_f, e)
                    return

            while True:

                transport = next(transport_gen)

                if transport.can_reconnect():
                    transport_candidate[0] = transport
                    break

            delay = transport.next_delay()
            self.log.debug(
                'trying transport {transport_idx} using connect delay {transport_delay}',
                transport_idx=transport.idx,
                transport_delay=delay,
            )

            self._delay_f = txaio.sleep(delay)
            txaio.add_callbacks(self._delay_f, attempt_connect, error)
开发者ID:potens1,项目名称:autobahn-python,代码行数:29,代码来源:component.py

示例4: test_as_future_recursive

def test_as_future_recursive(framework):
    '''
    Returns another Future from as_future
    '''
    errors = []
    results = []
    calls = []
    f1 = txaio.create_future_success(42)

    def method(*args, **kw):
        calls.append((args, kw))
        return f1
    f0 = txaio.as_future(method, 1, 2, 3, key='word')

    def cb(x):
        results.append(x)

    def errback(f):
        errors.append(f)

    txaio.add_callbacks(f0, cb, errback)

    run_once()

    assert len(results) == 1
    assert len(errors) == 0
    assert results[0] == 42
    assert calls[0] == ((1, 2, 3), dict(key='word'))
开发者ID:oberstet,项目名称:txaio,代码行数:28,代码来源:test_as_future.py

示例5: onClose

    def onClose(self, wasClean):
        """
        Implements :func:`autobahn.wamp.interfaces.ITransportHandler.onClose`
        """
        self._transport = None

        if self._session_id:
            # fire callback and close the transport
            d = txaio.as_future(
                self.onLeave,
                types.CloseDetails(
                    reason=types.CloseDetails.REASON_TRANSPORT_LOST,
                    message="WAMP transport was lost without closing the session before",
                ),
            )

            def _error(e):
                return self._swallow_error(e, "While firing onLeave")

            txaio.add_callbacks(d, None, _error)

            self._session_id = None

        d = txaio.as_future(self.onDisconnect, wasClean)

        def _error(e):
            return self._swallow_error(e, "While firing onDisconnect")

        txaio.add_callbacks(d, None, _error)
开发者ID:proea,项目名称:autobahn-python,代码行数:29,代码来源:protocol.py

示例6: test_immediate_failure

def test_immediate_failure(framework):
    exception = RuntimeError("it failed")
    try:
        raise exception
    except:
        f0 = txaio.create_future_error()
        fail = txaio.create_failure()

    errors = []
    results = []
    f1 = txaio.create_future_error(fail)

    def cb(x):
        results.append(x)

    def errback(f):
        errors.append(f)

    txaio.add_callbacks(f0, cb, errback)
    txaio.add_callbacks(f1, cb, errback)

    run_once()
    run_once()
    run_once()

    assert len(results) == 0
    assert len(errors) == 2
    assert isinstance(errors[0], txaio.IFailedFuture)
    assert isinstance(errors[1], txaio.IFailedFuture)
    assert errors[0].value == exception
    assert errors[1].value == exception
    # should be distinct FailedPromise instances
    assert id(errors[0]) != id(errors[1])
开发者ID:harpomarx,项目名称:txaio,代码行数:33,代码来源:test_errback.py

示例7: introspectRemoteObject

    def introspectRemoteObject(self, busName, objectPath,
                               replaceKnownInterfaces=False):
        """
        Calls org.freedesktop.DBus.Introspectable.Introspect

        @type busName: C{string}
        @param busName: Name of the bus containing the object

        @type objectPath: C{string}
        @param objectPath: Object Path to introspect
        
        @type replaceKnownInterfaces: C{bool}
        @param replaceKnownInterfaces: If True (defaults to False), the content of
                                       the introspected XML will override any
                                       pre-existing definitions of the contained
                                       interfaces.

        @rtype: L{twisted.internet.defer.Deferred}
        @returns: a Deferred to a list of L{interface.DBusInterface} instances
                  created from the content of the introspected XML
                  description of the object's interface.
        """
        d = self.callRemote(objectPath, 'Introspect',
                            interface   = 'org.freedesktop.DBus.Introspectable',
                            destination = busName)

        def ok(xml_str):
            return introspection.getInterfacesFromXML(xml_str, replaceKnownInterfaces)

        def err(e):
            raise error.IntrospectionFailed('Introspection Failed: ' + e.getErrorMessage())

        txaio.add_callbacks(d, ok, err)

        return d
开发者ID:alexander255,项目名称:txdbus,代码行数:35,代码来源:client.py

示例8: test_as_future_immediate_none

def test_as_future_immediate_none(framework):
    '''
    Returning None immediately from as_future
    '''
    errors = []
    results = []
    calls = []

    def method(*args, **kw):
        calls.append((args, kw))
        return None
    f = txaio.as_future(method, 1, 2, 3, key='word')

    def cb(x):
        results.append(x)

    def errback(f):
        errors.append(f)

    txaio.add_callbacks(f, cb, errback)

    run_once()

    assert len(results) == 1
    assert len(errors) == 0
    assert results[0] is None
    assert calls[0] == ((1, 2, 3), dict(key='word'))
开发者ID:oberstet,项目名称:txaio,代码行数:27,代码来源:test_as_future.py

示例9: test_errback_reject_no_args

def test_errback_reject_no_args():
    """
    txaio.reject() with no args
    """

    f = txaio.create_future()
    exception = RuntimeError("it failed")
    errors = []

    def err(f):
        errors.append(f)
    txaio.add_callbacks(f, None, err)
    try:
        raise exception
    except:
        txaio.reject(f)

    run_once()

    assert len(errors) == 1
    assert isinstance(errors[0], txaio.IFailedFuture)
    assert exception == errors[0].value
    tb = txaio.failure_format_traceback(errors[0])

    assert 'RuntimeError' in tb
    assert 'it failed' in tb
    assert txaio.failure_message(errors[0]) == 'RuntimeError: it failed'
    assert 'it failed' in str(errors[0])
开发者ID:hlamer,项目名称:txaio,代码行数:28,代码来源:test_errback.py

示例10: test_create_error

def test_create_error():
    f = txaio.create_future(error=RuntimeError("test"))
    if txaio.using_twisted:
        assert f.called
    else:
        assert f.done()
    # cancel the error; we expected it
    txaio.add_callbacks(f, None, lambda _: None)
开发者ID:hlamer,项目名称:txaio,代码行数:8,代码来源:test_create.py

示例11: on_connect

        def on_connect(req):
            f = txaio.create_future()

            def cb(x):
                f = foo(42)
                f.add_callbacks(f, lambda v: values.append(v), None)
                return f
            txaio.add_callbacks(f, cb, None)
            return f
开发者ID:crossbario,项目名称:autobahn-python,代码行数:9,代码来源:test_asyncio_websocket.py

示例12: addMatch

    def addMatch(self, callback, mtype=None, sender=None, interface=None,
                 member=None, path=None, path_namespace=None, destination=None,
                 arg=None, arg_path=None, arg0namespace=None):
        """
        Creates a message matching rule, associates it with the specified
        callback function, and sends the match rule to the DBus daemon.
        The arguments to this function are exactly follow the DBus specification.
        Refer to the \"Message Bus Message Routing\" section of the DBus
        specification for details.

        @rtype: C{int}
        @returns: a L{Deferred} to an integer id that may be used to unregister the match rule
        """

        l = list()

        def add( k,v ):
            if v is not None:
                l.append( "%s='%s'" % (k,v) )

        add('type',           mtype)
        add('sender',         sender)
        add('interface',      interface)
        add('member',         member)
        add('path',           path)
        add('path_namespace', path_namespace)
        add('destination',    destination)

        if arg:
            for idx, v in arg:
                add('arg%d' % (idx,), v)

        if arg_path:
            for idx, v in arg_path:
                add('arg%dpath' % (idx,), v)

        add('arg0namespace', arg0namespace)

        rule = ','.join(l)

        d = self.callRemote('/org/freedesktop/DBus', 'AddMatch',
                            interface   = 'org.freedesktop.DBus',
                            destination = 'org.freedesktop.DBus',
                            body        = [rule],
                            signature   = 's')

        def ok(_):
            rule_id = self.router.addMatch(callback, mtype, sender, interface,
                                           member, path, path_namespace, destination,
                                           arg, arg_path, arg0namespace)
            self.match_rules[rule_id] = rule
            return rule_id

        txaio.add_callbacks(d, ok, None)

        return d
开发者ID:alexander255,项目名称:txdbus,代码行数:56,代码来源:client.py

示例13: actual_connect

                def actual_connect(_):
                    f = self._connect_once(loop, transport)

                    def session_done(x):
                        txaio.resolve(done_f, None)

                    def connect_error(fail):
                        if isinstance(fail.value, asyncio.CancelledError):
                            reconnect[0] = False
                            txaio.reject(done_f, fail)
                            return

                        self.log.debug(u'component failed: {error}', error=txaio.failure_message(fail))
                        self.log.debug(u'{tb}', tb=txaio.failure_format_traceback(fail))
                        # If this is a "fatal error" that will never work,
                        # we bail out now
                        if isinstance(fail.value, ApplicationError):
                            if fail.value.error in [u'wamp.error.no_such_realm']:
                                reconnect[0] = False
                                self.log.error(u"Fatal error, not reconnecting")
                                txaio.reject(done_f, fail)
                                return

                            self.log.error(u"{msg}", msg=fail.value.error_message())
                            return one_reconnect_loop(None)

                        elif isinstance(fail.value, OSError):
                            # failed to connect entirely, like nobody
                            # listening etc.
                            self.log.info(u"Connection failed: {msg}", msg=txaio.failure_message(fail))
                            return one_reconnect_loop(None)

                        elif _is_ssl_error(fail.value):
                            # Quoting pyOpenSSL docs: "Whenever
                            # [SSL.Error] is raised directly, it has a
                            # list of error messages from the OpenSSL
                            # error queue, where each item is a tuple
                            # (lib, function, reason). Here lib, function
                            # and reason are all strings, describing where
                            # and what the problem is. See err(3) for more
                            # information."
                            self.log.error(u"TLS failure: {reason}", reason=fail.value.args[1])
                            self.log.error(u"Marking this transport as failed")
                            transport.failed()
                        else:
                            self.log.error(
                                u'Connection failed: {error}',
                                error=txaio.failure_message(fail),
                            )
                            # some types of errors should probably have
                            # stacktraces logged immediately at error
                            # level, e.g. SyntaxError?
                            self.log.debug(u'{tb}', tb=txaio.failure_format_traceback(fail))
                            return one_reconnect_loop(None)

                    txaio.add_callbacks(f, session_done, connect_error)
开发者ID:Anggi-Permana-Harianja,项目名称:autobahn-python,代码行数:56,代码来源:component.py

示例14: onJoin

            def onJoin(self, details):
                d2 = self.subscribe(lambda: None, u'com.example.topic1')

                def ok(_):
                    txaio.resolve(d, None)

                def error(err):
                    txaio.reject(d, err)

                txaio.add_callbacks(d2, ok, error)
开发者ID:FirefighterBlu3,项目名称:crossbar,代码行数:10,代码来源:test_broker.py

示例15: component_start

 def component_start(comp):
     # the future from start() errbacks if we fail, or callbacks
     # when the component is considered "done" (so maybe never)
     d = txaio.as_future(comp.start, reactor)
     txaio.add_callbacks(
         d,
         partial(component_success, comp),
         partial(component_failure, comp),
     )
     return d
开发者ID:Hrabal,项目名称:autobahn-python,代码行数:10,代码来源:component.py


注:本文中的txaio.add_callbacks函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。