Back to index

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

List of all members.

Public Member Functions

def __init__
def handle_xmlrpc
def handle_get
def handle_request
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

Detailed Description

Simple handler for XML-RPC data passed through CGI.

Definition at line 628 of file server.py.


Constructor & Destructor Documentation

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

Reimplemented from xmlrpc.server.SimpleXMLRPCDispatcher.

Definition at line 631 of file server.py.

00631 
00632     def __init__(self, allow_none=False, encoding=None):
00633         SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding)

Here is the caller graph for this function:


Member Function Documentation

Handle a single HTTP GET request.

Default implementation indicates an error because
XML-RPC uses the POST method.

Reimplemented in xmlrpc.server.DocCGIXMLRPCRequestHandler.

Definition at line 646 of file server.py.

00646 
00647     def handle_get(self):
00648         """Handle a single HTTP GET request.
00649 
00650         Default implementation indicates an error because
00651         XML-RPC uses the POST method.
00652         """
00653 
00654         code = 400
00655         message, explain = BaseHTTPRequestHandler.responses[code]
00656 
00657         response = http.server.DEFAULT_ERROR_MESSAGE % \
00658             {
00659              'code' : code,
00660              'message' : message,
00661              'explain' : explain
00662             }
00663         response = response.encode('utf-8')
00664         print('Status: %d %s' % (code, message))
00665         print('Content-Type: %s' % http.server.DEFAULT_ERROR_CONTENT_TYPE)
00666         print('Content-Length: %d' % len(response))
00667         print()
00668         sys.stdout.flush()
00669         sys.stdout.buffer.write(response)
00670         sys.stdout.buffer.flush()

Here is the caller graph for this function:

def xmlrpc.server.CGIXMLRPCRequestHandler.handle_request (   self,
  request_text = None 
)
Handle a single XML-RPC request passed through a CGI post method.

If no XML data is given then it is read from stdin. The resulting
XML-RPC response is printed to stdout along with the correct HTTP
headers.

Definition at line 671 of file server.py.

00671 
00672     def handle_request(self, request_text=None):
00673         """Handle a single XML-RPC request passed through a CGI post method.
00674 
00675         If no XML data is given then it is read from stdin. The resulting
00676         XML-RPC response is printed to stdout along with the correct HTTP
00677         headers.
00678         """
00679 
00680         if request_text is None and \
00681             os.environ.get('REQUEST_METHOD', None) == 'GET':
00682             self.handle_get()
00683         else:
00684             # POST data is normally available through stdin
00685             try:
00686                 length = int(os.environ.get('CONTENT_LENGTH', None))
00687             except (ValueError, TypeError):
00688                 length = -1
00689             if request_text is None:
00690                 request_text = sys.stdin.read(length)
00691 
00692             self.handle_xmlrpc(request_text)
00693 
00694 
00695 # -----------------------------------------------------------------------------
00696 # Self documenting XML-RPC Server.

Here is the call graph for this function:

def xmlrpc.server.CGIXMLRPCRequestHandler.handle_xmlrpc (   self,
  request_text 
)
Handle a single XML-RPC request

Definition at line 634 of file server.py.

00634 
00635     def handle_xmlrpc(self, request_text):
00636         """Handle a single XML-RPC request"""
00637 
00638         response = self._marshaled_dispatch(request_text)
00639 
00640         print('Content-Type: text/xml')
00641         print('Content-Length: %d' % len(response))
00642         print()
00643         sys.stdout.flush()
00644         sys.stdout.buffer.write(response)
00645         sys.stdout.buffer.flush()

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:

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:


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: