Пример #1
0
def make_session(config):
    @coroutine
    def on_join(session, details):
        print("on_join: {}".format(details))

        def add2(a, b):
            return a + b

        yield session.register(add2, u"com.example.add2")

        try:
            res = yield session.call(u"com.example.add2", 2, 3)
            print("result: {}".format(res))
        except Exception as e:
            print("error: {}".format(e))
        finally:
            session.leave()

    session = Session(config=config)
    session.on("join", on_join)
    return session
Пример #2
0
def create_session(config):
    session = Session(config)
    session.add_authenticator(
        create_authenticator(
            "cryptosign",
            authid="foo",
            authrole="role0",
            privkey="a" * 64,
        ))

    def joined(session, details):
        print("joined: {} {}".format(session, details))
        session.config.extra['running'].callback(session)

    session.on('join', joined)

    def left(session, details):
        if "no_such_procedure" in str(details.reason):
            session.config.extra['running'].errback(Exception(details.reason))

    session.on('leave', left)

    def disconnected(*args, **kw):
        print("disconnect: {} {}".format(args, kw))

    session.on('disconnect', disconnected)

    return session
Пример #3
0
def make_session(config):

    @coroutine
    def on_join(session, details):
        print("on_join: {}".format(details))

        def add2(a, b):
            return a + b

        yield session.register(add2, 'com.example.add2')

        try:
            res = yield session.call('com.example.add2', 2, 3)
            print("result: {}".format(res))
        except Exception as e:
            print("error: {}".format(e))
        finally:
            session.leave()

    session = Session(config=config)
    session.on('join', on_join)
    return session