forked from brandon-rhodes/fopnp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxmlrpc_server.py
35 lines (29 loc) · 1.07 KB
/
xmlrpc_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
# Foundations of Python Network Programming, Third Edition
# https://github.com/brandon-rhodes/fopnp/blob/m/py3/chapter18/xmlrpc_server.py
# XML-RPC server
import operator, math
from xmlrpc.server import SimpleXMLRPCServer
from functools import reduce
def main():
server = SimpleXMLRPCServer(('127.0.0.1', 7001))
server.register_introspection_functions()
server.register_multicall_functions()
server.register_function(addtogether)
server.register_function(quadratic)
server.register_function(remote_repr)
print("Server ready")
server.serve_forever()
def addtogether(*things):
"""Add together everything in the list `things`."""
return reduce(operator.add, things)
def quadratic(a, b, c):
"""Determine `x` values satisfying: `a` * x*x + `b` * x + c == 0"""
b24ac = math.sqrt(b*b - 4.0*a*c)
return list(set([ (-b-b24ac) / 2.0*a,
(-b+b24ac) / 2.0*a ]))
def remote_repr(arg):
"""Return the `repr()` rendering of the supplied `arg`."""
return arg
if __name__ == '__main__':
main()