How to use the tinyrpc.server.RPCServer 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_server.py View on Github external
def test_handle_message(transport, protocol, dispatcher):
    server = RPCServer(transport, protocol, dispatcher)
    server.receive_one_message()
    
    transport.receive_message.assert_called()
    protocol.parse_request.assert_called_with(RECMSG)
    dispatcher.dispatch.assert_called_with(PARMSG)
    dispatcher.dispatch().serialize.assert_called()
    transport.send_reply.assert_called_with(CONTEXT, SERMSG)
github mbr / tinyrpc / tests / test_server.py View on Github external
def test_handle_message_callback(transport, protocol, dispatcher):
    server = RPCServer(transport, protocol, dispatcher)
    server.trace = Mock(return_value=None)
    server.receive_one_message()

    assert server.trace.call_args_list == [call('-->', CONTEXT, RECMSG), call('<--', CONTEXT, SERMSG)]
    server.trace.assert_called()
github osrg / ryu / ryu / app / wsgi.py View on Github external
class WebSocketServerTransport(ServerTransport):
    def __init__(self, ws):
        self.ws = ws

    def receive_message(self):
        message = self.ws.wait()
        if message is None:
            raise WebSocketDisconnectedError()
        context = None
        return context, message

    def send_reply(self, context, reply):
        self.ws.send(six.text_type(reply))


class WebSocketRPCServer(RPCServer):
    def __init__(self, ws, rpc_callback):
        dispatcher = RPCDispatcher()
        dispatcher.register_instance(rpc_callback)
        super(WebSocketRPCServer, self).__init__(
            WebSocketServerTransport(ws),
            JSONRPCProtocol(),
            dispatcher,
        )

    def serve_forever(self):
        try:
            super(WebSocketRPCServer, self).serve_forever()
        except WebSocketDisconnectedError:
            return

    def _spawn(self, func, *args, **kwargs):
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 MatrixAINetwork / go-matrix / run / 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 / tinyrpc / server / gevent.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import
import gevent

from . import RPCServer


class RPCServerGreenlets(RPCServer):
    # documentation in docs because of dependencies
    def _spawn(self, func, *args, **kwargs):
        gevent.spawn(func, *args, **kwargs)