added RPCServer.help(); switched from SimpleXMLRPCServer to DocXMLRPCServer; some docstrings
This commit is contained in:
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user