17db96d56Sopenharmony_ci:mod:`xmlrpc.server` --- Basic XML-RPC servers
27db96d56Sopenharmony_ci==============================================
37db96d56Sopenharmony_ci
47db96d56Sopenharmony_ci.. module:: xmlrpc.server
57db96d56Sopenharmony_ci   :synopsis: Basic XML-RPC server implementations.
67db96d56Sopenharmony_ci
77db96d56Sopenharmony_ci.. moduleauthor:: Brian Quinlan <brianq@activestate.com>
87db96d56Sopenharmony_ci.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
97db96d56Sopenharmony_ci
107db96d56Sopenharmony_ci**Source code:** :source:`Lib/xmlrpc/server.py`
117db96d56Sopenharmony_ci
127db96d56Sopenharmony_ci--------------
137db96d56Sopenharmony_ci
147db96d56Sopenharmony_ciThe :mod:`xmlrpc.server` module provides a basic server framework for XML-RPC
157db96d56Sopenharmony_ciservers written in Python.  Servers can either be free standing, using
167db96d56Sopenharmony_ci:class:`SimpleXMLRPCServer`, or embedded in a CGI environment, using
177db96d56Sopenharmony_ci:class:`CGIXMLRPCRequestHandler`.
187db96d56Sopenharmony_ci
197db96d56Sopenharmony_ci
207db96d56Sopenharmony_ci.. warning::
217db96d56Sopenharmony_ci
227db96d56Sopenharmony_ci   The :mod:`xmlrpc.server` module is not secure against maliciously
237db96d56Sopenharmony_ci   constructed data.  If you need to parse untrusted or unauthenticated data see
247db96d56Sopenharmony_ci   :ref:`xml-vulnerabilities`.
257db96d56Sopenharmony_ci
267db96d56Sopenharmony_ci.. include:: ../includes/wasm-notavail.rst
277db96d56Sopenharmony_ci
287db96d56Sopenharmony_ci.. class:: SimpleXMLRPCServer(addr, requestHandler=SimpleXMLRPCRequestHandler,\
297db96d56Sopenharmony_ci               logRequests=True, allow_none=False, encoding=None,\
307db96d56Sopenharmony_ci               bind_and_activate=True, use_builtin_types=False)
317db96d56Sopenharmony_ci
327db96d56Sopenharmony_ci   Create a new server instance.  This class provides methods for registration of
337db96d56Sopenharmony_ci   functions that can be called by the XML-RPC protocol.  The *requestHandler*
347db96d56Sopenharmony_ci   parameter should be a factory for request handler instances; it defaults to
357db96d56Sopenharmony_ci   :class:`SimpleXMLRPCRequestHandler`.  The *addr* and *requestHandler* parameters
367db96d56Sopenharmony_ci   are passed to the :class:`socketserver.TCPServer` constructor.  If *logRequests*
377db96d56Sopenharmony_ci   is true (the default), requests will be logged; setting this parameter to false
387db96d56Sopenharmony_ci   will turn off logging.   The *allow_none* and *encoding* parameters are passed
397db96d56Sopenharmony_ci   on to :mod:`xmlrpc.client` and control the XML-RPC responses that will be returned
407db96d56Sopenharmony_ci   from the server. The *bind_and_activate* parameter controls whether
417db96d56Sopenharmony_ci   :meth:`server_bind` and :meth:`server_activate` are called immediately by the
427db96d56Sopenharmony_ci   constructor; it defaults to true. Setting it to false allows code to manipulate
437db96d56Sopenharmony_ci   the *allow_reuse_address* class variable before the address is bound.
447db96d56Sopenharmony_ci   The *use_builtin_types* parameter is passed to the
457db96d56Sopenharmony_ci   :func:`~xmlrpc.client.loads` function and controls which types are processed
467db96d56Sopenharmony_ci   when date/times values or binary data are received; it defaults to false.
477db96d56Sopenharmony_ci
487db96d56Sopenharmony_ci   .. versionchanged:: 3.3
497db96d56Sopenharmony_ci      The *use_builtin_types* flag was added.
507db96d56Sopenharmony_ci
517db96d56Sopenharmony_ci
527db96d56Sopenharmony_ci.. class:: CGIXMLRPCRequestHandler(allow_none=False, encoding=None,\
537db96d56Sopenharmony_ci               use_builtin_types=False)
547db96d56Sopenharmony_ci
557db96d56Sopenharmony_ci   Create a new instance to handle XML-RPC requests in a CGI environment.  The
567db96d56Sopenharmony_ci   *allow_none* and *encoding* parameters are passed on to :mod:`xmlrpc.client`
577db96d56Sopenharmony_ci   and control the XML-RPC responses that will be returned from the server.
587db96d56Sopenharmony_ci   The *use_builtin_types* parameter is passed to the
597db96d56Sopenharmony_ci   :func:`~xmlrpc.client.loads` function and controls which types are processed
607db96d56Sopenharmony_ci   when date/times values or binary data are received; it defaults to false.
617db96d56Sopenharmony_ci
627db96d56Sopenharmony_ci   .. versionchanged:: 3.3
637db96d56Sopenharmony_ci      The *use_builtin_types* flag was added.
647db96d56Sopenharmony_ci
657db96d56Sopenharmony_ci
667db96d56Sopenharmony_ci.. class:: SimpleXMLRPCRequestHandler()
677db96d56Sopenharmony_ci
687db96d56Sopenharmony_ci   Create a new request handler instance.  This request handler supports ``POST``
697db96d56Sopenharmony_ci   requests and modifies logging so that the *logRequests* parameter to the
707db96d56Sopenharmony_ci   :class:`SimpleXMLRPCServer` constructor parameter is honored.
717db96d56Sopenharmony_ci
727db96d56Sopenharmony_ci
737db96d56Sopenharmony_ci.. _simple-xmlrpc-servers:
747db96d56Sopenharmony_ci
757db96d56Sopenharmony_ciSimpleXMLRPCServer Objects
767db96d56Sopenharmony_ci--------------------------
777db96d56Sopenharmony_ci
787db96d56Sopenharmony_ciThe :class:`SimpleXMLRPCServer` class is based on
797db96d56Sopenharmony_ci:class:`socketserver.TCPServer` and provides a means of creating simple, stand
807db96d56Sopenharmony_cialone XML-RPC servers.
817db96d56Sopenharmony_ci
827db96d56Sopenharmony_ci
837db96d56Sopenharmony_ci.. method:: SimpleXMLRPCServer.register_function(function=None, name=None)
847db96d56Sopenharmony_ci
857db96d56Sopenharmony_ci   Register a function that can respond to XML-RPC requests.  If *name* is given,
867db96d56Sopenharmony_ci   it will be the method name associated with *function*, otherwise
877db96d56Sopenharmony_ci   ``function.__name__`` will be used.  *name* is a string, and may contain
887db96d56Sopenharmony_ci   characters not legal in Python identifiers, including the period character.
897db96d56Sopenharmony_ci
907db96d56Sopenharmony_ci   This method can also be used as a decorator.  When used as a decorator,
917db96d56Sopenharmony_ci   *name* can only be given as a keyword argument to register *function* under
927db96d56Sopenharmony_ci   *name*.  If no *name* is given, ``function.__name__`` will be used.
937db96d56Sopenharmony_ci
947db96d56Sopenharmony_ci   .. versionchanged:: 3.7
957db96d56Sopenharmony_ci      :meth:`register_function` can be used as a decorator.
967db96d56Sopenharmony_ci
977db96d56Sopenharmony_ci
987db96d56Sopenharmony_ci.. method:: SimpleXMLRPCServer.register_instance(instance, allow_dotted_names=False)
997db96d56Sopenharmony_ci
1007db96d56Sopenharmony_ci   Register an object which is used to expose method names which have not been
1017db96d56Sopenharmony_ci   registered using :meth:`register_function`.  If *instance* contains a
1027db96d56Sopenharmony_ci   :meth:`_dispatch` method, it is called with the requested method name and the
1037db96d56Sopenharmony_ci   parameters from the request.  Its API is ``def _dispatch(self, method, params)``
1047db96d56Sopenharmony_ci   (note that *params* does not represent a variable argument list).  If it calls
1057db96d56Sopenharmony_ci   an underlying function to perform its task, that function is called as
1067db96d56Sopenharmony_ci   ``func(*params)``, expanding the parameter list. The return value from
1077db96d56Sopenharmony_ci   :meth:`_dispatch` is returned to the client as the result.  If *instance* does
1087db96d56Sopenharmony_ci   not have a :meth:`_dispatch` method, it is searched for an attribute matching
1097db96d56Sopenharmony_ci   the name of the requested method.
1107db96d56Sopenharmony_ci
1117db96d56Sopenharmony_ci   If the optional *allow_dotted_names* argument is true and the instance does not
1127db96d56Sopenharmony_ci   have a :meth:`_dispatch` method, then if the requested method name contains
1137db96d56Sopenharmony_ci   periods, each component of the method name is searched for individually, with
1147db96d56Sopenharmony_ci   the effect that a simple hierarchical search is performed.  The value found from
1157db96d56Sopenharmony_ci   this search is then called with the parameters from the request, and the return
1167db96d56Sopenharmony_ci   value is passed back to the client.
1177db96d56Sopenharmony_ci
1187db96d56Sopenharmony_ci   .. warning::
1197db96d56Sopenharmony_ci
1207db96d56Sopenharmony_ci      Enabling the *allow_dotted_names* option allows intruders to access your
1217db96d56Sopenharmony_ci      module's global variables and may allow intruders to execute arbitrary code on
1227db96d56Sopenharmony_ci      your machine.  Only use this option on a secure, closed network.
1237db96d56Sopenharmony_ci
1247db96d56Sopenharmony_ci
1257db96d56Sopenharmony_ci.. method:: SimpleXMLRPCServer.register_introspection_functions()
1267db96d56Sopenharmony_ci
1277db96d56Sopenharmony_ci   Registers the XML-RPC introspection functions ``system.listMethods``,
1287db96d56Sopenharmony_ci   ``system.methodHelp`` and ``system.methodSignature``.
1297db96d56Sopenharmony_ci
1307db96d56Sopenharmony_ci
1317db96d56Sopenharmony_ci.. method:: SimpleXMLRPCServer.register_multicall_functions()
1327db96d56Sopenharmony_ci
1337db96d56Sopenharmony_ci   Registers the XML-RPC multicall function system.multicall.
1347db96d56Sopenharmony_ci
1357db96d56Sopenharmony_ci
1367db96d56Sopenharmony_ci.. attribute:: SimpleXMLRPCRequestHandler.rpc_paths
1377db96d56Sopenharmony_ci
1387db96d56Sopenharmony_ci   An attribute value that must be a tuple listing valid path portions of the URL
1397db96d56Sopenharmony_ci   for receiving XML-RPC requests.  Requests posted to other paths will result in a
1407db96d56Sopenharmony_ci   404 "no such page" HTTP error.  If this tuple is empty, all paths will be
1417db96d56Sopenharmony_ci   considered valid. The default value is ``('/', '/RPC2')``.
1427db96d56Sopenharmony_ci
1437db96d56Sopenharmony_ci
1447db96d56Sopenharmony_ci.. _simplexmlrpcserver-example:
1457db96d56Sopenharmony_ci
1467db96d56Sopenharmony_ciSimpleXMLRPCServer Example
1477db96d56Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^
1487db96d56Sopenharmony_ciServer code::
1497db96d56Sopenharmony_ci
1507db96d56Sopenharmony_ci   from xmlrpc.server import SimpleXMLRPCServer
1517db96d56Sopenharmony_ci   from xmlrpc.server import SimpleXMLRPCRequestHandler
1527db96d56Sopenharmony_ci
1537db96d56Sopenharmony_ci   # Restrict to a particular path.
1547db96d56Sopenharmony_ci   class RequestHandler(SimpleXMLRPCRequestHandler):
1557db96d56Sopenharmony_ci       rpc_paths = ('/RPC2',)
1567db96d56Sopenharmony_ci
1577db96d56Sopenharmony_ci   # Create server
1587db96d56Sopenharmony_ci   with SimpleXMLRPCServer(('localhost', 8000),
1597db96d56Sopenharmony_ci                           requestHandler=RequestHandler) as server:
1607db96d56Sopenharmony_ci       server.register_introspection_functions()
1617db96d56Sopenharmony_ci
1627db96d56Sopenharmony_ci       # Register pow() function; this will use the value of
1637db96d56Sopenharmony_ci       # pow.__name__ as the name, which is just 'pow'.
1647db96d56Sopenharmony_ci       server.register_function(pow)
1657db96d56Sopenharmony_ci
1667db96d56Sopenharmony_ci       # Register a function under a different name
1677db96d56Sopenharmony_ci       def adder_function(x, y):
1687db96d56Sopenharmony_ci           return x + y
1697db96d56Sopenharmony_ci       server.register_function(adder_function, 'add')
1707db96d56Sopenharmony_ci
1717db96d56Sopenharmony_ci       # Register an instance; all the methods of the instance are
1727db96d56Sopenharmony_ci       # published as XML-RPC methods (in this case, just 'mul').
1737db96d56Sopenharmony_ci       class MyFuncs:
1747db96d56Sopenharmony_ci           def mul(self, x, y):
1757db96d56Sopenharmony_ci               return x * y
1767db96d56Sopenharmony_ci
1777db96d56Sopenharmony_ci       server.register_instance(MyFuncs())
1787db96d56Sopenharmony_ci
1797db96d56Sopenharmony_ci       # Run the server's main loop
1807db96d56Sopenharmony_ci       server.serve_forever()
1817db96d56Sopenharmony_ci
1827db96d56Sopenharmony_ciThe following client code will call the methods made available by the preceding
1837db96d56Sopenharmony_ciserver::
1847db96d56Sopenharmony_ci
1857db96d56Sopenharmony_ci   import xmlrpc.client
1867db96d56Sopenharmony_ci
1877db96d56Sopenharmony_ci   s = xmlrpc.client.ServerProxy('http://localhost:8000')
1887db96d56Sopenharmony_ci   print(s.pow(2,3))  # Returns 2**3 = 8
1897db96d56Sopenharmony_ci   print(s.add(2,3))  # Returns 5
1907db96d56Sopenharmony_ci   print(s.mul(5,2))  # Returns 5*2 = 10
1917db96d56Sopenharmony_ci
1927db96d56Sopenharmony_ci   # Print list of available methods
1937db96d56Sopenharmony_ci   print(s.system.listMethods())
1947db96d56Sopenharmony_ci
1957db96d56Sopenharmony_ci:meth:`register_function` can also be used as a decorator. The previous server
1967db96d56Sopenharmony_ciexample can register functions in a decorator way::
1977db96d56Sopenharmony_ci
1987db96d56Sopenharmony_ci   from xmlrpc.server import SimpleXMLRPCServer
1997db96d56Sopenharmony_ci   from xmlrpc.server import SimpleXMLRPCRequestHandler
2007db96d56Sopenharmony_ci
2017db96d56Sopenharmony_ci   class RequestHandler(SimpleXMLRPCRequestHandler):
2027db96d56Sopenharmony_ci       rpc_paths = ('/RPC2',)
2037db96d56Sopenharmony_ci
2047db96d56Sopenharmony_ci   with SimpleXMLRPCServer(('localhost', 8000),
2057db96d56Sopenharmony_ci                           requestHandler=RequestHandler) as server:
2067db96d56Sopenharmony_ci       server.register_introspection_functions()
2077db96d56Sopenharmony_ci
2087db96d56Sopenharmony_ci       # Register pow() function; this will use the value of
2097db96d56Sopenharmony_ci       # pow.__name__ as the name, which is just 'pow'.
2107db96d56Sopenharmony_ci       server.register_function(pow)
2117db96d56Sopenharmony_ci
2127db96d56Sopenharmony_ci       # Register a function under a different name, using
2137db96d56Sopenharmony_ci       # register_function as a decorator. *name* can only be given
2147db96d56Sopenharmony_ci       # as a keyword argument.
2157db96d56Sopenharmony_ci       @server.register_function(name='add')
2167db96d56Sopenharmony_ci       def adder_function(x, y):
2177db96d56Sopenharmony_ci           return x + y
2187db96d56Sopenharmony_ci
2197db96d56Sopenharmony_ci       # Register a function under function.__name__.
2207db96d56Sopenharmony_ci       @server.register_function
2217db96d56Sopenharmony_ci       def mul(x, y):
2227db96d56Sopenharmony_ci           return x * y
2237db96d56Sopenharmony_ci
2247db96d56Sopenharmony_ci       server.serve_forever()
2257db96d56Sopenharmony_ci
2267db96d56Sopenharmony_ciThe following example included in the :file:`Lib/xmlrpc/server.py` module shows
2277db96d56Sopenharmony_cia server allowing dotted names and registering a multicall function.
2287db96d56Sopenharmony_ci
2297db96d56Sopenharmony_ci.. warning::
2307db96d56Sopenharmony_ci
2317db96d56Sopenharmony_ci  Enabling the *allow_dotted_names* option allows intruders to access your
2327db96d56Sopenharmony_ci  module's global variables and may allow intruders to execute arbitrary code on
2337db96d56Sopenharmony_ci  your machine.  Only use this example only within a secure, closed network.
2347db96d56Sopenharmony_ci
2357db96d56Sopenharmony_ci::
2367db96d56Sopenharmony_ci
2377db96d56Sopenharmony_ci    import datetime
2387db96d56Sopenharmony_ci
2397db96d56Sopenharmony_ci    class ExampleService:
2407db96d56Sopenharmony_ci        def getData(self):
2417db96d56Sopenharmony_ci            return '42'
2427db96d56Sopenharmony_ci
2437db96d56Sopenharmony_ci        class currentTime:
2447db96d56Sopenharmony_ci            @staticmethod
2457db96d56Sopenharmony_ci            def getCurrentTime():
2467db96d56Sopenharmony_ci                return datetime.datetime.now()
2477db96d56Sopenharmony_ci
2487db96d56Sopenharmony_ci    with SimpleXMLRPCServer(("localhost", 8000)) as server:
2497db96d56Sopenharmony_ci        server.register_function(pow)
2507db96d56Sopenharmony_ci        server.register_function(lambda x,y: x+y, 'add')
2517db96d56Sopenharmony_ci        server.register_instance(ExampleService(), allow_dotted_names=True)
2527db96d56Sopenharmony_ci        server.register_multicall_functions()
2537db96d56Sopenharmony_ci        print('Serving XML-RPC on localhost port 8000')
2547db96d56Sopenharmony_ci        try:
2557db96d56Sopenharmony_ci            server.serve_forever()
2567db96d56Sopenharmony_ci        except KeyboardInterrupt:
2577db96d56Sopenharmony_ci            print("\nKeyboard interrupt received, exiting.")
2587db96d56Sopenharmony_ci            sys.exit(0)
2597db96d56Sopenharmony_ci
2607db96d56Sopenharmony_ciThis ExampleService demo can be invoked from the command line::
2617db96d56Sopenharmony_ci
2627db96d56Sopenharmony_ci    python -m xmlrpc.server
2637db96d56Sopenharmony_ci
2647db96d56Sopenharmony_ci
2657db96d56Sopenharmony_ciThe client that interacts with the above server is included in
2667db96d56Sopenharmony_ci``Lib/xmlrpc/client.py``::
2677db96d56Sopenharmony_ci
2687db96d56Sopenharmony_ci    server = ServerProxy("http://localhost:8000")
2697db96d56Sopenharmony_ci
2707db96d56Sopenharmony_ci    try:
2717db96d56Sopenharmony_ci        print(server.currentTime.getCurrentTime())
2727db96d56Sopenharmony_ci    except Error as v:
2737db96d56Sopenharmony_ci        print("ERROR", v)
2747db96d56Sopenharmony_ci
2757db96d56Sopenharmony_ci    multi = MultiCall(server)
2767db96d56Sopenharmony_ci    multi.getData()
2777db96d56Sopenharmony_ci    multi.pow(2,9)
2787db96d56Sopenharmony_ci    multi.add(1,2)
2797db96d56Sopenharmony_ci    try:
2807db96d56Sopenharmony_ci        for response in multi():
2817db96d56Sopenharmony_ci            print(response)
2827db96d56Sopenharmony_ci    except Error as v:
2837db96d56Sopenharmony_ci        print("ERROR", v)
2847db96d56Sopenharmony_ci
2857db96d56Sopenharmony_ciThis client which interacts with the demo XMLRPC server can be invoked as::
2867db96d56Sopenharmony_ci
2877db96d56Sopenharmony_ci    python -m xmlrpc.client
2887db96d56Sopenharmony_ci
2897db96d56Sopenharmony_ci
2907db96d56Sopenharmony_ciCGIXMLRPCRequestHandler
2917db96d56Sopenharmony_ci-----------------------
2927db96d56Sopenharmony_ci
2937db96d56Sopenharmony_ciThe :class:`CGIXMLRPCRequestHandler` class can be used to handle XML-RPC
2947db96d56Sopenharmony_cirequests sent to Python CGI scripts.
2957db96d56Sopenharmony_ci
2967db96d56Sopenharmony_ci
2977db96d56Sopenharmony_ci.. method:: CGIXMLRPCRequestHandler.register_function(function=None, name=None)
2987db96d56Sopenharmony_ci
2997db96d56Sopenharmony_ci   Register a function that can respond to XML-RPC requests.  If *name* is given,
3007db96d56Sopenharmony_ci   it will be the method name associated with *function*, otherwise
3017db96d56Sopenharmony_ci   ``function.__name__`` will be used.  *name* is a string, and may contain
3027db96d56Sopenharmony_ci   characters not legal in Python identifiers, including the period character.
3037db96d56Sopenharmony_ci
3047db96d56Sopenharmony_ci   This method can also be used as a decorator.  When used as a decorator,
3057db96d56Sopenharmony_ci   *name* can only be given as a keyword argument to register *function* under
3067db96d56Sopenharmony_ci   *name*.  If no *name* is given, ``function.__name__`` will be used.
3077db96d56Sopenharmony_ci
3087db96d56Sopenharmony_ci   .. versionchanged:: 3.7
3097db96d56Sopenharmony_ci      :meth:`register_function` can be used as a decorator.
3107db96d56Sopenharmony_ci
3117db96d56Sopenharmony_ci
3127db96d56Sopenharmony_ci.. method:: CGIXMLRPCRequestHandler.register_instance(instance)
3137db96d56Sopenharmony_ci
3147db96d56Sopenharmony_ci   Register an object which is used to expose method names  which have not been
3157db96d56Sopenharmony_ci   registered using :meth:`register_function`. If  instance contains a
3167db96d56Sopenharmony_ci   :meth:`_dispatch` method, it is called with the  requested method name and the
3177db96d56Sopenharmony_ci   parameters from the  request; the return value is returned to the client as the
3187db96d56Sopenharmony_ci   result. If instance does not have a :meth:`_dispatch` method, it is searched
3197db96d56Sopenharmony_ci   for an attribute matching the name of the requested method; if  the requested
3207db96d56Sopenharmony_ci   method name contains periods, each  component of the method name is searched for
3217db96d56Sopenharmony_ci   individually,  with the effect that a simple hierarchical search is performed.
3227db96d56Sopenharmony_ci   The value found from this search is then called with the  parameters from the
3237db96d56Sopenharmony_ci   request, and the return value is passed  back to the client.
3247db96d56Sopenharmony_ci
3257db96d56Sopenharmony_ci
3267db96d56Sopenharmony_ci.. method:: CGIXMLRPCRequestHandler.register_introspection_functions()
3277db96d56Sopenharmony_ci
3287db96d56Sopenharmony_ci   Register the XML-RPC introspection functions  ``system.listMethods``,
3297db96d56Sopenharmony_ci   ``system.methodHelp`` and  ``system.methodSignature``.
3307db96d56Sopenharmony_ci
3317db96d56Sopenharmony_ci
3327db96d56Sopenharmony_ci.. method:: CGIXMLRPCRequestHandler.register_multicall_functions()
3337db96d56Sopenharmony_ci
3347db96d56Sopenharmony_ci   Register the XML-RPC multicall function ``system.multicall``.
3357db96d56Sopenharmony_ci
3367db96d56Sopenharmony_ci
3377db96d56Sopenharmony_ci.. method:: CGIXMLRPCRequestHandler.handle_request(request_text=None)
3387db96d56Sopenharmony_ci
3397db96d56Sopenharmony_ci   Handle an XML-RPC request. If *request_text* is given, it should be the POST
3407db96d56Sopenharmony_ci   data provided by the HTTP server,  otherwise the contents of stdin will be used.
3417db96d56Sopenharmony_ci
3427db96d56Sopenharmony_ciExample::
3437db96d56Sopenharmony_ci
3447db96d56Sopenharmony_ci   class MyFuncs:
3457db96d56Sopenharmony_ci       def mul(self, x, y):
3467db96d56Sopenharmony_ci           return x * y
3477db96d56Sopenharmony_ci
3487db96d56Sopenharmony_ci
3497db96d56Sopenharmony_ci   handler = CGIXMLRPCRequestHandler()
3507db96d56Sopenharmony_ci   handler.register_function(pow)
3517db96d56Sopenharmony_ci   handler.register_function(lambda x,y: x+y, 'add')
3527db96d56Sopenharmony_ci   handler.register_introspection_functions()
3537db96d56Sopenharmony_ci   handler.register_instance(MyFuncs())
3547db96d56Sopenharmony_ci   handler.handle_request()
3557db96d56Sopenharmony_ci
3567db96d56Sopenharmony_ci
3577db96d56Sopenharmony_ciDocumenting XMLRPC server
3587db96d56Sopenharmony_ci-------------------------
3597db96d56Sopenharmony_ci
3607db96d56Sopenharmony_ciThese classes extend the above classes to serve HTML documentation in response
3617db96d56Sopenharmony_cito HTTP GET requests.  Servers can either be free standing, using
3627db96d56Sopenharmony_ci:class:`DocXMLRPCServer`, or embedded in a CGI environment, using
3637db96d56Sopenharmony_ci:class:`DocCGIXMLRPCRequestHandler`.
3647db96d56Sopenharmony_ci
3657db96d56Sopenharmony_ci
3667db96d56Sopenharmony_ci.. class:: DocXMLRPCServer(addr, requestHandler=DocXMLRPCRequestHandler,\
3677db96d56Sopenharmony_ci               logRequests=True, allow_none=False, encoding=None,\
3687db96d56Sopenharmony_ci               bind_and_activate=True, use_builtin_types=True)
3697db96d56Sopenharmony_ci
3707db96d56Sopenharmony_ci   Create a new server instance. All parameters have the same meaning as for
3717db96d56Sopenharmony_ci   :class:`SimpleXMLRPCServer`; *requestHandler* defaults to
3727db96d56Sopenharmony_ci   :class:`DocXMLRPCRequestHandler`.
3737db96d56Sopenharmony_ci
3747db96d56Sopenharmony_ci   .. versionchanged:: 3.3
3757db96d56Sopenharmony_ci      The *use_builtin_types* flag was added.
3767db96d56Sopenharmony_ci
3777db96d56Sopenharmony_ci
3787db96d56Sopenharmony_ci.. class:: DocCGIXMLRPCRequestHandler()
3797db96d56Sopenharmony_ci
3807db96d56Sopenharmony_ci   Create a new instance to handle XML-RPC requests in a CGI environment.
3817db96d56Sopenharmony_ci
3827db96d56Sopenharmony_ci
3837db96d56Sopenharmony_ci.. class:: DocXMLRPCRequestHandler()
3847db96d56Sopenharmony_ci
3857db96d56Sopenharmony_ci   Create a new request handler instance. This request handler supports XML-RPC
3867db96d56Sopenharmony_ci   POST requests, documentation GET requests, and modifies logging so that the
3877db96d56Sopenharmony_ci   *logRequests* parameter to the :class:`DocXMLRPCServer` constructor parameter is
3887db96d56Sopenharmony_ci   honored.
3897db96d56Sopenharmony_ci
3907db96d56Sopenharmony_ci
3917db96d56Sopenharmony_ci.. _doc-xmlrpc-servers:
3927db96d56Sopenharmony_ci
3937db96d56Sopenharmony_ciDocXMLRPCServer Objects
3947db96d56Sopenharmony_ci-----------------------
3957db96d56Sopenharmony_ci
3967db96d56Sopenharmony_ciThe :class:`DocXMLRPCServer` class is derived from :class:`SimpleXMLRPCServer`
3977db96d56Sopenharmony_ciand provides a means of creating self-documenting, stand alone XML-RPC
3987db96d56Sopenharmony_ciservers. HTTP POST requests are handled as XML-RPC method calls. HTTP GET
3997db96d56Sopenharmony_cirequests are handled by generating pydoc-style HTML documentation. This allows a
4007db96d56Sopenharmony_ciserver to provide its own web-based documentation.
4017db96d56Sopenharmony_ci
4027db96d56Sopenharmony_ci
4037db96d56Sopenharmony_ci.. method:: DocXMLRPCServer.set_server_title(server_title)
4047db96d56Sopenharmony_ci
4057db96d56Sopenharmony_ci   Set the title used in the generated HTML documentation. This title will be used
4067db96d56Sopenharmony_ci   inside the HTML "title" element.
4077db96d56Sopenharmony_ci
4087db96d56Sopenharmony_ci
4097db96d56Sopenharmony_ci.. method:: DocXMLRPCServer.set_server_name(server_name)
4107db96d56Sopenharmony_ci
4117db96d56Sopenharmony_ci   Set the name used in the generated HTML documentation. This name will appear at
4127db96d56Sopenharmony_ci   the top of the generated documentation inside a "h1" element.
4137db96d56Sopenharmony_ci
4147db96d56Sopenharmony_ci
4157db96d56Sopenharmony_ci.. method:: DocXMLRPCServer.set_server_documentation(server_documentation)
4167db96d56Sopenharmony_ci
4177db96d56Sopenharmony_ci   Set the description used in the generated HTML documentation. This description
4187db96d56Sopenharmony_ci   will appear as a paragraph, below the server name, in the documentation.
4197db96d56Sopenharmony_ci
4207db96d56Sopenharmony_ci
4217db96d56Sopenharmony_ciDocCGIXMLRPCRequestHandler
4227db96d56Sopenharmony_ci--------------------------
4237db96d56Sopenharmony_ci
4247db96d56Sopenharmony_ciThe :class:`DocCGIXMLRPCRequestHandler` class is derived from
4257db96d56Sopenharmony_ci:class:`CGIXMLRPCRequestHandler` and provides a means of creating
4267db96d56Sopenharmony_ciself-documenting, XML-RPC CGI scripts. HTTP POST requests are handled as XML-RPC
4277db96d56Sopenharmony_cimethod calls. HTTP GET requests are handled by generating pydoc-style HTML
4287db96d56Sopenharmony_cidocumentation. This allows a server to provide its own web-based documentation.
4297db96d56Sopenharmony_ci
4307db96d56Sopenharmony_ci
4317db96d56Sopenharmony_ci.. method:: DocCGIXMLRPCRequestHandler.set_server_title(server_title)
4327db96d56Sopenharmony_ci
4337db96d56Sopenharmony_ci   Set the title used in the generated HTML documentation. This title will be used
4347db96d56Sopenharmony_ci   inside the HTML "title" element.
4357db96d56Sopenharmony_ci
4367db96d56Sopenharmony_ci
4377db96d56Sopenharmony_ci.. method:: DocCGIXMLRPCRequestHandler.set_server_name(server_name)
4387db96d56Sopenharmony_ci
4397db96d56Sopenharmony_ci   Set the name used in the generated HTML documentation. This name will appear at
4407db96d56Sopenharmony_ci   the top of the generated documentation inside a "h1" element.
4417db96d56Sopenharmony_ci
4427db96d56Sopenharmony_ci
4437db96d56Sopenharmony_ci.. method:: DocCGIXMLRPCRequestHandler.set_server_documentation(server_documentation)
4447db96d56Sopenharmony_ci
4457db96d56Sopenharmony_ci   Set the description used in the generated HTML documentation. This description
4467db96d56Sopenharmony_ci   will appear as a paragraph, below the server name, in the documentation.
447