How to use the jsonrpcserver.response.SuccessResponse function in jsonrpcserver

To help you get started, we’ve selected a few jsonrpcserver 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 bcb / jsonrpcserver / tests / test_response.py View on Github external
def test_success_response_null_id():
    # OK - any type of id is acceptable
    response = SuccessResponse("foo", id=None)
    assert str(response) == '{"jsonrpc": "2.0", "result": "foo", "id": null}'
github bcb / jsonrpcserver / tests / test_dispatcher.py View on Github external
def test_dispatch_pure_request():
    response = dispatch_pure(
        '{"jsonrpc": "2.0", "method": "ping", "id": 1}',
        Methods(ping),
        convert_camel_case=False,
        context=NOCONTEXT,
        debug=True,
        serialize=default_serialize,
        deserialize=default_deserialize,
    )
    assert isinstance(response, SuccessResponse)
    assert response.result == "pong"
    assert response.id == 1
github bcb / jsonrpcserver / tests / test_response.py View on Github external
def test_success_response():
    response = SuccessResponse("foo", id=1)
    assert response.wanted == True
    assert response.result == "foo"
    assert str(response) == '{"jsonrpc": "2.0", "result": "foo", "id": 1}'
github bcb / jsonrpcserver / tests / test_response.py View on Github external
def test_batch_response():
    response = BatchResponse(
        {SuccessResponse("foo", id=1), SuccessResponse("bar", id=2)}
    )
    expected = [
        {"jsonrpc": "2.0", "result": "foo", "id": 1},
        {"jsonrpc": "2.0", "result": "bar", "id": 2},
    ]
    assert response.wanted == True
    for r in response.deserialized():
        assert r in expected
github bcb / jsonrpcserver / tests / test_response.py View on Github external
def test_success_response_str():
    response = SuccessResponse("foo", id=1)
    assert str(response) == '{"jsonrpc": "2.0", "result": "foo", "id": 1}'
github bcb / jsonrpcserver / tests / test_response.py View on Github external
def test_success_response_null_result():
    # Perfectly fine.
    response = SuccessResponse(None, id=1)
    assert str(response) == '{"jsonrpc": "2.0", "result": null, "id": 1}'
github bcb / jsonrpcserver / jsonrpcserver / dispatcher.py View on Github external
Args:
        request: The Request object.
        methods: The list of methods that can be called.
        debug: Include more information in error responses.
        serialize: Function that is used to serialize data.

    Returns:
        A Response object.
    """
    with handle_exceptions(request, debug) as handler:
        result = call(lookup(methods, request.method), *request.args, **request.kwargs)
        # Ensure value returned from the method is JSON-serializable. If not,
        # handle_exception will set handler.response to an ExceptionResponse
        serialize(result)
        handler.response = SuccessResponse(
            result=result, id=request.id, serialize_func=serialize
        )
    return handler.response
github bcb / jsonrpcserver / jsonrpcserver / async_dispatcher.py View on Github external
async def safe_call(
    request: Request, methods: Methods, *, debug: bool, serialize: Callable
) -> Response:
    with handle_exceptions(request, debug) as handler:
        result = await call(
            lookup(methods, request.method), *request.args, **request.kwargs
        )
        # Ensure value returned from the method is JSON-serializable. If not,
        # handle_exception will set handler.response to an ExceptionResponse
        serialize(result)
        handler.response = SuccessResponse(
            result=result, id=request.id, serialize_func=serialize
        )
    return handler.response