Пример #1
0
async def test_9_batch_method_and_notifications(client: ServerProxy):
    notification = client.create_notification("test")

    results = await client(
        client.mirror.prepare(0),
        client.mirror.prepare(1),
        notification,
        client.mirror.prepare(2),
        client.mirror.prepare(3),
        client.test,
        notification.prepare(),
    )

    assert results == [0, 1, None, 2, 3, None, None]
Пример #2
0
    async def _create_from_app_factory(app_factory, *args, **kwargs):
        nonlocal test_client, rpc_client

        app = app_factory(*args, **kwargs)
        test_client = TestClient(TestServer(app))

        await test_client.start_server()

        rpc_client = ServerProxy("", client=test_client)

        add_cleanup(rpc_client.close)
        add_cleanup(test_client.close)

        return rpc_client
Пример #3
0
class Client(ClientIf):
    def __init__(self, addr: str, params: dict = {}):
        super().__init__(addr, params)
        self.cl = ServerProxy(self.addr)
        self.loop = asyncio.get_event_loop()

    def call(self, method: str, params=None):
        if isinstance(params, dict):
            res = self.cl[method](**params)
        elif isinstance(params, (tuple, list)):
            res = self.cl[method](*params)
        else:
            res = self.cl[method](params)
        return self.loop.run_until_complete(res)

    def __del__(self):
        return self.loop.run_until_complete(self.cl.close())
Пример #4
0
import asyncio
from aiohttp_jsonrpc.client import ServerProxy, batch

loop = asyncio.get_event_loop()
client = ServerProxy("http://127.0.0.1:8080/", loop=loop)


async def main():
    print(await client.test())

    # Or via __getitem__
    method = client['args']
    print(await method(1, 2, 3))

    results = await batch(
        client,
        client['test'],
        client['test'].prepare(),
        client['args'].prepare(1, 2, 3),
        client['not_found'].prepare(1, 2, 3),
    )

    print(results)

    client.close()


if __name__ == "__main__":
    loop.run_until_complete(main())
Пример #5
0
async def test_8_notification(client: ServerProxy):
    notification = client.create_notification("test")
    await notification()
Пример #6
0
import asyncio
from aiohttp_jsonrpc.client import ServerProxy, batch

# initialize a loop
loop = asyncio.get_event_loop()
client = ServerProxy("http://127.0.0.1:8888/api", loop=loop)


# lets list a virtual machines
async def main():
    print(await client.list_vms(preset='C_DEV-app-dev'))


# close a client
client.close()
loop.run_until_complete(main())
Пример #7
0
 def __init__(self, addr: str, params: dict = {}):
     super().__init__(addr, params)
     self.cl = ServerProxy(self.addr)
     self.loop = asyncio.get_event_loop()