How to use the txaio.create_future_success function in txaio

To help you get started, we’ve selected a few txaio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github crossbario / txaio / test / test_is_future.py View on Github external
def test_is_called(framework):
    f = txaio.create_future_success(None)
    assert txaio.is_called(f)
github crossbario / txaio / test / test_callback.py View on Github external
def test_immediate_result(framework):
    f = txaio.create_future_success("it worked")
    results = []

    def cb(f):
        results.append(f)
    txaio.add_callbacks(f, cb, None)

    run_once()

    assert len(results) == 1
    assert results[0] == "it worked"
github crossbario / txaio / test / test_as_future.py View on Github external
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()
github crossbario / autobahn-python / autobahn / wamp / component.py View on Github external
def stop(self):
        self._stopping = True
        if self._session and self._session.is_attached():
            return self._session.leave()
        elif self._delay_f:
            # This cancel request will actually call the "error" callback of
            # the _delay_f future. Nothing to worry about.
            return txaio.as_future(txaio.cancel, self._delay_f)
        # if (for some reason -- should we log warning here to figure
        # out if this can evern happen?) we've not fired _done_f, we
        # do that now (causing our "main" to exit, and thus react() to
        # quit)
        if not txaio.is_called(self._done_f):
            txaio.resolve(self._done_f, None)
        return txaio.create_future_success(None)
github Kitware / VTK / ThirdParty / AutobahnPython / vtkAutobahn / autobahn / wamp / protocol.py View on Github external
def _errback_outstanding_requests(self, exc):
        """
        Errback any still outstanding requests with exc.
        """
        d = txaio.create_future_success(None)
        all_requests = [
            self._publish_reqs,
            self._subscribe_reqs,
            self._unsubscribe_reqs,
            self._call_reqs,
            self._register_reqs,
            self._unregister_reqs
        ]
        outstanding = []
        for requests in all_requests:
            outstanding.extend(requests.values())
            requests.clear()

        if outstanding:
            self.log.info(
                'Cancelling {count} outstanding requests',
github crossbario / crossbar / crossbar / router / router.py View on Github external
"""
        assert(type(uri) == str)
        assert(action in ['call', 'register', 'publish', 'subscribe'])

        # the role under which the session that wishes to perform the given action on
        # the given URI was authenticated under
        role = session._authrole

        if role in self._roles:
            # the authorizer procedure of the role which we will call ..
            authorize = self._roles[role].authorize
            d = txaio.as_future(authorize, session, uri, action, options)
        else:
            # normally, the role should exist on the router (and hence we should not arrive
            # here), but the role might have been dynamically removed - and anyway, safety first!
            d = txaio.create_future_success(False)

        # XXX would be nicer for dynamic-authorizer authors if we
        # sanity-checked the return-value ('authorization') here
        # (i.e. is it a dict? does it have 'allow' in it? does it have
        # disallowed keys in it?)

        def got_authorization(authorization):
            # backward compatibility
            if isinstance(authorization, bool):
                authorization = {
                    'allow': authorization,
                    'cache': False
                }
                if action in ['call', 'publish']:
                    authorization['disclose'] = False
github Kitware / VTK / ThirdParty / AutobahnPython / vtkAutobahn / autobahn / wamp / cryptosign.py View on Github external
:rtype: bytes
            """
            if not self._can_sign:
                raise Exception("a signing key required to sign")

            if type(data) != six.binary_type:
                raise Exception("data to be signed must be binary")

            # sig is a nacl.signing.SignedMessage
            sig = self._key.sign(data)

            # we only return the actual signature! if we return "sig",
            # it get coerced into the concatenation of message + signature
            # not sure which order, but we don't want that. we only want
            # the signature
            return txaio.create_future_success(sig.signature)