Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="node564.html" /> | |
13 | <link rel="prev" href="module-SimpleXMLRPCServer.html" /> | |
14 | <link rel="parent" href="module-SimpleXMLRPCServer.html" /> | |
15 | <link rel="next" href="node564.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>11.23.1 SimpleXMLRPCServer Objects </title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="11.23 SimpleXMLRPCServer " | |
25 | href="module-SimpleXMLRPCServer.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="11.23 SimpleXMLRPCServer " | |
28 | href="module-SimpleXMLRPCServer.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="11.23.2 CGIXMLRPCRequestHandler" | |
31 | href="node564.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="module-SimpleXMLRPCServer.html">11.23 SimpleXMLRPCServer </A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="module-SimpleXMLRPCServer.html">11.23 SimpleXMLRPCServer </A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="node564.html">11.23.2 CGIXMLRPCRequestHandler</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H2><A NAME="SECTION00132310000000000000000"></A><A NAME="simple-xmlrpc-servers"></A> | |
56 | <BR> | |
57 | 11.23.1 SimpleXMLRPCServer Objects | |
58 | </H2> | |
59 | ||
60 | <P> | |
61 | The <tt class="class">SimpleXMLRPCServer</tt> class is based on | |
62 | <tt class="class">SocketServer.TCPServer</tt> and provides a means of creating | |
63 | simple, stand alone XML-RPC servers. | |
64 | ||
65 | <P> | |
66 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
67 | <td><nobr><b><tt id='l2h-3723' xml:id='l2h-3723' class="method">register_function</tt></b>(</nobr></td> | |
68 | <td><var>function</var><big>[</big><var>, | |
69 | name</var><big>]</big><var></var>)</td></tr></table></dt> | |
70 | <dd> | |
71 | Register a function that can respond to XML-RPC requests. If | |
72 | <var>name</var> is given, it will be the method name associated with | |
73 | <var>function</var>, otherwise <code><var>function</var>.__name__</code> will be | |
74 | used. <var>name</var> can be either a normal or Unicode string, and may | |
75 | contain characters not legal in Python identifiers, including the | |
76 | period character. | |
77 | </dl> | |
78 | ||
79 | <P> | |
80 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
81 | <td><nobr><b><tt id='l2h-3724' xml:id='l2h-3724' class="method">register_instance</tt></b>(</nobr></td> | |
82 | <td><var>instance</var><big>[</big><var>, | |
83 | allow_dotted_names</var><big>]</big><var></var>)</td></tr></table></dt> | |
84 | <dd> | |
85 | Register an object which is used to expose method names which have | |
86 | not been registered using <tt class="method">register_function()</tt>. If | |
87 | <var>instance</var> contains a <tt class="method">_dispatch()</tt> method, it is called | |
88 | with the requested method name and the parameters from the request. Its | |
89 | API is <code>def <tt class="method">_dispatch</tt>(self, method, params)</code> (note that | |
90 | <var>params</var> does not represent a variable argument list). If it calls an | |
91 | underlying function to perform its task, that function is called as | |
92 | <code>func(*params)</code>, expanding the parameter list. | |
93 | The return value from <tt class="method">_dispatch()</tt> is returned to the client as | |
94 | the result. If | |
95 | <var>instance</var> does not have a <tt class="method">_dispatch()</tt> method, it is | |
96 | searched for an attribute matching the name of the requested method. | |
97 | ||
98 | <P> | |
99 | If the optional <var>allow_dotted_names</var> argument is true and the | |
100 | instance does not have a <tt class="method">_dispatch()</tt> method, then | |
101 | if the requested method name contains periods, each component of the | |
102 | method name is searched for individually, with the effect that a | |
103 | simple hierarchical search is performed. The value found from this | |
104 | search is then called with the parameters from the request, and the | |
105 | return value is passed back to the client. | |
106 | ||
107 | <P> | |
108 | <div class="warning"><b class="label">Warning:</b> | |
109 | ||
110 | Enabling the <var>allow_dotted_names</var> option allows intruders to access | |
111 | your module's global variables and may allow intruders to execute | |
112 | arbitrary code on your machine. Only use this option on a secure, | |
113 | closed network. | |
114 | </div> | |
115 | ||
116 | <P> | |
117 | ||
118 | <span class="versionnote">Changed in version 2.3.5, 2.4.1: | |
119 | <var>allow_dotted_names</var> was added to plug a security hole; | |
120 | prior versions are insecure.</span> | |
121 | ||
122 | <P> | |
123 | </dl> | |
124 | ||
125 | <P> | |
126 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
127 | <td><nobr><b><tt id='l2h-3725' xml:id='l2h-3725' class="method">register_introspection_functions</tt></b>(</nobr></td> | |
128 | <td><var></var>)</td></tr></table></dt> | |
129 | <dd> | |
130 | Registers the XML-RPC introspection functions <code>system.listMethods</code>, | |
131 | <code>system.methodHelp</code> and <code>system.methodSignature</code>. | |
132 | ||
133 | <span class="versionnote">New in version 2.3.</span> | |
134 | ||
135 | </dl> | |
136 | ||
137 | <P> | |
138 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
139 | <td><nobr><b><tt id='l2h-3726' xml:id='l2h-3726' class="method">register_multicall_functions</tt></b>(</nobr></td> | |
140 | <td><var></var>)</td></tr></table></dt> | |
141 | <dd> | |
142 | Registers the XML-RPC multicall function system.multicall. | |
143 | </dl> | |
144 | ||
145 | <P> | |
146 | Example: | |
147 | ||
148 | <P> | |
149 | <div class="verbatim"><pre> | |
150 | class MyFuncs: | |
151 | def div(self, x, y) : return x // y | |
152 | ||
153 | ||
154 | server = SimpleXMLRPCServer(("localhost", 8000)) | |
155 | server.register_function(pow) | |
156 | server.register_function(lambda x,y: x+y, 'add') | |
157 | server.register_introspection_functions() | |
158 | server.register_instance(MyFuncs()) | |
159 | server.serve_forever() | |
160 | </pre></div> | |
161 | ||
162 | <P> | |
163 | ||
164 | <DIV CLASS="navigation"> | |
165 | <div class='online-navigation'> | |
166 | <p></p><hr /> | |
167 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
168 | <tr> | |
169 | <td class='online-navigation'><a rel="prev" title="11.23 SimpleXMLRPCServer " | |
170 | href="module-SimpleXMLRPCServer.html"><img src='../icons/previous.png' | |
171 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
172 | <td class='online-navigation'><a rel="parent" title="11.23 SimpleXMLRPCServer " | |
173 | href="module-SimpleXMLRPCServer.html"><img src='../icons/up.png' | |
174 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
175 | <td class='online-navigation'><a rel="next" title="11.23.2 CGIXMLRPCRequestHandler" | |
176 | href="node564.html"><img src='../icons/next.png' | |
177 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
178 | <td align="center" width="100%">Python Library Reference</td> | |
179 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
180 | href="contents.html"><img src='../icons/contents.png' | |
181 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
182 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
183 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
184 | <td class='online-navigation'><a rel="index" title="Index" | |
185 | href="genindex.html"><img src='../icons/index.png' | |
186 | border='0' height='32' alt='Index' width='32' /></A></td> | |
187 | </tr></table> | |
188 | <div class='online-navigation'> | |
189 | <b class="navlabel">Previous:</b> | |
190 | <a class="sectref" rel="prev" href="module-SimpleXMLRPCServer.html">11.23 SimpleXMLRPCServer </A> | |
191 | <b class="navlabel">Up:</b> | |
192 | <a class="sectref" rel="parent" href="module-SimpleXMLRPCServer.html">11.23 SimpleXMLRPCServer </A> | |
193 | <b class="navlabel">Next:</b> | |
194 | <a class="sectref" rel="next" href="node564.html">11.23.2 CGIXMLRPCRequestHandler</A> | |
195 | </div> | |
196 | </div> | |
197 | <hr /> | |
198 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
199 | </DIV> | |
200 | <!--End of Navigation Panel--> | |
201 | <ADDRESS> | |
202 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
203 | </ADDRESS> | |
204 | </BODY> | |
205 | </HTML> |