SimpleXMLRPCServer
index
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SimpleXMLRPCServer.py
Module Docs

Simple XML-RPC Server.
 
This module can be used to create simple XML-RPC servers
by creating a server and either installing functions, a
class instance, or by extending the SimpleXMLRPCServer
class.
 
It can also be used to handle XML-RPC requests in a CGI
environment using CGIXMLRPCRequestHandler.
 
A list of possible usage patterns follows:
 
1. Install functions:
 
server = SimpleXMLRPCServer(("localhost", 8000))
server.register_function(pow)
server.register_function(lambda x,y: x+y, 'add')
server.serve_forever()
 
2. Install an instance:
 
class MyFuncs:
    def __init__(self):
        # make all of the string functions available through
        # string.func_name
        import string
        self.string = string
    def _listMethods(self):
        # implement this method so that system.listMethods
        # knows to advertise the strings methods
        return list_public_methods(self) + \
                ['string.' + method for method in list_public_methods(self.string)]
    def pow(self, x, y): return pow(x, y)
    def add(self, x, y) : return x + y
 
server = SimpleXMLRPCServer(("localhost", 8000))
server.register_introspection_functions()
server.register_instance(MyFuncs())
server.serve_forever()
 
3. Install an instance with custom dispatch method:
 
class Math:
    def _listMethods(self):
        # this method must be present for system.listMethods
        # to work
        return ['add', 'pow']
    def _methodHelp(self, method):
        # this method must be present for system.methodHelp
        # to work
        if method == 'add':
            return "add(2,3) => 5"
        elif method == 'pow':
            return "pow(x, y[, z]) => number"
        else:
            # By convention, return empty
            # string if no help is available
            return ""
    def _dispatch(self, method, params):
        if method == 'pow':
            return pow(*params)
        elif method == 'add':
            return params[0] + params[1]
        else:
            raise 'bad method'
 
server = SimpleXMLRPCServer(("localhost", 8000))
server.register_introspection_functions()
server.register_instance(Math())
server.serve_forever()
 
4. Subclass SimpleXMLRPCServer:
 
class MathServer(SimpleXMLRPCServer):
    def _dispatch(self, method, params):
        try:
            # We are forcing the 'export_' prefix on methods that are
            # callable through XML-RPC to prevent potential security
            # problems
            func = getattr(self, 'export_' + method)
        except AttributeError:
            raise Exception('method "%s" is not supported' % method)
        else:
            return func(*params)
 
    def export_add(self, x, y):
        return x + y
 
server = MathServer(("localhost", 8000))
server.serve_forever()
 
5. CGI script:
 
server = CGIXMLRPCRequestHandler()
server.register_function(pow)
server.handle_request()

 
Modules
       
BaseHTTPServer
SocketServer
fcntl
os
re
sys
traceback
xmlrpclib

 
Classes
       
BaseHTTPServer.BaseHTTPRequestHandler(SocketServer.StreamRequestHandler)
SimpleXMLRPCRequestHandler
SimpleXMLRPCDispatcher
CGIXMLRPCRequestHandler
SimpleXMLRPCServer(SocketServer.TCPServer, SimpleXMLRPCDispatcher)
MultiPathXMLRPCServer
SocketServer.TCPServer(SocketServer.BaseServer)
SimpleXMLRPCServer(SocketServer.TCPServer, SimpleXMLRPCDispatcher)
MultiPathXMLRPCServer

 
class CGIXMLRPCRequestHandler(SimpleXMLRPCDispatcher)
    Simple handler for XML-RPC data passed through CGI.
 
  Methods defined here:
__init__(self, allow_none=False, encoding=None)
handle_get(self)
Handle a single HTTP GET request.
 
Default implementation indicates an error because
XML-RPC uses the POST method.
handle_request(self, request_text=None)
Handle a single XML-RPC request passed through a CGI post method.
 
If no XML data is given then it is read from stdin. The resulting
XML-RPC response is printed to stdout along with the correct HTTP
headers.
handle_xmlrpc(self, request_text)
Handle a single XML-RPC request

Methods inherited from SimpleXMLRPCDispatcher:
register_function(self, function, name=None)
Registers a function to respond to XML-RPC requests.
 
The optional name argument can be used to set a Unicode name
for the function.
register_instance(self, instance, allow_dotted_names=False)
Registers an instance to respond to XML-RPC requests.
 
Only one instance can be installed at a time.
 
If the registered instance has a _dispatch method then that
method will be called with the name of the XML-RPC method and
its parameters as a tuple
e.g. instance._dispatch('add',(2,3))
 
If the registered instance does not have a _dispatch method
then the instance will be searched to find a matching method
and, if found, will be called. Methods beginning with an '_'
are considered private and will not be called by
SimpleXMLRPCServer.
 
If a registered function matches a XML-RPC request, then it
will be called instead of the registered instance.
 
If the optional allow_dotted_names argument is true and the
instance does not have a _dispatch method, method names
containing dots are supported and resolved, as long as none of
the name segments start with an '_'.
 
    *** SECURITY WARNING: ***
 
    Enabling the allow_dotted_names options allows intruders
    to access your module's global variables and may allow
    intruders to execute arbitrary code on your machine.  Only
    use this option on a secure, closed network.
register_introspection_functions(self)
Registers the XML-RPC introspection methods in the system
namespace.
 
see http://xmlrpc.usefulinc.com/doc/reserved.html
register_multicall_functions(self)
Registers the XML-RPC multicall method in the system
namespace.
 
see http://www.xmlrpc.com/discuss/msgReader$1208
system_listMethods(self)
system.listMethods() => ['add', 'subtract', 'multiple']
 
Returns a list of the methods supported by the server.
system_methodHelp(self, method_name)
system.methodHelp('add') => "Adds two integers together"
 
Returns a string containing documentation for the specified method.
system_methodSignature(self, method_name)
system.methodSignature('add') => [double, int, int]
 
Returns a list describing the signature of the method. In the
above example, the add method takes two integers as arguments
and returns a double result.
 
This server does NOT support system.methodSignature.
system_multicall(self, call_list)
system.multicall([{'methodName': 'add', 'params': [2, 2]}, ...]) => [[4], ...]
 
Allows the caller to package multiple XML-RPC calls into a single
request.
 
See http://www.xmlrpc.com/discuss/msgReader$1208

 
class MultiPathXMLRPCServer(SimpleXMLRPCServer)
    Multipath XML-RPC Server
This specialization of SimpleXMLRPCServer allows the user to create
multiple Dispatcher instances and assign them to different
HTTP request paths.  This makes it possible to run two or more
'virtual XML-RPC servers' at the same port.
Make sure that the requestHandler accepts the paths in question.
 
 
Method resolution order:
MultiPathXMLRPCServer
SimpleXMLRPCServer
SocketServer.TCPServer
SocketServer.BaseServer
SimpleXMLRPCDispatcher

Methods defined here:
__init__(self, addr, requestHandler=<class SimpleXMLRPCServer.SimpleXMLRPCRequestHandler>, logRequests=True, allow_none=False, encoding=None, bind_and_activate=True)
add_dispatcher(self, path, dispatcher)
get_dispatcher(self, path)

Data and other attributes inherited from SimpleXMLRPCServer:
allow_reuse_address = True

Methods inherited from SocketServer.TCPServer:
close_request(self, request)
Called to clean up an individual request.
fileno(self)
Return socket file number.
 
Interface required by select().
get_request(self)
Get the request and client address from the socket.
 
May be overridden.
server_activate(self)
Called by constructor to activate the server.
 
May be overridden.
server_bind(self)
Called by constructor to bind the socket.
 
May be overridden.
server_close(self)
Called to clean-up the server.
 
May be overridden.
shutdown_request(self, request)
Called to shutdown and close an individual request.

Data and other attributes inherited from SocketServer.TCPServer:
address_family = 2
request_queue_size = 5
socket_type = 1

Methods inherited from SocketServer.BaseServer:
finish_request(self, request, client_address)
Finish one request by instantiating RequestHandlerClass.
handle_error(self, request, client_address)
Handle an error gracefully.  May be overridden.
 
The default is to print a traceback and continue.
handle_request(self)
Handle one request, possibly blocking.
 
Respects self.timeout.
handle_timeout(self)
Called if no new request arrives within self.timeout.
 
Overridden by ForkingMixIn.
process_request(self, request, client_address)
Call finish_request.
 
Overridden by ForkingMixIn and ThreadingMixIn.
serve_forever(self, poll_interval=0.5)
Handle one request at a time until shutdown.
 
Polls for shutdown every poll_interval seconds. Ignores
self.timeout. If you need to do periodic tasks, do them in
another thread.
shutdown(self)
Stops the serve_forever loop.
 
Blocks until the loop has finished. This must be called while
serve_forever() is running in another thread, or it will
deadlock.
verify_request(self, request, client_address)
Verify the request.  May be overridden.
 
Return True if we should proceed with this request.

Data and other attributes inherited from SocketServer.BaseServer:
timeout = None

Methods inherited from SimpleXMLRPCDispatcher:
register_function(self, function, name=None)
Registers a function to respond to XML-RPC requests.
 
The optional name argument can be used to set a Unicode name
for the function.
register_instance(self, instance, allow_dotted_names=False)
Registers an instance to respond to XML-RPC requests.
 
Only one instance can be installed at a time.
 
If the registered instance has a _dispatch method then that
method will be called with the name of the XML-RPC method and
its parameters as a tuple
e.g. instance._dispatch('add',(2,3))
 
If the registered instance does not have a _dispatch method
then the instance will be searched to find a matching method
and, if found, will be called. Methods beginning with an '_'
are considered private and will not be called by
SimpleXMLRPCServer.
 
If a registered function matches a XML-RPC request, then it
will be called instead of the registered instance.
 
If the optional allow_dotted_names argument is true and the
instance does not have a _dispatch method, method names
containing dots are supported and resolved, as long as none of
the name segments start with an '_'.
 
    *** SECURITY WARNING: ***
 
    Enabling the allow_dotted_names options allows intruders
    to access your module's global variables and may allow
    intruders to execute arbitrary code on your machine.  Only
    use this option on a secure, closed network.
register_introspection_functions(self)
Registers the XML-RPC introspection methods in the system
namespace.
 
see http://xmlrpc.usefulinc.com/doc/reserved.html
register_multicall_functions(self)
Registers the XML-RPC multicall method in the system
namespace.
 
see http://www.xmlrpc.com/discuss/msgReader$1208
system_listMethods(self)
system.listMethods() => ['add', 'subtract', 'multiple']
 
Returns a list of the methods supported by the server.
system_methodHelp(self, method_name)
system.methodHelp('add') => "Adds two integers together"
 
Returns a string containing documentation for the specified method.
system_methodSignature(self, method_name)
system.methodSignature('add') => [double, int, int]
 
Returns a list describing the signature of the method. In the
above example, the add method takes two integers as arguments
and returns a double result.
 
This server does NOT support system.methodSignature.
system_multicall(self, call_list)
system.multicall([{'methodName': 'add', 'params': [2, 2]}, ...]) => [[4], ...]
 
Allows the caller to package multiple XML-RPC calls into a single
request.
 
See http://www.xmlrpc.com/discuss/msgReader$1208

 
class SimpleXMLRPCDispatcher
    Mix-in class that dispatches XML-RPC requests.
 
This class is used to register XML-RPC method handlers
and then to dispatch them. This class doesn't need to be
instanced directly when used by SimpleXMLRPCServer but it
can be instanced when used by the MultiPathXMLRPCServer.
 
  Methods defined here:
__init__(self, allow_none=False, encoding=None)
register_function(self, function, name=None)
Registers a function to respond to XML-RPC requests.
 
The optional name argument can be used to set a Unicode name
for the function.
register_instance(self, instance, allow_dotted_names=False)
Registers an instance to respond to XML-RPC requests.
 
Only one instance can be installed at a time.
 
If the registered instance has a _dispatch method then that
method will be called with the name of the XML-RPC method and
its parameters as a tuple
e.g. instance._dispatch('add',(2,3))
 
If the registered instance does not have a _dispatch method
then the instance will be searched to find a matching method
and, if found, will be called. Methods beginning with an '_'
are considered private and will not be called by
SimpleXMLRPCServer.
 
If a registered function matches a XML-RPC request, then it
will be called instead of the registered instance.
 
If the optional allow_dotted_names argument is true and the
instance does not have a _dispatch method, method names
containing dots are supported and resolved, as long as none of
the name segments start with an '_'.
 
    *** SECURITY WARNING: ***
 
    Enabling the allow_dotted_names options allows intruders
    to access your module's global variables and may allow
    intruders to execute arbitrary code on your machine.  Only
    use this option on a secure, closed network.
register_introspection_functions(self)
Registers the XML-RPC introspection methods in the system
namespace.
 
see http://xmlrpc.usefulinc.com/doc/reserved.html
register_multicall_functions(self)
Registers the XML-RPC multicall method in the system
namespace.
 
see http://www.xmlrpc.com/discuss/msgReader$1208
system_listMethods(self)
system.listMethods() => ['add', 'subtract', 'multiple']
 
Returns a list of the methods supported by the server.
system_methodHelp(self, method_name)
system.methodHelp('add') => "Adds two integers together"
 
Returns a string containing documentation for the specified method.
system_methodSignature(self, method_name)
system.methodSignature('add') => [double, int, int]
 
Returns a list describing the signature of the method. In the
above example, the add method takes two integers as arguments
and returns a double result.
 
This server does NOT support system.methodSignature.
system_multicall(self, call_list)
system.multicall([{'methodName': 'add', 'params': [2, 2]}, ...]) => [[4], ...]
 
Allows the caller to package multiple XML-RPC calls into a single
request.
 
See http://www.xmlrpc.com/discuss/msgReader$1208

 
class SimpleXMLRPCRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler)
    Simple XML-RPC request handler class.
 
Handles all HTTP POST requests and attempts to decode them as
XML-RPC requests.
 
 
Method resolution order:
SimpleXMLRPCRequestHandler
BaseHTTPServer.BaseHTTPRequestHandler
SocketServer.StreamRequestHandler
SocketServer.BaseRequestHandler

Methods defined here:
accept_encodings(self)
decode_request_content(self, data)
do_POST(self)
Handles the HTTP POST request.
 
Attempts to interpret all HTTP POST requests as XML-RPC calls,
which are forwarded to the server's _dispatch method for handling.
is_rpc_path_valid(self)
log_request(self, code='-', size='-')
Selectively log an accepted request.
report_404(self)

Data and other attributes defined here:
aepattern = <_sre.SRE_Pattern object>
disable_nagle_algorithm = True
encode_threshold = 1400
rpc_paths = ('/', '/RPC2')
wbufsize = -1

Methods inherited from BaseHTTPServer.BaseHTTPRequestHandler:
address_string(self)
Return the client address formatted for logging.
 
This version looks up the full hostname using gethostbyaddr(),
and tries to find a name that contains at least one dot.
date_time_string(self, timestamp=None)
Return the current date and time formatted for a message header.
end_headers(self)
Send the blank line ending the MIME headers.
handle(self)
Handle multiple requests if necessary.
handle_one_request(self)
Handle a single HTTP request.
 
You normally don't need to override this method; see the class
__doc__ string for information on how to handle specific HTTP
commands such as GET and POST.
log_date_time_string(self)
Return the current time formatted for logging.
log_error(self, format, *args)
Log an error.
 
This is called when a request cannot be fulfilled.  By
default it passes the message on to log_message().
 
Arguments are the same as for log_message().
 
XXX This should go to the separate error log.
log_message(self, format, *args)
Log an arbitrary message.
 
This is used by all other logging functions.  Override
it if you have specific logging wishes.
 
The first argument, FORMAT, is a format string for the
message to be logged.  If the format string contains
any % escapes requiring parameters, they should be
specified as subsequent arguments (it's just like
printf!).
 
The client ip address and current date/time are prefixed to every
message.
parse_request(self)
Parse a request (internal).
 
The request should be stored in self.raw_requestline; the results
are in self.command, self.path, self.request_version and
self.headers.
 
Return True for success, False for failure; on failure, an
error is sent back.
send_error(self, code, message=None)
Send and log an error reply.
 
Arguments are the error code, and a detailed message.
The detailed message defaults to the short entry matching the
response code.
 
This sends an error response (so it must be called before any
output has been generated), logs the error, and finally sends
a piece of HTML explaining the error to the user.
send_header(self, keyword, value)
Send a MIME header.
send_response(self, code, message=None)
Send the response header and log the response code.
 
Also send two standard headers with the server software
version and the current date.
version_string(self)
Return the server software version string.

Data and other attributes inherited from BaseHTTPServer.BaseHTTPRequestHandler:
MessageClass = <class mimetools.Message>
default_request_version = 'HTTP/0.9'
error_content_type = 'text/html'
error_message_format = '<head>\n<title>Error response</title>\n</head>\n<bo...ode explanation: %(code)s = %(explain)s.\n</body>\n'
monthname = [None, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
protocol_version = 'HTTP/1.0'
responses = {100: ('Continue', 'Request received, please continue'), 101: ('Switching Protocols', 'Switching to new protocol; obey Upgrade header'), 200: ('OK', 'Request fulfilled, document follows'), 201: ('Created', 'Document created, URL follows'), 202: ('Accepted', 'Request accepted, processing continues off-line'), 203: ('Non-Authoritative Information', 'Request fulfilled from cache'), 204: ('No Content', 'Request fulfilled, nothing follows'), 205: ('Reset Content', 'Clear input form for further input.'), 206: ('Partial Content', 'Partial content follows.'), 300: ('Multiple Choices', 'Object has several resources -- see URI list'), ...}
server_version = 'BaseHTTP/0.3'
sys_version = 'Python/2.7.10'
weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']

Methods inherited from SocketServer.StreamRequestHandler:
finish(self)
setup(self)

Data and other attributes inherited from SocketServer.StreamRequestHandler:
rbufsize = -1
timeout = None

Methods inherited from SocketServer.BaseRequestHandler:
__init__(self, request, client_address, server)

 
class SimpleXMLRPCServer(SocketServer.TCPServer, SimpleXMLRPCDispatcher)
    Simple XML-RPC server.
 
Simple XML-RPC server that allows functions and a single instance
to be installed to handle requests. The default implementation
attempts to dispatch XML-RPC calls to the functions or instance
installed in the server. Override the _dispatch method inhereted
from SimpleXMLRPCDispatcher to change this behavior.
 
 
Method resolution order:
SimpleXMLRPCServer
SocketServer.TCPServer
SocketServer.BaseServer
SimpleXMLRPCDispatcher

Methods defined here:
__init__(self, addr, requestHandler=<class SimpleXMLRPCServer.SimpleXMLRPCRequestHandler>, logRequests=True, allow_none=False, encoding=None, bind_and_activate=True)

Data and other attributes defined here:
allow_reuse_address = True

Methods inherited from SocketServer.TCPServer:
close_request(self, request)
Called to clean up an individual request.
fileno(self)
Return socket file number.
 
Interface required by select().
get_request(self)
Get the request and client address from the socket.
 
May be overridden.
server_activate(self)
Called by constructor to activate the server.
 
May be overridden.
server_bind(self)
Called by constructor to bind the socket.
 
May be overridden.
server_close(self)
Called to clean-up the server.
 
May be overridden.
shutdown_request(self, request)
Called to shutdown and close an individual request.

Data and other attributes inherited from SocketServer.TCPServer:
address_family = 2
request_queue_size = 5
socket_type = 1

Methods inherited from SocketServer.BaseServer:
finish_request(self, request, client_address)
Finish one request by instantiating RequestHandlerClass.
handle_error(self, request, client_address)
Handle an error gracefully.  May be overridden.
 
The default is to print a traceback and continue.
handle_request(self)
Handle one request, possibly blocking.
 
Respects self.timeout.
handle_timeout(self)
Called if no new request arrives within self.timeout.
 
Overridden by ForkingMixIn.
process_request(self, request, client_address)
Call finish_request.
 
Overridden by ForkingMixIn and ThreadingMixIn.
serve_forever(self, poll_interval=0.5)
Handle one request at a time until shutdown.
 
Polls for shutdown every poll_interval seconds. Ignores
self.timeout. If you need to do periodic tasks, do them in
another thread.
shutdown(self)
Stops the serve_forever loop.
 
Blocks until the loop has finished. This must be called while
serve_forever() is running in another thread, or it will
deadlock.
verify_request(self, request, client_address)
Verify the request.  May be overridden.
 
Return True if we should proceed with this request.

Data and other attributes inherited from SocketServer.BaseServer:
timeout = None

Methods inherited from SimpleXMLRPCDispatcher:
register_function(self, function, name=None)
Registers a function to respond to XML-RPC requests.
 
The optional name argument can be used to set a Unicode name
for the function.
register_instance(self, instance, allow_dotted_names=False)
Registers an instance to respond to XML-RPC requests.
 
Only one instance can be installed at a time.
 
If the registered instance has a _dispatch method then that
method will be called with the name of the XML-RPC method and
its parameters as a tuple
e.g. instance._dispatch('add',(2,3))
 
If the registered instance does not have a _dispatch method
then the instance will be searched to find a matching method
and, if found, will be called. Methods beginning with an '_'
are considered private and will not be called by
SimpleXMLRPCServer.
 
If a registered function matches a XML-RPC request, then it
will be called instead of the registered instance.
 
If the optional allow_dotted_names argument is true and the
instance does not have a _dispatch method, method names
containing dots are supported and resolved, as long as none of
the name segments start with an '_'.
 
    *** SECURITY WARNING: ***
 
    Enabling the allow_dotted_names options allows intruders
    to access your module's global variables and may allow
    intruders to execute arbitrary code on your machine.  Only
    use this option on a secure, closed network.
register_introspection_functions(self)
Registers the XML-RPC introspection methods in the system
namespace.
 
see http://xmlrpc.usefulinc.com/doc/reserved.html
register_multicall_functions(self)
Registers the XML-RPC multicall method in the system
namespace.
 
see http://www.xmlrpc.com/discuss/msgReader$1208
system_listMethods(self)
system.listMethods() => ['add', 'subtract', 'multiple']
 
Returns a list of the methods supported by the server.
system_methodHelp(self, method_name)
system.methodHelp('add') => "Adds two integers together"
 
Returns a string containing documentation for the specified method.
system_methodSignature(self, method_name)
system.methodSignature('add') => [double, int, int]
 
Returns a list describing the signature of the method. In the
above example, the add method takes two integers as arguments
and returns a double result.
 
This server does NOT support system.methodSignature.
system_multicall(self, call_list)
system.multicall([{'methodName': 'add', 'params': [2, 2]}, ...]) => [[4], ...]
 
Allows the caller to package multiple XML-RPC calls into a single
request.
 
See http://www.xmlrpc.com/discuss/msgReader$1208

 
Functions
       
list_public_methods(obj)
Returns a list of attribute strings, found in the specified
object, which represent callable attributes
remove_duplicates(lst)
remove_duplicates([2,2,2,1,3,3]) => [3,1,2]
 
Returns a copy of a list without duplicates. Every list
item must be hashable and the order of the items in the
resulting list is not defined.
resolve_dotted_attribute(obj, attr, allow_dotted_names=True)
resolve_dotted_attribute(a, 'b.c.d') => a.b.c.d
 
Resolves a dotted attribute name to an object.  Raises
an AttributeError if any attribute in the chain starts with a '_'.
 
If the optional allow_dotted_names argument is false, dots are not
supported and this function operates similar to getattr(obj, attr).