blob: be56c456f8e8416f3728ca222777992ec97ef2cb [file] [log] [blame]
Fred Drakee486e0d2001-09-28 22:02:21 +00001\section{\module{SimpleXMLRPCServer} ---
2 Basic XML-RPC server}
3
4\declaremodule{standard}{SimpleXMLRPCServer}
Fred Drake48704ee2001-11-28 07:32:53 +00005\modulesynopsis{Basic XML-RPC server implementation.}
Fred Drakee486e0d2001-09-28 22:02:21 +00006\moduleauthor{Brian Quinlan}{brianq@activestate.com}
7\sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
8
9
10The \module{SimpleXMLRPCServer} module provides a basic server
11framework for XML-RPC servers written in Python. The server object is
Fred Drake2b05ca32001-09-29 05:01:59 +000012based on the \class{\refmodule{SocketServer}.TCPServer} class,
Fred Drakee486e0d2001-09-28 22:02:21 +000013and the request handler is based on the
Fred Drake2b05ca32001-09-29 05:01:59 +000014\class{\refmodule{BaseHTTPServer}.BaseHTTPRequestHandler} class.
Fred Drakee486e0d2001-09-28 22:02:21 +000015
16
17\begin{classdesc}{SimpleXMLRPCServer}{addr\optional{,
18 requestHandler\optional{, logRequests}}}
19 Create a new server instance. The \var{requestHandler} parameter
20 should be a factory for request handler instances; it defaults to
21 \class{SimpleXMLRPCRequestHandler}. The \var{addr} and
22 \var{requestHandler} parameters are passed to the
23 \class{\refmodule{SocketServer}.TCPServer} constructor. If
24 \var{logRequests} is true (the default), requests will be logged;
25 setting this parameter to false will turn off logging. This class
26 provides methods for registration of functions that can be called by
27 the XML-RPC protocol.
28\end{classdesc}
29
30
31\begin{classdesc}{SimpleXMLRPCRequestHandler}{}
32 Create a new request handler instance. This request handler
33 supports \code{POST} requests and modifies logging so that the
34 \var{logRequests} parameter to the \class{SimpleXMLRPCServer}
35 constructor parameter is honored.
36\end{classdesc}
37
38
39\subsection{SimpleXMLRPCServer Objects \label{simple-xmlrpc-servers}}
40
41The \class{SimpleXMLRPCServer} class provides two methods that an
42application can use to register functions that can be called via the
43XML-RPC protocol via the request handler.
44
45\begin{methoddesc}[SimpleXMLRPCServer]{register_function}{function\optional{,
46 name}}
47 Register a function that can respond to XML-RPC requests. The
48 function must be callable with a single parameter which will be the
49 return value of \function{\refmodule{xmlrpclib}.loads()} when called
50 with the payload of the request. If \var{name} is given, it will be
51 the method name associated with \var{function}, otherwise
52 \code{\var{function}.__name__} will be used. \var{name} can be
53 either a normal or Unicode string, and may contain characters not
54 legal in Python identifiers, including the period character.
55\end{methoddesc}
56
57\begin{methoddesc}[SimpleXMLRPCServer]{register_instance}{instance}
58 Register an object which is used to expose method names which have
59 not been registered using \method{register_function()}. If
60 \var{instance} contains a \method{_dispatch()} method, it is called
61 with the requested method name and the parameters from the request;
62 the return value is returned to the client as the result. If
63 \var{instance} does not have a \method{_dispatch()} method, it is
64 searched for an attribute matching the name of the requested method;
65 if the requested method name contains periods, each component of the
66 method name is searched for individually, with the effect that a
67 simple hierarchical search is performed. The value found from this
68 search is then called with the parameters from the request, and the
69 return value is passed back to the client.
70\end{methoddesc}