annotate Doc/lib/libsimplexmlrpc.tex @ 39042:c02fa187e0f4 legacy-trunk

Part of SF patch #1484695. This removes dead code. The chksum was already verified in .frombuf() on the lines above. If there was a problem an exception is raised, so there was no way this condition could have been true.
author Neal Norwitz <nnorwitz@gmail.com>
date Mon, 10 Jul 2006 00:23:17 +0000
parents f831e8bc6bd3
children 4274edfdce98
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20165
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1 \section{\module{SimpleXMLRPCServer} ---
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
2 Basic XML-RPC server}
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
3
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
4 \declaremodule{standard}{SimpleXMLRPCServer}
21063
f187496ffaef Add synopsis for the SimpleXMLRPCServer module; used in the chapter-level
Fred Drake <fdrake@acm.org>
parents: 20176
diff changeset
5 \modulesynopsis{Basic XML-RPC server implementation.}
20165
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
6 \moduleauthor{Brian Quinlan}{brianq@activestate.com}
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
7 \sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
8
36271
21e178b93030 added a missing +\versionadded{2.2} tag
Fredrik Lundh <fredrik@pythonware.com>
parents: 35983
diff changeset
9 \versionadded{2.2}
20165
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
10
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
11 The \module{SimpleXMLRPCServer} module provides a basic server
27249
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
12 framework for XML-RPC servers written in Python. Servers can either
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
13 be free standing, using \class{SimpleXMLRPCServer}, or embedded in a
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
14 CGI environment, using \class{CGIXMLRPCRequestHandler}.
20165
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
15
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
16 \begin{classdesc}{SimpleXMLRPCServer}{addr\optional{,
35980
ad0f0385c6f3 [Patch #893642] Add optional allow_none argument to SimpleXMLRPCServer, CGIXMLRPCRequestHandler
Andrew M. Kuchling <amk@amk.ca>
parents: 35354
diff changeset
17 requestHandler\optional{,
35982
03ae0b8eb6cb [Patch #1039083] Add 'encoding' parameter to SimpleXMLRPCServer
Andrew M. Kuchling <amk@amk.ca>
parents: 35980
diff changeset
18 logRequests\optional{allow_none\optional{, encoding}}}}}
27249
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
19
35982
03ae0b8eb6cb [Patch #1039083] Add 'encoding' parameter to SimpleXMLRPCServer
Andrew M. Kuchling <amk@amk.ca>
parents: 35980
diff changeset
20 Create a new server instance. This class
03ae0b8eb6cb [Patch #1039083] Add 'encoding' parameter to SimpleXMLRPCServer
Andrew M. Kuchling <amk@amk.ca>
parents: 35980
diff changeset
21 provides methods for registration of functions that can be called by
03ae0b8eb6cb [Patch #1039083] Add 'encoding' parameter to SimpleXMLRPCServer
Andrew M. Kuchling <amk@amk.ca>
parents: 35980
diff changeset
22 the XML-RPC protocol. The \var{requestHandler} parameter
20165
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
23 should be a factory for request handler instances; it defaults to
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
24 \class{SimpleXMLRPCRequestHandler}. The \var{addr} and
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
25 \var{requestHandler} parameters are passed to the
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
26 \class{\refmodule{SocketServer}.TCPServer} constructor. If
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
27 \var{logRequests} is true (the default), requests will be logged;
35982
03ae0b8eb6cb [Patch #1039083] Add 'encoding' parameter to SimpleXMLRPCServer
Andrew M. Kuchling <amk@amk.ca>
parents: 35980
diff changeset
28 setting this parameter to false will turn off logging.
03ae0b8eb6cb [Patch #1039083] Add 'encoding' parameter to SimpleXMLRPCServer
Andrew M. Kuchling <amk@amk.ca>
parents: 35980
diff changeset
29 The \var{allow_none} and \var{encoding} parameters are passed on to
03ae0b8eb6cb [Patch #1039083] Add 'encoding' parameter to SimpleXMLRPCServer
Andrew M. Kuchling <amk@amk.ca>
parents: 35980
diff changeset
30 \module{xmlrpclib} and control the XML-RPC responses that will be returned
03ae0b8eb6cb [Patch #1039083] Add 'encoding' parameter to SimpleXMLRPCServer
Andrew M. Kuchling <amk@amk.ca>
parents: 35980
diff changeset
31 from the server.
03ae0b8eb6cb [Patch #1039083] Add 'encoding' parameter to SimpleXMLRPCServer
Andrew M. Kuchling <amk@amk.ca>
parents: 35980
diff changeset
32 \versionchanged[The \var{allow_none} and \var{encoding} parameters were added]{2.5}
20165
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
33 \end{classdesc}
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
34
35982
03ae0b8eb6cb [Patch #1039083] Add 'encoding' parameter to SimpleXMLRPCServer
Andrew M. Kuchling <amk@amk.ca>
parents: 35980
diff changeset
35 \begin{classdesc}{CGIXMLRPCRequestHandler}{\optional{allow_none\optional{, encoding}}}
27249
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
36 Create a new instance to handle XML-RPC requests in a CGI
35982
03ae0b8eb6cb [Patch #1039083] Add 'encoding' parameter to SimpleXMLRPCServer
Andrew M. Kuchling <amk@amk.ca>
parents: 35980
diff changeset
37 environment.
03ae0b8eb6cb [Patch #1039083] Add 'encoding' parameter to SimpleXMLRPCServer
Andrew M. Kuchling <amk@amk.ca>
parents: 35980
diff changeset
38 The \var{allow_none} and \var{encoding} parameters are passed on to
03ae0b8eb6cb [Patch #1039083] Add 'encoding' parameter to SimpleXMLRPCServer
Andrew M. Kuchling <amk@amk.ca>
parents: 35980
diff changeset
39 \module{xmlrpclib} and control the XML-RPC responses that will be returned
03ae0b8eb6cb [Patch #1039083] Add 'encoding' parameter to SimpleXMLRPCServer
Andrew M. Kuchling <amk@amk.ca>
parents: 35980
diff changeset
40 from the server.
03ae0b8eb6cb [Patch #1039083] Add 'encoding' parameter to SimpleXMLRPCServer
Andrew M. Kuchling <amk@amk.ca>
parents: 35980
diff changeset
41 \versionadded{2.3}
03ae0b8eb6cb [Patch #1039083] Add 'encoding' parameter to SimpleXMLRPCServer
Andrew M. Kuchling <amk@amk.ca>
parents: 35980
diff changeset
42 \versionchanged[The \var{allow_none} and \var{encoding} parameters were added]{2.5}
27249
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
43 \end{classdesc}
20165
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
44
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
45 \begin{classdesc}{SimpleXMLRPCRequestHandler}{}
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
46 Create a new request handler instance. This request handler
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
47 supports \code{POST} requests and modifies logging so that the
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
48 \var{logRequests} parameter to the \class{SimpleXMLRPCServer}
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
49 constructor parameter is honored.
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
50 \end{classdesc}
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
51
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
52
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
53 \subsection{SimpleXMLRPCServer Objects \label{simple-xmlrpc-servers}}
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
54
27249
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
55 The \class{SimpleXMLRPCServer} class is based on
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
56 \class{SocketServer.TCPServer} and provides a means of creating
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
57 simple, stand alone XML-RPC servers.
20165
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
58
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
59 \begin{methoddesc}[SimpleXMLRPCServer]{register_function}{function\optional{,
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
60 name}}
27249
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
61 Register a function that can respond to XML-RPC requests. If
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
62 \var{name} is given, it will be the method name associated with
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
63 \var{function}, otherwise \code{\var{function}.__name__} will be
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
64 used. \var{name} can be either a normal or Unicode string, and may
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
65 contain characters not legal in Python identifiers, including the
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
66 period character.
20165
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
67 \end{methoddesc}
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
68
34528
1c072615e5b8 Security fix PSF-2005-001 for SimpleXMLRPCServer.py.
Guido van Rossum <guido@python.org>
parents: 34067
diff changeset
69 \begin{methoddesc}[SimpleXMLRPCServer]{register_instance}{instance\optional{,
1c072615e5b8 Security fix PSF-2005-001 for SimpleXMLRPCServer.py.
Guido van Rossum <guido@python.org>
parents: 34067
diff changeset
70 allow_dotted_names}}
20165
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
71 Register an object which is used to expose method names which have
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
72 not been registered using \method{register_function()}. If
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
73 \var{instance} contains a \method{_dispatch()} method, it is called
33395
b14f7ee25d50 Make the api of the _dispatch() method more concrete. I have no idea if
Skip Montanaro <skip@pobox.com>
parents: 27284
diff changeset
74 with the requested method name and the parameters from the request. Its
35354
de2d84e0447e Fix typo (fixes SF bug #1263086).
Walter Dörwald <walter@livinglogic.de>
parents: 34528
diff changeset
75 API is \code{def \method{_dispatch}(self, method, params)} (note that
33395
b14f7ee25d50 Make the api of the _dispatch() method more concrete. I have no idea if
Skip Montanaro <skip@pobox.com>
parents: 27284
diff changeset
76 \var{params} does not represent a variable argument list). If it calls an
b14f7ee25d50 Make the api of the _dispatch() method more concrete. I have no idea if
Skip Montanaro <skip@pobox.com>
parents: 27284
diff changeset
77 underlying function to perform its task, that function is called as
b14f7ee25d50 Make the api of the _dispatch() method more concrete. I have no idea if
Skip Montanaro <skip@pobox.com>
parents: 27284
diff changeset
78 \code{func(*params)}, expanding the parameter list.
b14f7ee25d50 Make the api of the _dispatch() method more concrete. I have no idea if
Skip Montanaro <skip@pobox.com>
parents: 27284
diff changeset
79 The return value from \method{_dispatch()} is returned to the client as
b14f7ee25d50 Make the api of the _dispatch() method more concrete. I have no idea if
Skip Montanaro <skip@pobox.com>
parents: 27284
diff changeset
80 the result. If
20165
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
81 \var{instance} does not have a \method{_dispatch()} method, it is
34528
1c072615e5b8 Security fix PSF-2005-001 for SimpleXMLRPCServer.py.
Guido van Rossum <guido@python.org>
parents: 34067
diff changeset
82 searched for an attribute matching the name of the requested method.
1c072615e5b8 Security fix PSF-2005-001 for SimpleXMLRPCServer.py.
Guido van Rossum <guido@python.org>
parents: 34067
diff changeset
83
1c072615e5b8 Security fix PSF-2005-001 for SimpleXMLRPCServer.py.
Guido van Rossum <guido@python.org>
parents: 34067
diff changeset
84 If the optional \var{allow_dotted_names} argument is true and the
1c072615e5b8 Security fix PSF-2005-001 for SimpleXMLRPCServer.py.
Guido van Rossum <guido@python.org>
parents: 34067
diff changeset
85 instance does not have a \method{_dispatch()} method, then
20165
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
86 if the requested method name contains periods, each component of the
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
87 method name is searched for individually, with the effect that a
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
88 simple hierarchical search is performed. The value found from this
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
89 search is then called with the parameters from the request, and the
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
90 return value is passed back to the client.
34528
1c072615e5b8 Security fix PSF-2005-001 for SimpleXMLRPCServer.py.
Guido van Rossum <guido@python.org>
parents: 34067
diff changeset
91
1c072615e5b8 Security fix PSF-2005-001 for SimpleXMLRPCServer.py.
Guido van Rossum <guido@python.org>
parents: 34067
diff changeset
92 \begin{notice}[warning]
1c072615e5b8 Security fix PSF-2005-001 for SimpleXMLRPCServer.py.
Guido van Rossum <guido@python.org>
parents: 34067
diff changeset
93 Enabling the \var{allow_dotted_names} option allows intruders to access
1c072615e5b8 Security fix PSF-2005-001 for SimpleXMLRPCServer.py.
Guido van Rossum <guido@python.org>
parents: 34067
diff changeset
94 your module's global variables and may allow intruders to execute
1c072615e5b8 Security fix PSF-2005-001 for SimpleXMLRPCServer.py.
Guido van Rossum <guido@python.org>
parents: 34067
diff changeset
95 arbitrary code on your machine. Only use this option on a secure,
1c072615e5b8 Security fix PSF-2005-001 for SimpleXMLRPCServer.py.
Guido van Rossum <guido@python.org>
parents: 34067
diff changeset
96 closed network.
1c072615e5b8 Security fix PSF-2005-001 for SimpleXMLRPCServer.py.
Guido van Rossum <guido@python.org>
parents: 34067
diff changeset
97 \end{notice}
1c072615e5b8 Security fix PSF-2005-001 for SimpleXMLRPCServer.py.
Guido van Rossum <guido@python.org>
parents: 34067
diff changeset
98
1c072615e5b8 Security fix PSF-2005-001 for SimpleXMLRPCServer.py.
Guido van Rossum <guido@python.org>
parents: 34067
diff changeset
99 \versionchanged[\var{allow_dotted_names} was added to plug a security hole;
1c072615e5b8 Security fix PSF-2005-001 for SimpleXMLRPCServer.py.
Guido van Rossum <guido@python.org>
parents: 34067
diff changeset
100 prior versions are insecure]{2.3.5, 2.4.1}
1c072615e5b8 Security fix PSF-2005-001 for SimpleXMLRPCServer.py.
Guido van Rossum <guido@python.org>
parents: 34067
diff changeset
101
20165
db82c0b40dfc Preliminary documentation for the SimpleXMLRPCServer module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
102 \end{methoddesc}
27249
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
103
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
104 \begin{methoddesc}{register_introspection_functions}{}
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
105 Registers the XML-RPC introspection functions \code{system.listMethods},
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
106 \code{system.methodHelp} and \code{system.methodSignature}.
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
107 \versionadded{2.3}
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
108 \end{methoddesc}
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
109
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
110 \begin{methoddesc}{register_multicall_functions}{}
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
111 Registers the XML-RPC multicall function system.multicall.
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
112 \end{methoddesc}
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
113
38526
f831e8bc6bd3 [Bug #1473048]
Andrew M. Kuchling <amk@amk.ca>
parents: 36271
diff changeset
114 \begin{memberdesc}[SimpleXMLRPCServer]{rpc_paths}
f831e8bc6bd3 [Bug #1473048]
Andrew M. Kuchling <amk@amk.ca>
parents: 36271
diff changeset
115 An attribute value that must be a tuple listing valid path portions of
f831e8bc6bd3 [Bug #1473048]
Andrew M. Kuchling <amk@amk.ca>
parents: 36271
diff changeset
116 the URL for receiving XML-RPC requests. Requests posted to other
f831e8bc6bd3 [Bug #1473048]
Andrew M. Kuchling <amk@amk.ca>
parents: 36271
diff changeset
117 paths will result in a 404 ``no such page'' HTTP error. If this
f831e8bc6bd3 [Bug #1473048]
Andrew M. Kuchling <amk@amk.ca>
parents: 36271
diff changeset
118 tuple is empty, all paths will be considered valid.
f831e8bc6bd3 [Bug #1473048]
Andrew M. Kuchling <amk@amk.ca>
parents: 36271
diff changeset
119 The default value is \code{('/', '/RPC2')}.
f831e8bc6bd3 [Bug #1473048]
Andrew M. Kuchling <amk@amk.ca>
parents: 36271
diff changeset
120 \versionadded{2.5}
f831e8bc6bd3 [Bug #1473048]
Andrew M. Kuchling <amk@amk.ca>
parents: 36271
diff changeset
121 \end{memberdesc}
f831e8bc6bd3 [Bug #1473048]
Andrew M. Kuchling <amk@amk.ca>
parents: 36271
diff changeset
122
27249
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
123 Example:
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
124
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
125 \begin{verbatim}
34067
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
126 from SimpleXMLRPCServer import SimpleXMLRPCServer
27249
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
127
34067
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
128 # Create server
27249
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
129 server = SimpleXMLRPCServer(("localhost", 8000))
34067
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
130 server.register_introspection_functions()
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
131
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
132 # Register pow() function; this will use the value of
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
133 # pow.__name__ as the name, which is just 'pow'.
27249
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
134 server.register_function(pow)
34067
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
135
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
136 # Register a function under a different name
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
137 def adder_function(x,y):
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
138 return x + y
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
139 server.register_function(adder_function, 'add')
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
140
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
141 # Register an instance; all the methods of the instance are
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
142 # published as XML-RPC methods (in this case, just 'div').
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
143 class MyFuncs:
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
144 def div(self, x, y):
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
145 return x // y
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
146
27249
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
147 server.register_instance(MyFuncs())
34067
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
148
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
149 # Run the server's main loop
27249
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
150 server.serve_forever()
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
151 \end{verbatim}
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
152
34067
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
153 The following client code will call the methods made available by
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
154 the preceding server:
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
155
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
156 \begin{verbatim}
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
157 import xmlrpclib
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
158
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
159 s = xmlrpclib.Server('http://localhost:8000')
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
160 print s.pow(2,3) # Returns 2**3 = 8
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
161 print s.add(2,3) # Returns 5
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
162 print s.div(5,2) # Returns 5//2 = 2
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
163
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
164 # Print list of available methods
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
165 print s.system.listMethods()
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
166 \end{verbatim}
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
167
8c8022b81f02 Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Andrew M. Kuchling <amk@amk.ca>
parents: 33691
diff changeset
168
27249
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
169 \subsection{CGIXMLRPCRequestHandler}
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
170
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
171 The \class{CGIXMLRPCRequestHandler} class can be used to
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
172 handle XML-RPC requests sent to Python CGI scripts.
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
173
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
174 \begin{methoddesc}{register_function}{function\optional{, name}}
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
175 Register a function that can respond to XML-RPC requests. If
27284
df2754aca717 Fix a couple of markup errors.
Fred Drake <fdrake@acm.org>
parents: 27249
diff changeset
176 \var{name} is given, it will be the method name associated with
27249
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
177 function, otherwise \var{function.__name__} will be used. \var{name}
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
178 can be either a normal or Unicode string, and may contain
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
179 characters not legal in Python identifiers, including the period
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
180 character.
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
181 \end{methoddesc}
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
182
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
183 \begin{methoddesc}{register_instance}{instance}
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
184 Register an object which is used to expose method names
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
185 which have not been registered using \method{register_function()}. If
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
186 instance contains a \method{_dispatch()} method, it is called with the
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
187 requested method name and the parameters from the
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
188 request; the return value is returned to the client as the result.
27284
df2754aca717 Fix a couple of markup errors.
Fred Drake <fdrake@acm.org>
parents: 27249
diff changeset
189 If instance does not have a \method{_dispatch()} method, it is searched
27249
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
190 for an attribute matching the name of the requested method; if
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
191 the requested method name contains periods, each
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
192 component of the method name is searched for individually,
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
193 with the effect that a simple hierarchical search is performed.
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
194 The value found from this search is then called with the
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
195 parameters from the request, and the return value is passed
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
196 back to the client.
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
197 \end{methoddesc}
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
198
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
199 \begin{methoddesc}{register_introspection_functions}{}
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
200 Register the XML-RPC introspection functions
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
201 \code{system.listMethods}, \code{system.methodHelp} and
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
202 \code{system.methodSignature}.
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
203 \end{methoddesc}
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
204
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
205 \begin{methoddesc}{register_multicall_functions}{}
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
206 Register the XML-RPC multicall function \code{system.multicall}.
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
207 \end{methoddesc}
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
208
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
209 \begin{methoddesc}{handle_request}{\optional{request_text = None}}
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
210 Handle a XML-RPC request. If \var{request_text} is given, it
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
211 should be the POST data provided by the HTTP server,
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
212 otherwise the contents of stdin will be used.
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
213 \end{methoddesc}
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
214
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
215 Example:
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
216
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
217 \begin{verbatim}
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
218 class MyFuncs:
35983
e26dc3348909 [Bug #1041501] Fix example
Andrew M. Kuchling <amk@amk.ca>
parents: 35982
diff changeset
219 def div(self, x, y) : return x // y
27249
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
220
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
221
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
222 handler = CGIXMLRPCRequestHandler()
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
223 handler.register_function(pow)
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
224 handler.register_function(lambda x,y: x+y, 'add')
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
225 handler.register_introspection_functions()
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
226 handler.register_instance(MyFuncs())
7c34e5bf2e22 Patch #473586: Implement CGIXMLRPCRequestHandler.
Martin v. Löwis <martin@v.loewis.de>
parents: 21063
diff changeset
227 handler.handle_request()
27284
df2754aca717 Fix a couple of markup errors.
Fred Drake <fdrake@acm.org>
parents: 27249
diff changeset
228 \end{verbatim}