Advertisement
rfmonk

xmlrpclib_server.py

Feb 19th, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. from SimpleXMLRPCServer import SimpleXMLRPCServer
  5. from xmlrpclib import Binary
  6. import datetime
  7.  
  8. server = SimpleXMLRPCServer(('localhost', 9000),
  9.                             logRequests=True,
  10.                             allow_none=True)
  11. server.register_introspection_functions()
  12. server.register_multicall_functions()
  13.  
  14.  
  15. class ExampleService:
  16.  
  17.     def ping(self):
  18.         """Simple function to respond when called
  19.        to demonstrate connectivity.
  20.        """
  21.         return True
  22.  
  23.     def now(self):
  24.         """Returns the server current date and time."""
  25.         return datetime.datetime.now()
  26.  
  27.     def show_type(self, arg):
  28.         """Illustrates how types are passed in and out of
  29.        server methods.
  30.  
  31.        Accepts one argument of any type.
  32.        Returns a tuple with string representation of the value,
  33.        the name of the type, and the value itself.
  34.        """
  35.         return (str(arg), str(type(arg)), arg)
  36.  
  37.     def raises_exception(self, msg):
  38.         "Always raises a RuntimeError with the message passed in"
  39.         raise RuntimeError(msg)
  40.  
  41.     def send_back_binary(self, bin):
  42.         """Accepts single Binary argument, and unpacks and
  43.        repacks it to return it."""
  44.         data = bin.data
  45.         response = Binary(data)
  46.         return response
  47.  
  48. server.register_instance(ExampleService())
  49.  
  50. try:
  51.     print 'Use Control-C to exit'
  52.     server.serve_forever()
  53. except KeyboardInterrupt:
  54.     print 'Exiting'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement