@@ -32,7 +32,7 @@ def _listMethods(self):
3232 ['string.' + method for method in list_public_methods(self.string)]
3333 def pow(self, x, y): return pow(x, y)
3434 def add(self, x, y) : return x + y
35-
35+
3636server = SimpleXMLRPCServer(("localhost", 8000))
3737server.register_introspection_functions()
3838server.register_instance(MyFuncs())
@@ -137,7 +137,7 @@ def remove_duplicates(lst):
137137 Returns a copy of a list without duplicates. Every list
138138 item must be hashable and the order of the items in the
139139 resulting list is not defined.
140- """
140+ """
141141 u = {}
142142 for x in lst :
143143 u [x ] = 1
@@ -151,7 +151,7 @@ class SimpleXMLRPCDispatcher:
151151 and then to dispatch them. There should never be any
152152 reason to instantiate this class directly.
153153 """
154-
154+
155155 def __init__ (self ):
156156 self .funcs = {}
157157 self .instance = None
@@ -195,7 +195,7 @@ def register_introspection_functions(self):
195195
196196 see http://xmlrpc.usefulinc.com/doc/reserved.html
197197 """
198-
198+
199199 self .funcs .update ({'system.listMethods' : self .system_listMethods ,
200200 'system.methodSignature' : self .system_methodSignature ,
201201 'system.methodHelp' : self .system_methodHelp })
@@ -205,28 +205,28 @@ def register_multicall_functions(self):
205205 namespace.
206206
207207 see http://www.xmlrpc.com/discuss/msgReader$1208"""
208-
208+
209209 self .funcs .update ({'system.multicall' : self .system_multicall })
210-
210+
211211 def _marshaled_dispatch (self , data , dispatch_method = None ):
212212 """Dispatches an XML-RPC method from marshalled (XML) data.
213-
213+
214214 XML-RPC methods are dispatched from the marshalled (XML) data
215215 using the _dispatch method and the result is returned as
216216 marshalled data. For backwards compatibility, a dispatch
217- function can be provided as an argument (see comment in
217+ function can be provided as an argument (see comment in
218218 SimpleXMLRPCRequestHandler.do_POST) but overriding the
219219 existing method through subclassing is the prefered means
220220 of changing method dispatch behavior.
221221 """
222-
222+
223223 params , method = xmlrpclib .loads (data )
224224
225225 # generate response
226226 try :
227227 if dispatch_method is not None :
228228 response = dispatch_method (method , params )
229- else :
229+ else :
230230 response = self ._dispatch (method , params )
231231 # wrap response in a singleton tuple
232232 response = (response ,)
@@ -245,7 +245,7 @@ def system_listMethods(self):
245245 """system.listMethods() => ['add', 'subtract', 'multiple']
246246
247247 Returns a list of the methods supported by the server."""
248-
248+
249249 methods = self .funcs .keys ()
250250 if self .instance is not None :
251251 # Instance can implement _listMethod to return a list of
@@ -263,7 +263,7 @@ def system_listMethods(self):
263263 )
264264 methods .sort ()
265265 return methods
266-
266+
267267 def system_methodSignature (self , method_name ):
268268 """system.methodSignature('add') => [double, int, int]
269269
@@ -274,14 +274,14 @@ def system_methodSignature(self, method_name):
274274 This server does NOT support system.methodSignature."""
275275
276276 # See http://xmlrpc.usefulinc.com/doc/sysmethodsig.html
277-
277+
278278 return 'signatures not supported'
279279
280280 def system_methodHelp (self , method_name ):
281281 """system.methodHelp('add') => "Adds two integers together"
282282
283283 Returns a string containing documentation for the specified method."""
284-
284+
285285 method = None
286286 if self .funcs .has_key (method_name ):
287287 method = self .funcs [method_name ]
@@ -314,9 +314,9 @@ def system_multicall(self, call_list):
314314 Allows the caller to package multiple XML-RPC calls into a single
315315 request.
316316
317- See http://www.xmlrpc.com/discuss/msgReader$1208
317+ See http://www.xmlrpc.com/discuss/msgReader$1208
318318 """
319-
319+
320320 results = []
321321 for call in call_list :
322322 method_name = call ['methodName' ]
@@ -337,7 +337,7 @@ def system_multicall(self, call_list):
337337 'faultString' : "%s:%s" % (sys .exc_type , sys .exc_value )}
338338 )
339339 return results
340-
340+
341341 def _dispatch (self , method , params ):
342342 """Dispatches the XML-RPC method.
343343
@@ -382,7 +382,7 @@ def _dispatch(self, method, params):
382382 return func (* params )
383383 else :
384384 raise Exception ('method "%s" is not supported' % method )
385-
385+
386386class SimpleXMLRPCRequestHandler (BaseHTTPServer .BaseHTTPRequestHandler ):
387387 """Simple XML-RPC request handler class.
388388
@@ -396,7 +396,7 @@ def do_POST(self):
396396 Attempts to interpret all HTTP POST requests as XML-RPC calls,
397397 which are forwarded to the server's _dispatch method for handling.
398398 """
399-
399+
400400 try :
401401 # get arguments
402402 data = self .rfile .read (int (self .headers ["content-length" ]))
@@ -423,14 +423,14 @@ def do_POST(self):
423423 # shut down the connection
424424 self .wfile .flush ()
425425 self .connection .shutdown (1 )
426-
426+
427427 def log_request (self , code = '-' , size = '-' ):
428428 """Selectively log an accepted request."""
429429
430430 if self .server .logRequests :
431431 BaseHTTPServer .BaseHTTPRequestHandler .log_request (self , code , size )
432432
433- class SimpleXMLRPCServer (SocketServer .TCPServer ,
433+ class SimpleXMLRPCServer (SocketServer .TCPServer ,
434434 SimpleXMLRPCDispatcher ):
435435 """Simple XML-RPC server.
436436
@@ -444,21 +444,21 @@ class SimpleXMLRPCServer(SocketServer.TCPServer,
444444 def __init__ (self , addr , requestHandler = SimpleXMLRPCRequestHandler ,
445445 logRequests = 1 ):
446446 self .logRequests = logRequests
447-
447+
448448 SimpleXMLRPCDispatcher .__init__ (self )
449449 SocketServer .TCPServer .__init__ (self , addr , requestHandler )
450-
450+
451451class CGIXMLRPCRequestHandler (SimpleXMLRPCDispatcher ):
452452 """Simple handler for XML-RPC data passed through CGI."""
453-
453+
454454 def __init__ (self ):
455455 SimpleXMLRPCDispatcher .__init__ (self )
456456
457457 def handle_xmlrpc (self , request_text ):
458458 """Handle a single XML-RPC request"""
459-
459+
460460 response = self ._marshaled_dispatch (request_text )
461-
461+
462462 print 'Content-Type: text/xml'
463463 print 'Content-Length: %d' % len (response )
464464 print
@@ -474,37 +474,37 @@ def handle_get(self):
474474 code = 400
475475 message , explain = \
476476 BaseHTTPServer .BaseHTTPRequestHandler .responses [code ]
477-
477+
478478 response = BaseHTTPServer .DEFAULT_ERROR_MESSAGE % \
479479 {
480- 'code' : code ,
481- 'message' : message ,
480+ 'code' : code ,
481+ 'message' : message ,
482482 'explain' : explain
483483 }
484484 print 'Status: %d %s' % (code , message )
485485 print 'Content-Type: text/html'
486486 print 'Content-Length: %d' % len (response )
487487 print
488488 print response
489-
489+
490490 def handle_request (self , request_text = None ):
491491 """Handle a single XML-RPC request passed through a CGI post method.
492-
492+
493493 If no XML data is given then it is read from stdin. The resulting
494494 XML-RPC response is printed to stdout along with the correct HTTP
495495 headers.
496496 """
497-
497+
498498 if request_text is None and \
499499 os .environ .get ('REQUEST_METHOD' , None ) == 'GET' :
500500 self .handle_get ()
501501 else :
502502 # POST data is normally available through stdin
503503 if request_text is None :
504- request_text = sys .stdin .read ()
504+ request_text = sys .stdin .read ()
505505
506506 self .handle_xmlrpc (request_text )
507-
507+
508508if __name__ == '__main__' :
509509 server = SimpleXMLRPCServer (("localhost" , 8000 ))
510510 server .register_function (pow )
0 commit comments