-
-
Save tsaridas/867c496cd1338df66f7412e8fd5bda55 to your computer and use it in GitHub Desktop.
Simple uWSGI + XML-RPC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import xmlrpclib | |
| s = xmlrpclib.ServerProxy('http://localhost:3040') | |
| print s.pow(2,3) | |
| print s.sum([2,3]) | |
| print s.system.listMethods() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # start uwsgi with this app, listening with http on some port | |
| uwsgi --wsgi xmlrpc_server --http :3040 | |
| # in another window | |
| python client.py | |
| # output should be 8, 5 and a list of functions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from SimpleXMLRPCServer import SimpleXMLRPCDispatcher | |
| dispatch = SimpleXMLRPCDispatcher() | |
| dispatch.register_introspection_functions() | |
| dispatch.register_function(pow) | |
| dispatch.register_function(sum) | |
| def application(environ, start_response): | |
| if environ["REQUEST_METHOD"] != "POST": | |
| start_response("500 Error", ()) | |
| return ["Only POST allowed"] | |
| try: | |
| length = int(environ.get('CONTENT_LENGTH', None)) | |
| except (TypeError, ValueError): | |
| length = -1 | |
| request_text = environ["wsgi.input"].read(length) | |
| response = dispatch._marshaled_dispatch(request_text) | |
| start_response("200 OK", [("Content-Type", "text/xml"), ("Content-Length", str(len(response)))]) | |
| return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment