Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# MessagePack-RPC Server/Client with mprpc module
2from ..client import ClientIf
3from ..server import ServerIf
4from logging import getLogger
5import functools
7import mprpc
8import mprpc.exceptions
9from gevent.server import StreamServer
11log = getLogger(__name__)
14class Server(ServerIf):
15 class MPServ(mprpc.RPCServer):
16 def __getattr__(self, name, dflt=None):
17 log.debug("getattr %s", name)
18 return functools.partial(self.d, name)
19 # try:
20 # if hasattr(self, name):
21 # return getattr(self, name, dflt)
22 # finally:
23 # return functools.partial(self.d, self, name)
25 def serve(self, dispatcher):
26 # does not work
27 srv = Server.MPServ()
28 srv.d = dispatcher
29 server = StreamServer(
30 (self.addr_parsed.hostname, self.addr_parsed.port), srv)
31 server.serve_forever()
34class Client(ClientIf):
35 def call(self, method: str, params=None):
36 log.debug("connect host=%s port=%s",
37 self.addr_parsed.hostname, self.addr_parsed.port)
38 cl = mprpc.RPCClient(self.addr_parsed.hostname, self.addr_parsed.port)
39 log.debug("call %s(%s)", method, params)
40 return cl.call(method, params)