How to use the tinyrpc.protocols.jsonrpc.JSONRPCProtocol function in tinyrpc

To help you get started, we’ve selected a few tinyrpc 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 mbr / tinyrpc / tests / test_jsonrpc.py View on Github external
def prot():
    from tinyrpc.protocols.jsonrpc import JSONRPCProtocol

    return JSONRPCProtocol()
github mbr / tinyrpc / tests / test_protocols.py View on Github external
def protocol(request):
    if 'jsonrpc':
        return JSONRPCProtocol()

    raise RuntimeError('Bad protocol name in test case')
github MatrixAINetwork / go-matrix / cmd / clef / pythonsigner.py View on Github external
def main(args):

    cmd = ["./clef", "--stdio-ui"]
    if len(args) > 0 and args[0] == "test":
        cmd.extend(["--stdio-ui-test"])
    print("cmd: {}".format(" ".join(cmd)))
    dispatcher = RPCDispatcher()
    dispatcher.register_instance(StdIOHandler(), '')
    # line buffered
    p = subprocess.Popen(cmd, bufsize=1, universal_newlines=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)

    rpc_server = RPCServer(
        PipeTransport(p.stdout, p.stdin),
        JSONRPCProtocol(),
        dispatcher
    )
    rpc_server.serve_forever()
github mbr / tinyrpc / examples / http_client_example.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from tinyrpc.protocols.jsonrpc import JSONRPCProtocol
from tinyrpc.transports.http import HttpPostClientTransport
from tinyrpc import RPCClient

rpc_client = RPCClient(
    JSONRPCProtocol(),
    HttpPostClientTransport('http://127.0.0.1:5000/')
)

remote_server = rpc_client.get_proxy()

# call a method called 'reverse_string' with a single string argument
result = remote_server.reverse_string('Hello, World!')

print("Server answered:", result)
github osrg / ryu / ryu / app / wsgi.py View on Github external
def __init__(self, ws):
        self.ws = ws
        self.queue = hub.Queue()
        super(WebSocketRPCClient, self).__init__(
            JSONRPCProtocol(),
            WebSocketClientTransport(ws, self.queue),
        )
github mbr / tinyrpc / tinyrpc / protocols / jsonrpc.py View on Github external
def __init__(self, *args, **kwargs) -> None:
        super(JSONRPCProtocol, self).__init__(*args, **kwargs)
        self._id_counter = 0
github osrg / ryu / ryu / app / wsgi.py View on Github external
def __init__(self, ws, rpc_callback):
        dispatcher = RPCDispatcher()
        dispatcher.register_instance(rpc_callback)
        super(WebSocketRPCServer, self).__init__(
            WebSocketServerTransport(ws),
            JSONRPCProtocol(),
            dispatcher,
        )
github osrg / ryu / ryu / contrib / tinyrpc / transports / INTEGRATE_ME.py View on Github external
gevent.spawn(handle_client, message)


context = zmq.Context()
socket = context.socket(zmq.ROUTER)
socket.bind("tcp://127.0.0.1:12345")

dispatcher = RPCDispatcher()

@dispatcher.public
def throw_up():
    return 'asad'
    raise Exception('BLARGH')

rpc_server(socket, JSONRPCProtocol(), dispatcher)
github mbr / tinyrpc / tinyrpc / protocols / jsonrpc.py View on Github external
def _to_dict(self):
        jdata = {
            'jsonrpc': JSONRPCProtocol.JSON_RPC_VERSION,
            'method': self.method,
        }
        if self.args:
            jdata['params'] = self.args
        if self.kwargs:
            jdata['params'] = self.kwargs
        if not self.one_way and hasattr(
                self, 'unique_id') and self.unique_id is not None:
            jdata['id'] = self.unique_id
        return jdata