blob: 0afa2aaea7f8cf3abaa836c11cfbfb2a0afc48e1 [file] [log] [blame]
Eric S. Raymonde304bb92001-07-12 02:39:45 +00001\section{\module{xmlrpclib} --- XML-RPC client access}
2
3\declaremodule{standard}{xmlrpclib}
4\modulesynopsis{XML-RPC client access.}
5\moduleauthor{Fredrik Lundh}{effbot@telia.com}
6\sectionauthor{Eric S. Raymond}{esr@snark.thyrsus.com}
7
8% Not everyting is documented yet. It might be good to describe
9% Marshaller, Unmarshaller, getparser, dumps, loads, and Transport.
10
11\versionadded{2.2}
12
13XML-RPC is a Remote Procedure Call method that uses XML passed via
14HTTP as a transport. With it, a client can call methods with
15parameters on a remote server (the server is named by a URI) and get back
16structured data. This module supports writing XML-RPC client code; it
17handles all the details of translating between conformable Python
18objects and XML on the wire.
19
20\begin{seealso}
21 \seetitle{http://xmlrpc-c.sourceforge.net/xmlrpc-howto/xmlrpc-howto.html}
22 {XML-RPC HOWTO}{A good description of XML operation and client
23 software in several languages. Contains pretty much
24 everything an XML-RPC client developer needs to know.}
25 \seetitle{http://xmlrpc-c.sourceforge.net/hacks.php}
26 {XML-RPC-Hacks page}{Extensions for various open-source
27 libraries to support instrospection and multicall.}
28\end{seealso}
29
30\begin{classdesc}{Server}{\optional{uri\optional{, transport, encoding, verbose}}}
31A \class{Server} instance is a server proxy that manages communication
32with a remote XML-RPC server. The required first argument is a URI
33(Uniform Resource Indicator), and will normally be the URL of the
34server. The optional second argument is a transport factory instance;
35by default it is an internal \class{SafeTransport} instance for https:
36URLs and an internal HTTP \class{Transport} instance otherwise. The
37optional third argument is an encoding, by default UTF-8. The optional
38fourth argument is a debugging flag.
39
40The returned instance is a proxy object with methods that can be used
41to invoke corresponding RPC calls on the remote server. If the remote
42server supports the introspection API, the proxy can also be used to query
43the remote server for the methods it supports (service discovery) and
44fetch other server-associated metadata.
45
46\class{Server} instance methods take Python basic types and objects as
47arguments and return Python basic types and classes. Types that are
48conformable (e.g. that can be marshalled through XML), include the
49following (and except where noted, they are unmarshalled as the same
50Python type):
51
52\begin{tableii}{l|l}{constant}{Name}{Meaning}
53 \lineii{boolean}{The True and False constants that then module supplies}
54 \lineii{integers}{Pass in directly}
55 \lineii{floating-point numbers}{Pass in directly}
56 \lineii{strings}{Pass in directly}
57 \lineii{arrays}{Any Python sequence type containing conformable
58 elements. Arrays are returned as lists}
59 \lineii{structures}{A Python dictionary. Keys must be strings,
60 values may be any conformable type.}
61 \lineii{dates}{in seconds since the epoch; pass in an instance of the
62 \class{DateTime} wrapper class}
63 \lineii{binary data}{pass in an instance of the \class{Binary} wrapper class}
64\end{tableii}
65
66This is the full set of data types supported by XML-RPC. Method calls
67may also return a special \class{Fault} instance, used to signal XML-RPCserver
68errors, or a \class{ProtocolError} instance used to signal an error in
69the HTTP/HTTPS transport layer.
70
71\end{classdesc}
72
73\subsection{Server Objects \label{server-objects}}
74
75A \class{Server} instance proxy object has a method corresponding to
76each remote procedure call accepted by the XML-RPC server. Calling
77the method performs an RPC, dispatched by both name and argument
78signature (e.g. the same method name can be overloaded with multiple
79argument signatures). The RPC finishes by returning a value, which
80may be either returned data in a conformant type or a \class{Fault} or
81\class{ProtocolError} object indicating an error.
82
83Servers that support the XML introspection API support some common
84methods grouped under the reserved \member{system} member:
85
86\begin{methoddesc}{system.listMethods}{}
87This method returns a list of strings, one for each (non-system)
88method supported by the XML-RPC server.
89\end{methoddesc}
90
91\begin{methoddesc}{system.methodHelp}{name}
92This method takes one parameter, the name of a method implemented by
93the XML-RPC server.It returns an array of possible signatures for this
94method. A signature is an array of types. The first of these types is
95the return type of the method, the rest are parameters.
96
97Because multiple signatures (ie. overloading) is permitted, this method
98returns a list of signatures rather than a singleton.
99
100Signatures themselves are restricted to the top level parameters
101expected by a method. For instance if a method expects one array of
102structs as a parameter, and it returns a string, its signature is
103simply "string, array". If it expects three integers and returns a
104string, its signature is "string, int, int, int".
105
106If no signature is defined for the method, a non-array value is
107returned. In Python this means that the type of the returned
108value will be something other that list.
109\end{methoddesc}
110
111\begin{methoddesc}{system.methodHelp}{name}
112This method takes one parameter, the name of a method implemented by
113the XML-RPC server. It returns a documentation string describing the
114use of that method. If no such string is available, an empty string is
115returned. The documentation string may contain HTML markup.
116\end{methoddesc}
117
118Introspection methods are currently supported by servers written in
119PHP, C and Microsoft .NET. Partial introspection support is included
120in recent updates to UserLand Frontier. Introspection support for
121Perl, Python and Java is available at the XML-RPC Hacks page.
122
123\subsection{Boolean Objects \label{boolean-objects}}
124
125This class may be initialized from any Python value; the instance
126returned depends onlyon its truth value. It supports various Python
127operators through \class{__cmp__}, \class{__repr__}, \class{__int__},
128and \class{__nonzero__} methods, all implemented in the obvious ways.
129
130It also has the following method, supported mainly for internal use by
131the unmarshalling code:
132
133\begin{methoddesc}{encode}{out}
134Write the XML-RPC encoding of this Boolean item to the out stream object.
135\end{methoddesc}
136
137\subsection{DateTime Objects \label{datetime-objects}}
138
139This class may initialized from date in seconds since the epoch, a
140time tuple, or an ISO 8601 time/date string. It has the following
141methods, supported mainly for internal use by the
142marshalling/unmarshalling code:
143
144\begin{methoddesc}{decode}{string}
145Accept a string as the instance's new time value.
146\end{methoddesc}
147
148\begin{methoddesc}{encode}{out}
149Write the XML-RPC encoding of this DateTime item to the out stream object.
150\end{methoddesc}
151
152It also supports certain of Python's built-in operators through
153\method{_cmp__} and \method{__repr__} methods.
154
155\subsection{Binary Objects \label{binary-objects}}
156
157This class may initialized from string data (which may include NULs).
158It has the following methods, supported mainly for internal use by the
159marshalling/unmarshalling code:
160
161\begin{methoddesc}{decode}{string}
162Accept a base64 string and decode it as the instance's new data.
163\end{methoddesc}
164
165\begin{methoddesc}{encode}{out}
166Write the XML-RPC base 64 encoding of this binary item to the out stream object.
167\end{methoddesc}
168
169It also supports certain of Python's built-in operators through a
170\method{_cmp__} method.
171
172\subsection{Fault Objects \label{fault-objects}}
173
174A \class{Fault} object encapsulates the content of an XML-RPC fault tag.
175Fault objects have the following members:
176
177\begin{memberdesc}{faultCode}
178A string indicating the fault type.
179\end{memberdesc}
180
181\begin{memberdesc}{faultString}
182A string containing a diagnostic message associated with the fault.
183\end{memberdesc}
184
185\subsection{ProtocolError Objects \label{protocol-error-objects}}
186
187A \class{ProtocolError} object describes a protocol error in the
188underlying transport layer (such as a 404 `not found' error if the
189server named by the URI does not exist). It has the following
190members:
191
192\begin{memberdesc}{url}
193The URI or URL that triggered te error.
194\end{memberdesc}
195
196\begin{memberdesc}{errcode}
197The error code.
198\end{memberdesc}
199
200\begin{memberdesc}{errmsg}
201The eror message of diagnostic string.
202\end{memberdesc}
203
204\begin{memberdesc}{headers}
205A string containing the headers of the HTTP/HTTPS request that
206triggered the error.
207\end{memberdesc}
208
209\subsection{Convenience Functions}
210
211\begin{funcdesc}{boolean}{value, \optional{truefals=(False, True)}}
212Convert any Python value to one of the XML-RPC boolean constants.
213The optional second argument supplies a conversion table to be indexed
214by the first argument's Python truth value.
215\end{funcdesc}
216
217\begin{funcdesc}{binary}{data}
218Trivially convert any Python string to a \class{Binary} object.
219\end{funcdesc}
220
221\subsection{Example of Client Usage
222
223\begin{verbatim}
224 # simple test program (from the XML-RPC specification)
225
226 # server = Server("http://localhost:8000") # local server
227 server = Server("http://betty.userland.com")
228
229 print server
230
231 try:
232 print server.examples.getStateName(41)
233 except Error, v:
234 print "ERROR", v
235\end{verbatim}
236
237% End