Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
xmlrpc.server.MultiPathXMLRPCServer Class Reference
Inheritance diagram for xmlrpc.server.MultiPathXMLRPCServer:
Inheritance graph
[legend]
Collaboration diagram for xmlrpc.server.MultiPathXMLRPCServer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def add_dispatcher
def get_dispatcher
def server_bind
def server_activate
def server_close
def fileno
def get_request
def shutdown_request
def close_request
def serve_forever
def shutdown
def handle_request
def handle_timeout
def verify_request
def process_request
def finish_request
def handle_error
def register_instance
def register_function
def register_introspection_functions
def register_multicall_functions
def system_listMethods
def system_methodSignature
def system_methodHelp
def system_multicall

Public Attributes

 dispatchers
 allow_none
 encoding
 logRequests
 socket
 server_address
 RequestHandlerClass
 funcs
 instance
 allow_dotted_names

Static Public Attributes

 allow_reuse_address = True
 address_family = socket.AF_INET
 socket_type = socket.SOCK_STREAM
int request_queue_size = 5
 timeout = None

Private Member Functions

def _marshaled_dispatch

Detailed Description

Multipath XML-RPC Server
This specialization of SimpleXMLRPCServer allows the user to create
multiple Dispatcher instances and assign them to different
HTTP request paths.  This makes it possible to run two or more
'virtual XML-RPC servers' at the same port.
Make sure that the requestHandler accepts the paths in question.

Definition at line 590 of file server.py.


Constructor & Destructor Documentation

def xmlrpc.server.MultiPathXMLRPCServer.__init__ (   self,
  addr,
  requestHandler = SimpleXMLRPCRequestHandler,
  logRequests = True,
  allow_none = False,
  encoding = None,
  bind_and_activate = True 
)

Reimplemented from xmlrpc.server.SimpleXMLRPCServer.

Definition at line 599 of file server.py.

00599 
00600                  logRequests=True, allow_none=False, encoding=None, bind_and_activate=True):
00601 
00602         SimpleXMLRPCServer.__init__(self, addr, requestHandler, logRequests, allow_none,
00603                                     encoding, bind_and_activate)
00604         self.dispatchers = {}
00605         self.allow_none = allow_none
00606         self.encoding = encoding

Here is the caller graph for this function:


Member Function Documentation

def xmlrpc.server.MultiPathXMLRPCServer._marshaled_dispatch (   self,
  data,
  dispatch_method = None,
  path = None 
) [private]
Dispatches an XML-RPC method from marshalled (XML) data.

XML-RPC methods are dispatched from the marshalled (XML) data
using the _dispatch method and the result is returned as
marshalled data. For backwards compatibility, a dispatch
function can be provided as an argument (see comment in
SimpleXMLRPCRequestHandler.do_POST) but overriding the
existing method through subclassing is the preferred means
of changing method dispatch behavior.

Reimplemented from xmlrpc.server.SimpleXMLRPCDispatcher.

Definition at line 614 of file server.py.

00614 
00615     def _marshaled_dispatch(self, data, dispatch_method = None, path = None):
00616         try:
00617             response = self.dispatchers[path]._marshaled_dispatch(
00618                data, dispatch_method, path)
00619         except:
00620             # report low level exception back to server
00621             # (each dispatcher should have handled their own
00622             # exceptions)
00623             exc_type, exc_value = sys.exc_info()[:2]
00624             response = xmlrpclib.dumps(
00625                 xmlrpclib.Fault(1, "%s:%s" % (exc_type, exc_value)),
00626                 encoding=self.encoding, allow_none=self.allow_none)
00627         return response

def xmlrpc.server.MultiPathXMLRPCServer.add_dispatcher (   self,
  path,
  dispatcher 
)

Definition at line 607 of file server.py.

00607 
00608     def add_dispatcher(self, path, dispatcher):
00609         self.dispatchers[path] = dispatcher
00610         return dispatcher

def socketserver.TCPServer.close_request (   self,
  request 
) [inherited]
Called to clean up an individual request.

Reimplemented from socketserver.BaseServer.

Reimplemented in socketserver.UDPServer.

Definition at line 464 of file socketserver.py.

00464 
00465     def close_request(self, request):
00466         """Called to clean up an individual request."""
00467         request.close()
00468 

Here is the caller graph for this function:

def socketserver.TCPServer.fileno (   self) [inherited]
Return socket file number.

Interface required by select().

Definition at line 438 of file socketserver.py.

00438 
00439     def fileno(self):
00440         """Return socket file number.
00441 
00442         Interface required by select().
00443 
00444         """
00445         return self.socket.fileno()

Here is the caller graph for this function:

def socketserver.BaseServer.finish_request (   self,
  request,
  client_address 
) [inherited]
Finish one request by instantiating RequestHandlerClass.

Definition at line 321 of file socketserver.py.

00321 
00322     def finish_request(self, request, client_address):
00323         """Finish one request by instantiating RequestHandlerClass."""
00324         self.RequestHandlerClass(request, client_address, self)

Here is the caller graph for this function:

Definition at line 611 of file server.py.

00611 
00612     def get_dispatcher(self, path):
00613         return self.dispatchers[path]

def socketserver.TCPServer.get_request (   self) [inherited]
Get the request and client address from the socket.

May be overridden.

Reimplemented in socketserver.UDPServer, idlelib.rpc.RPCServer, test.test_imaplib.SecureTCPServer, and test.test_urllib2_localnet.LoopbackHttpServer.

Definition at line 446 of file socketserver.py.

00446 
00447     def get_request(self):
00448         """Get the request and client address from the socket.
00449 
00450         May be overridden.
00451 
00452         """
00453         return self.socket.accept()

Here is the caller graph for this function:

def socketserver.BaseServer.handle_error (   self,
  request,
  client_address 
) [inherited]
Handle an error gracefully.  May be overridden.

The default is to print a traceback and continue.

Reimplemented in idlelib.run.MyRPCServer, and idlelib.rpc.RPCServer.

Definition at line 333 of file socketserver.py.

00333 
00334     def handle_error(self, request, client_address):
00335         """Handle an error gracefully.  May be overridden.
00336 
00337         The default is to print a traceback and continue.
00338 
00339         """
00340         print('-'*40)
00341         print('Exception happened during processing of request from', end=' ')
00342         print(client_address)
00343         import traceback
00344         traceback.print_exc() # XXX But this goes to stderr!
00345         print('-'*40)
00346 

Here is the call graph for this function:

Here is the caller graph for this function:

def socketserver.BaseServer.handle_request (   self) [inherited]
Handle one request, possibly blocking.

Respects self.timeout.

Definition at line 253 of file socketserver.py.

00253 
00254     def handle_request(self):
00255         """Handle one request, possibly blocking.
00256 
00257         Respects self.timeout.
00258         """
00259         # Support people who used socket.settimeout() to escape
00260         # handle_request before self.timeout was available.
00261         timeout = self.socket.gettimeout()
00262         if timeout is None:
00263             timeout = self.timeout
00264         elif self.timeout is not None:
00265             timeout = min(timeout, self.timeout)
00266         fd_sets = select.select([self], [], [], timeout)
00267         if not fd_sets[0]:
00268             self.handle_timeout()
00269             return
00270         self._handle_request_noblock()

Here is the call graph for this function:

Here is the caller graph for this function:

def socketserver.BaseServer.handle_timeout (   self) [inherited]
Called if no new request arrives within self.timeout.

Overridden by ForkingMixIn.

Definition at line 289 of file socketserver.py.

00289 
00290     def handle_timeout(self):
00291         """Called if no new request arrives within self.timeout.
00292 
00293         Overridden by ForkingMixIn.
00294         """
00295         pass

Here is the caller graph for this function:

def socketserver.BaseServer.process_request (   self,
  request,
  client_address 
) [inherited]
Call finish_request.

Overridden by ForkingMixIn and ThreadingMixIn.

Definition at line 304 of file socketserver.py.

00304 
00305     def process_request(self, request, client_address):
00306         """Call finish_request.
00307 
00308         Overridden by ForkingMixIn and ThreadingMixIn.
00309 
00310         """
00311         self.finish_request(request, client_address)
00312         self.shutdown_request(request)

Here is the call graph for this function:

Here is the caller graph for this function:

def xmlrpc.server.SimpleXMLRPCDispatcher.register_function (   self,
  function,
  name = None 
) [inherited]
Registers a function to respond to XML-RPC requests.

The optional name argument can be used to set a Unicode name
for the function.

Definition at line 205 of file server.py.

00205 
00206     def register_function(self, function, name=None):
00207         """Registers a function to respond to XML-RPC requests.
00208 
00209         The optional name argument can be used to set a Unicode name
00210         for the function.
00211         """
00212 
00213         if name is None:
00214             name = function.__name__
00215         self.funcs[name] = function

def xmlrpc.server.SimpleXMLRPCDispatcher.register_instance (   self,
  instance,
  allow_dotted_names = False 
) [inherited]
Registers an instance to respond to XML-RPC requests.

Only one instance can be installed at a time.

If the registered instance has a _dispatch method then that
method will be called with the name of the XML-RPC method and
its parameters as a tuple
e.g. instance._dispatch('add',(2,3))

If the registered instance does not have a _dispatch method
then the instance will be searched to find a matching method
and, if found, will be called. Methods beginning with an '_'
are considered private and will not be called by
SimpleXMLRPCServer.

If a registered function matches a XML-RPC request, then it
will be called instead of the registered instance.

If the optional allow_dotted_names argument is true and the
instance does not have a _dispatch method, method names
containing dots are supported and resolved, as long as none of
the name segments start with an '_'.

    *** SECURITY WARNING: ***

    Enabling the allow_dotted_names options allows intruders
    to access your module's global variables and may allow
    intruders to execute arbitrary code on your machine.  Only
    use this option on a secure, closed network.

Definition at line 169 of file server.py.

00169 
00170     def register_instance(self, instance, allow_dotted_names=False):
00171         """Registers an instance to respond to XML-RPC requests.
00172 
00173         Only one instance can be installed at a time.
00174 
00175         If the registered instance has a _dispatch method then that
00176         method will be called with the name of the XML-RPC method and
00177         its parameters as a tuple
00178         e.g. instance._dispatch('add',(2,3))
00179 
00180         If the registered instance does not have a _dispatch method
00181         then the instance will be searched to find a matching method
00182         and, if found, will be called. Methods beginning with an '_'
00183         are considered private and will not be called by
00184         SimpleXMLRPCServer.
00185 
00186         If a registered function matches a XML-RPC request, then it
00187         will be called instead of the registered instance.
00188 
00189         If the optional allow_dotted_names argument is true and the
00190         instance does not have a _dispatch method, method names
00191         containing dots are supported and resolved, as long as none of
00192         the name segments start with an '_'.
00193 
00194             *** SECURITY WARNING: ***
00195 
00196             Enabling the allow_dotted_names options allows intruders
00197             to access your module's global variables and may allow
00198             intruders to execute arbitrary code on your machine.  Only
00199             use this option on a secure, closed network.
00200 
00201         """
00202 
00203         self.instance = instance
00204         self.allow_dotted_names = allow_dotted_names

Registers the XML-RPC introspection methods in the system
namespace.

see http://xmlrpc.usefulinc.com/doc/reserved.html

Definition at line 216 of file server.py.

00216 
00217     def register_introspection_functions(self):
00218         """Registers the XML-RPC introspection methods in the system
00219         namespace.
00220 
00221         see http://xmlrpc.usefulinc.com/doc/reserved.html
00222         """
00223 
00224         self.funcs.update({'system.listMethods' : self.system_listMethods,
00225                       'system.methodSignature' : self.system_methodSignature,
00226                       'system.methodHelp' : self.system_methodHelp})

Here is the call graph for this function:

Registers the XML-RPC multicall method in the system
namespace.

see http://www.xmlrpc.com/discuss/msgReader$1208

Definition at line 227 of file server.py.

00227 
00228     def register_multicall_functions(self):
00229         """Registers the XML-RPC multicall method in the system
00230         namespace.
00231 
00232         see http://www.xmlrpc.com/discuss/msgReader$1208"""
00233 
00234         self.funcs.update({'system.multicall' : self.system_multicall})

Here is the call graph for this function:

def socketserver.BaseServer.serve_forever (   self,
  poll_interval = 0.5 
) [inherited]
Handle one request at a time until shutdown.

Polls for shutdown every poll_interval seconds. Ignores
self.timeout. If you need to do periodic tasks, do them in
another thread.

Definition at line 211 of file socketserver.py.

00211 
00212     def serve_forever(self, poll_interval=0.5):
00213         """Handle one request at a time until shutdown.
00214 
00215         Polls for shutdown every poll_interval seconds. Ignores
00216         self.timeout. If you need to do periodic tasks, do them in
00217         another thread.
00218         """
00219         self.__is_shut_down.clear()
00220         try:
00221             while not self.__shutdown_request:
00222                 # XXX: Consider using another file descriptor or
00223                 # connecting to the socket to wake this up instead of
00224                 # polling. Polling reduces our responsiveness to a
00225                 # shutdown request and wastes cpu at all other times.
00226                 r, w, e = select.select([self], [], [], poll_interval)
00227                 if self in r:
00228                     self._handle_request_noblock()
00229         finally:
00230             self.__shutdown_request = False
00231             self.__is_shut_down.set()

Here is the call graph for this function:

def socketserver.TCPServer.server_activate (   self) [inherited]
Called by constructor to activate the server.

May be overridden.

Reimplemented from socketserver.BaseServer.

Reimplemented in socketserver.UDPServer, and idlelib.rpc.RPCServer.

Definition at line 422 of file socketserver.py.

00422 
00423     def server_activate(self):
00424         """Called by constructor to activate the server.
00425 
00426         May be overridden.
00427 
00428         """
00429         self.socket.listen(self.request_queue_size)

def socketserver.TCPServer.server_bind (   self) [inherited]
Called by constructor to bind the socket.

May be overridden.

Reimplemented in http.server.HTTPServer, idlelib.rpc.RPCServer, wsgiref.simple_server.WSGIServer, and test.test_wsgiref.MockServer.

Definition at line 411 of file socketserver.py.

00411 
00412     def server_bind(self):
00413         """Called by constructor to bind the socket.
00414 
00415         May be overridden.
00416 
00417         """
00418         if self.allow_reuse_address:
00419             self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
00420         self.socket.bind(self.server_address)
00421         self.server_address = self.socket.getsockname()

Here is the caller graph for this function:

def socketserver.TCPServer.server_close (   self) [inherited]
Called to clean-up the server.

May be overridden.

Reimplemented from socketserver.BaseServer.

Definition at line 430 of file socketserver.py.

00430 
00431     def server_close(self):
00432         """Called to clean-up the server.
00433 
00434         May be overridden.
00435 
00436         """
00437         self.socket.close()

Here is the caller graph for this function:

def socketserver.BaseServer.shutdown (   self) [inherited]
Stops the serve_forever loop.

Blocks until the loop has finished. This must be called while
serve_forever() is running in another thread, or it will
deadlock.

Definition at line 232 of file socketserver.py.

00232 
00233     def shutdown(self):
00234         """Stops the serve_forever loop.
00235 
00236         Blocks until the loop has finished. This must be called while
00237         serve_forever() is running in another thread, or it will
00238         deadlock.
00239         """
00240         self.__shutdown_request = True
00241         self.__is_shut_down.wait()

def socketserver.TCPServer.shutdown_request (   self,
  request 
) [inherited]
Called to shutdown and close an individual request.

Reimplemented from socketserver.BaseServer.

Reimplemented in socketserver.UDPServer.

Definition at line 454 of file socketserver.py.

00454 
00455     def shutdown_request(self, request):
00456         """Called to shutdown and close an individual request."""
00457         try:
00458             #explicitly shutdown.  socket.close() merely releases
00459             #the socket and waits for GC to perform the actual close.
00460             request.shutdown(socket.SHUT_WR)
00461         except socket.error:
00462             pass #some platforms may raise ENOTCONN here
00463         self.close_request(request)

Here is the call graph for this function:

Here is the caller graph for this function:

system.listMethods() => ['add', 'subtract', 'multiple']

Returns a list of the methods supported by the server.

Definition at line 272 of file server.py.

00272 
00273     def system_listMethods(self):
00274         """system.listMethods() => ['add', 'subtract', 'multiple']
00275 
00276         Returns a list of the methods supported by the server."""
00277 
00278         methods = set(self.funcs.keys())
00279         if self.instance is not None:
00280             # Instance can implement _listMethod to return a list of
00281             # methods
00282             if hasattr(self.instance, '_listMethods'):
00283                 methods |= set(self.instance._listMethods())
00284             # if the instance has a _dispatch method then we
00285             # don't have enough information to provide a list
00286             # of methods
00287             elif not hasattr(self.instance, '_dispatch'):
00288                 methods |= set(list_public_methods(self.instance))
00289         return sorted(methods)

Here is the call graph for this function:

Here is the caller graph for this function:

def xmlrpc.server.SimpleXMLRPCDispatcher.system_methodHelp (   self,
  method_name 
) [inherited]
system.methodHelp('add') => "Adds two integers together"

Returns a string containing documentation for the specified method.

Definition at line 303 of file server.py.

00303 
00304     def system_methodHelp(self, method_name):
00305         """system.methodHelp('add') => "Adds two integers together"
00306 
00307         Returns a string containing documentation for the specified method."""
00308 
00309         method = None
00310         if method_name in self.funcs:
00311             method = self.funcs[method_name]
00312         elif self.instance is not None:
00313             # Instance can implement _methodHelp to return help for a method
00314             if hasattr(self.instance, '_methodHelp'):
00315                 return self.instance._methodHelp(method_name)
00316             # if the instance has a _dispatch method then we
00317             # don't have enough information to provide help
00318             elif not hasattr(self.instance, '_dispatch'):
00319                 try:
00320                     method = resolve_dotted_attribute(
00321                                 self.instance,
00322                                 method_name,
00323                                 self.allow_dotted_names
00324                                 )
00325                 except AttributeError:
00326                     pass
00327 
00328         # Note that we aren't checking that the method actually
00329         # be a callable object of some kind
00330         if method is None:
00331             return ""
00332         else:
00333             import pydoc
00334             return pydoc.getdoc(method)

Here is the call graph for this function:

Here is the caller graph for this function:

def xmlrpc.server.SimpleXMLRPCDispatcher.system_methodSignature (   self,
  method_name 
) [inherited]
system.methodSignature('add') => [double, int, int]

Returns a list describing the signature of the method. In the
above example, the add method takes two integers as arguments
and returns a double result.

This server does NOT support system.methodSignature.

Definition at line 290 of file server.py.

00290 
00291     def system_methodSignature(self, method_name):
00292         """system.methodSignature('add') => [double, int, int]
00293 
00294         Returns a list describing the signature of the method. In the
00295         above example, the add method takes two integers as arguments
00296         and returns a double result.
00297 
00298         This server does NOT support system.methodSignature."""
00299 
00300         # See http://xmlrpc.usefulinc.com/doc/sysmethodsig.html
00301 
00302         return 'signatures not supported'

Here is the caller graph for this function:

def xmlrpc.server.SimpleXMLRPCDispatcher.system_multicall (   self,
  call_list 
) [inherited]
system.multicall([{'methodName': 'add', 'params': [2, 2]}, ...]) => \
[[4], ...]

Allows the caller to package multiple XML-RPC calls into a single
request.

See http://www.xmlrpc.com/discuss/msgReader$1208

Definition at line 335 of file server.py.

00335 
00336     def system_multicall(self, call_list):
00337         """system.multicall([{'methodName': 'add', 'params': [2, 2]}, ...]) => \
00338 [[4], ...]
00339 
00340         Allows the caller to package multiple XML-RPC calls into a single
00341         request.
00342 
00343         See http://www.xmlrpc.com/discuss/msgReader$1208
00344         """
00345 
00346         results = []
00347         for call in call_list:
00348             method_name = call['methodName']
00349             params = call['params']
00350 
00351             try:
00352                 # XXX A marshalling error in any response will fail the entire
00353                 # multicall. If someone cares they should fix this.
00354                 results.append([self._dispatch(method_name, params)])
00355             except Fault as fault:
00356                 results.append(
00357                     {'faultCode' : fault.faultCode,
00358                      'faultString' : fault.faultString}
00359                     )
00360             except:
00361                 exc_type, exc_value, exc_tb = sys.exc_info()
00362                 results.append(
00363                     {'faultCode' : 1,
00364                      'faultString' : "%s:%s" % (exc_type, exc_value)}
00365                     )
00366         return results

Here is the call graph for this function:

Here is the caller graph for this function:

def socketserver.BaseServer.verify_request (   self,
  request,
  client_address 
) [inherited]
Verify the request.  May be overridden.

Return True if we should proceed with this request.

Definition at line 296 of file socketserver.py.

00296 
00297     def verify_request(self, request, client_address):
00298         """Verify the request.  May be overridden.
00299 
00300         Return True if we should proceed with this request.
00301 
00302         """
00303         return True

Here is the caller graph for this function:


Member Data Documentation

socketserver.TCPServer.address_family = socket.AF_INET [static, inherited]

Reimplemented in socketserver.UnixDatagramServer, and socketserver.UnixStreamServer.

Definition at line 394 of file socketserver.py.

Definition at line 203 of file server.py.

Reimplemented from xmlrpc.server.SimpleXMLRPCDispatcher.

Definition at line 604 of file server.py.

Reimplemented from socketserver.TCPServer.

Definition at line 567 of file server.py.

Definition at line 603 of file server.py.

Reimplemented from xmlrpc.server.SimpleXMLRPCDispatcher.

Definition at line 605 of file server.py.

Definition at line 164 of file server.py.

Definition at line 165 of file server.py.

Definition at line 577 of file server.py.

Definition at line 398 of file socketserver.py.

Definition at line 199 of file socketserver.py.

Reimplemented from socketserver.BaseServer.

Definition at line 420 of file socketserver.py.

Definition at line 405 of file socketserver.py.

socketserver.TCPServer.socket_type = socket.SOCK_STREAM [static, inherited]

Reimplemented in socketserver.UDPServer.

Definition at line 396 of file socketserver.py.

socketserver.BaseServer.timeout = None [static, inherited]

Reimplemented in test.test_logging.LogRecordSocketReceiver.

Definition at line 194 of file socketserver.py.


The documentation for this class was generated from the following file: