Back to index

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

List of all members.

Public Member Functions

def handle_get
def __init__
def handle_xmlrpc
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
def set_server_title
def set_server_name
def set_server_documentation
def generate_html_documentation

Public Attributes

 funcs
 instance
 allow_none
 encoding
 allow_dotted_names
 server_name
 server_documentation
 server_title

Detailed Description

Handler for XML-RPC data and documentation requests passed through
CGI

Definition at line 933 of file server.py.


Constructor & Destructor Documentation

Reimplemented from xmlrpc.server.XMLRPCDocGenerator.

Definition at line 953 of file server.py.

00953 
00954     def __init__(self):
00955         CGIXMLRPCRequestHandler.__init__(self)
00956         XMLRPCDocGenerator.__init__(self)
00957 

Here is the caller graph for this function:


Member Function Documentation

generate_html_documentation() => html documentation for the server

Generates HTML documentation for the server using introspection for
installed functions and instances that do not implement the
_dispatch method. Alternatively, instances can choose to implement
the _get_method_argstring(method_name) method to provide the
argument string used in the documentation and the
_methodHelp(method_name) method to provide the help text used
in the documentation.

Definition at line 838 of file server.py.

00838 
00839     def generate_html_documentation(self):
00840         """generate_html_documentation() => html documentation for the server
00841 
00842         Generates HTML documentation for the server using introspection for
00843         installed functions and instances that do not implement the
00844         _dispatch method. Alternatively, instances can choose to implement
00845         the _get_method_argstring(method_name) method to provide the
00846         argument string used in the documentation and the
00847         _methodHelp(method_name) method to provide the help text used
00848         in the documentation."""
00849 
00850         methods = {}
00851 
00852         for method_name in self.system_listMethods():
00853             if method_name in self.funcs:
00854                 method = self.funcs[method_name]
00855             elif self.instance is not None:
00856                 method_info = [None, None] # argspec, documentation
00857                 if hasattr(self.instance, '_get_method_argstring'):
00858                     method_info[0] = self.instance._get_method_argstring(method_name)
00859                 if hasattr(self.instance, '_methodHelp'):
00860                     method_info[1] = self.instance._methodHelp(method_name)
00861 
00862                 method_info = tuple(method_info)
00863                 if method_info != (None, None):
00864                     method = method_info
00865                 elif not hasattr(self.instance, '_dispatch'):
00866                     try:
00867                         method = resolve_dotted_attribute(
00868                                     self.instance,
00869                                     method_name
00870                                     )
00871                     except AttributeError:
00872                         method = method_info
00873                 else:
00874                     method = method_info
00875             else:
00876                 assert 0, "Could not find method in self.functions and no "\
00877                           "instance installed"
00878 
00879             methods[method_name] = method
00880 
00881         documenter = ServerHTMLDoc()
00882         documentation = documenter.docserver(
00883                                 self.server_name,
00884                                 self.server_documentation,
00885                                 methods
00886                             )
00887 
00888         return documenter.page(self.server_title, documentation)

Here is the call graph for this function:

Here is the caller graph for this function:

Handles the HTTP GET request.

Interpret all HTTP GET requests as requests for server
documentation.

Reimplemented from xmlrpc.server.CGIXMLRPCRequestHandler.

Definition at line 937 of file server.py.

00937 
00938     def handle_get(self):
00939         """Handles the HTTP GET request.
00940 
00941         Interpret all HTTP GET requests as requests for server
00942         documentation.
00943         """
00944 
00945         response = self.generate_html_documentation().encode('utf-8')
00946 
00947         print('Content-Type: text/html')
00948         print('Content-Length: %d' % len(response))
00949         print()
00950         sys.stdout.flush()
00951         sys.stdout.buffer.write(response)
00952         sys.stdout.buffer.flush()

Here is the call graph for this function:

def xmlrpc.server.CGIXMLRPCRequestHandler.handle_request (   self,
  request_text = None 
) [inherited]
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 
) [inherited]
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:

def xmlrpc.server.XMLRPCDocGenerator.set_server_documentation (   self,
  server_documentation 
) [inherited]
Set the documentation string for the entire server.

Definition at line 833 of file server.py.

00833 
00834     def set_server_documentation(self, server_documentation):
00835         """Set the documentation string for the entire server."""
00836 
00837         self.server_documentation = server_documentation

def xmlrpc.server.XMLRPCDocGenerator.set_server_name (   self,
  server_name 
) [inherited]
Set the name of the generated HTML server documentation

Definition at line 828 of file server.py.

00828 
00829     def set_server_name(self, server_name):
00830         """Set the name of the generated HTML server documentation"""
00831 
00832         self.server_name = server_name

def xmlrpc.server.XMLRPCDocGenerator.set_server_title (   self,
  server_title 
) [inherited]
Set the HTML title of the generated server documentation

Definition at line 823 of file server.py.

00823 
00824     def set_server_title(self, server_title):
00825         """Set the HTML title of the generated server documentation"""
00826 
00827         self.server_title = server_title

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.

Definition at line 818 of file server.py.

Definition at line 817 of file server.py.

Definition at line 821 of file server.py.


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