added RPCServer.help(); switched from SimpleXMLRPCServer to DocXMLRPCServer; some docstrings

This commit is contained in:
2023-01-22 20:13:20 +01:00
parent bbda0da44d
commit c8cadfa364
2 changed files with 26 additions and 3 deletions

View File

@ -47,7 +47,7 @@ class MainWindow(QMainWindow):
self.setCentralWidget(splitter)
rst = RPCServerThread(host, port)
rst = RPCServerThread(host, port, doc_title_suffix="grum")
rst.start()
rst.server.register_function(self.new_plot)
rst.server.register_function(self.append_data)

View File

@ -1,16 +1,39 @@
import xmlrpc.server as xrs
from inspect import getdoc, signature
class RPCServer(xrs.SimpleXMLRPCServer):
class RPCServer(xrs.DocXMLRPCServer):
def __init__(self, host, port, *args, **kwargs):
def __init__(self, host, port, doc_title_suffix="", *args, **kwargs):
addr = (host, port)
kwargs.setdefault("allow_none", True)
super().__init__(addr, *args, **kwargs)
if doc_title_suffix:
self.server_name = doc_title_suffix + " " + self.server_name
self.server_title = doc_title_suffix + " " + self.server_title
self.register_function(self.ping)
self.register_function(self.help)
def ping(self):
"""
Returns "pong". May be used for testing the connection.
"""
return "pong"
def help(self):
"""
Returns a dict mapping names of exposed functions to dicts holding their signature and docstring.
"""
res = {}
for name, func in self.funcs.items():
doc = getdoc(func)
sig = str(signature(func))
res[name] = dict(signature=sig, docstring=doc)
return res