Ejemplo n.º 1
0
def consume(*args, **kwargs):
    print("!", args, kwargs)


endpoint = Endpoint(Dispatcher(), consume)
message = {
    "jsonrpc": "2.0",
    "method": "add",
    "params": {
        "x": 10,
        "y": 20
    },
}

print("-")
endpoint.consume(message)
print("-")
endpoint.consume(ChainMap({"id": 1}, message))

print("-")
endpoint.consume(ChainMap({"method": "foo", "id": 2}, message))

endpoint.shutdown()
# -
# DEBUG:pyls_jsonrpc.endpoint:Handling notification from client {'jsonrpc': '2.0', 'method': 'add', 'params': {'x': 10, 'y': 20}}
# -
# DEBUG:pyls_jsonrpc.endpoint:Handling request from client ChainMap({'id': 1}, {'jsonrpc': '2.0', 'method': 'add', 'params': {'x': 10, 'y': 20}})
# DEBUG:pyls_jsonrpc.endpoint:Got result from synchronous request handler: 30
# ! ({'jsonrpc': '2.0', 'id': 1, 'result': 30},) {}
# -
# DEBUG:pyls_jsonrpc.endpoint:Handling request from client ChainMap({'method': 'foo', 'id': 2}, {'jsonrpc': '2.0', 'method': 'add', 'params': {'x': 10, 'y': 20}})
Ejemplo n.º 2
0
        def cont() -> dict:

            time.sleep(1)
            print(f"*** {name}: bye ***")
            return {"time": time.time() - t}

        return cont


def consume(*args, **kwargs):
    print("!!!", args, kwargs)


logging.basicConfig(
    level=logging.DEBUG,
    format="\t" + logging.BASIC_FORMAT,
)
endpoint = Endpoint(Dispatcher(), consume)
message = {
    "jsonrpc": "2.0",
    "method": "hello",
    "params": {
        "name": "foo",
    },
}

endpoint.consume(ChainMap({"id": 1}, message))
endpoint.consume(ChainMap({"id": 2, "params": {"name": "bar"}}, message))
endpoint.shutdown()