Back to index

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

List of all members.

Public Member Functions

def __init__
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

 funcs
 instance
 allow_none
 encoding
 allow_dotted_names

Private Member Functions

def _marshaled_dispatch
def _dispatch

Detailed Description

Mix-in class that dispatches XML-RPC requests.

This class is used to register XML-RPC method handlers
and then to dispatch them. This class doesn't need to be
instanced directly when used by SimpleXMLRPCServer but it
can be instanced when used by the MultiPathXMLRPCServer

Definition at line 154 of file server.py.


Constructor & Destructor Documentation

def xmlrpc.server.SimpleXMLRPCDispatcher.__init__ (   self,
  allow_none = False,
  encoding = None 
)

Reimplemented in xmlrpc.server.CGIXMLRPCRequestHandler.

Definition at line 163 of file server.py.

00163 
00164     def __init__(self, allow_none=False, encoding=None):
00165         self.funcs = {}
00166         self.instance = None
00167         self.allow_none = allow_none
00168         self.encoding = encoding or 'utf-8'

Here is the caller graph for this function:


Member Function Documentation

def xmlrpc.server.SimpleXMLRPCDispatcher._dispatch (   self,
  method,
  params 
) [private]
Dispatches the XML-RPC method.

XML-RPC calls are forwarded to a registered function that
matches the called XML-RPC method name. If no such function
exists then the call is forwarded to the registered instance,
if available.

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.

Definition at line 367 of file server.py.

00367 
00368     def _dispatch(self, method, params):
00369         """Dispatches the XML-RPC method.
00370 
00371         XML-RPC calls are forwarded to a registered function that
00372         matches the called XML-RPC method name. If no such function
00373         exists then the call is forwarded to the registered instance,
00374         if available.
00375 
00376         If the registered instance has a _dispatch method then that
00377         method will be called with the name of the XML-RPC method and
00378         its parameters as a tuple
00379         e.g. instance._dispatch('add',(2,3))
00380 
00381         If the registered instance does not have a _dispatch method
00382         then the instance will be searched to find a matching method
00383         and, if found, will be called.
00384 
00385         Methods beginning with an '_' are considered private and will
00386         not be called.
00387         """
00388 
00389         func = None
00390         try:
00391             # check to see if a matching function has been registered
00392             func = self.funcs[method]
00393         except KeyError:
00394             if self.instance is not None:
00395                 # check for a _dispatch method
00396                 if hasattr(self.instance, '_dispatch'):
00397                     return self.instance._dispatch(method, params)
00398                 else:
00399                     # call instance method directly
00400                     try:
00401                         func = resolve_dotted_attribute(
00402                             self.instance,
00403                             method,
00404                             self.allow_dotted_names
00405                             )
00406                     except AttributeError:
00407                         pass
00408 
00409         if func is not None:
00410             return func(*params)
00411         else:
00412             raise Exception('method "%s" is not supported' % method)

Here is the call graph for this function:

Here is the caller graph for this function:

def xmlrpc.server.SimpleXMLRPCDispatcher._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 in xmlrpc.server.MultiPathXMLRPCServer.

Definition at line 235 of file server.py.

00235 
00236     def _marshaled_dispatch(self, data, dispatch_method = None, path = None):
00237         """Dispatches an XML-RPC method from marshalled (XML) data.
00238 
00239         XML-RPC methods are dispatched from the marshalled (XML) data
00240         using the _dispatch method and the result is returned as
00241         marshalled data. For backwards compatibility, a dispatch
00242         function can be provided as an argument (see comment in
00243         SimpleXMLRPCRequestHandler.do_POST) but overriding the
00244         existing method through subclassing is the preferred means
00245         of changing method dispatch behavior.
00246         """
00247 
00248         try:
00249             params, method = loads(data)
00250 
00251             # generate response
00252             if dispatch_method is not None:
00253                 response = dispatch_method(method, params)
00254             else:
00255                 response = self._dispatch(method, params)
00256             # wrap response in a singleton tuple
00257             response = (response,)
00258             response = dumps(response, methodresponse=1,
00259                              allow_none=self.allow_none, encoding=self.encoding)
00260         except Fault as fault:
00261             response = dumps(fault, allow_none=self.allow_none,
00262                              encoding=self.encoding)
00263         except:
00264             # report exception back to server
00265             exc_type, exc_value, exc_tb = sys.exc_info()
00266             response = dumps(
00267                 Fault(1, "%s:%s" % (exc_type, exc_value)),
00268                 encoding=self.encoding, allow_none=self.allow_none,
00269                 )
00270 
00271         return response.encode(self.encoding)

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 
)
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 
)
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:

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 
)
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:

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:

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:


Member Data Documentation

Definition at line 203 of file server.py.

Reimplemented in xmlrpc.server.MultiPathXMLRPCServer.

Definition at line 166 of file server.py.

Reimplemented in xmlrpc.server.MultiPathXMLRPCServer.

Definition at line 167 of file server.py.

Definition at line 164 of file server.py.

Definition at line 165 of file server.py.


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