Back to index

python3.2  3.2.2
Classes | Functions | Variables
xmlrpc.server Namespace Reference

Classes

class  SimpleXMLRPCDispatcher
class  SimpleXMLRPCRequestHandler
class  SimpleXMLRPCServer
class  MultiPathXMLRPCServer
class  CGIXMLRPCRequestHandler
class  ServerHTMLDoc
class  XMLRPCDocGenerator
class  DocXMLRPCRequestHandler
class  DocXMLRPCServer
class  DocCGIXMLRPCRequestHandler

Functions

def resolve_dotted_attribute
def list_public_methods

Variables

 fcntl = None
tuple server = SimpleXMLRPCServer(("localhost", 8000))

Detailed Description

XML-RPC Servers.

This module can be used to create simple XML-RPC servers
by creating a server and either installing functions, a
class instance, or by extending the SimpleXMLRPCServer
class.

It can also be used to handle XML-RPC requests in a CGI
environment using CGIXMLRPCRequestHandler.

The Doc* classes can be used to create XML-RPC servers that
serve pydoc-style documentation in response to HTTP
GET requests. This documentation is dynamically generated
based on the functions and methods registered with the
server.

A list of possible usage patterns follows:

1. Install functions:

server = SimpleXMLRPCServer(("localhost", 8000))
server.register_function(pow)
server.register_function(lambda x,y: x+y, 'add')
server.serve_forever()

2. Install an instance:

class MyFuncs:
    def __init__(self):
# make all of the sys functions available through sys.func_name
import sys
self.sys = sys
    def _listMethods(self):
# implement this method so that system.listMethods
# knows to advertise the sys methods
return list_public_methods(self) + \
        ['sys.' + method for method in list_public_methods(self.sys)]
    def pow(self, x, y): return pow(x, y)
    def add(self, x, y) : return x + y

server = SimpleXMLRPCServer(("localhost", 8000))
server.register_introspection_functions()
server.register_instance(MyFuncs())
server.serve_forever()

3. Install an instance with custom dispatch method:

class Math:
    def _listMethods(self):
# this method must be present for system.listMethods
# to work
return ['add', 'pow']
    def _methodHelp(self, method):
# this method must be present for system.methodHelp
# to work
if method == 'add':
    return "add(2,3) => 5"
elif method == 'pow':
    return "pow(x, y[, z]) => number"
else:
    # By convention, return empty
    # string if no help is available
    return ""
    def _dispatch(self, method, params):
if method == 'pow':
    return pow(*params)
elif method == 'add':
    return params[0] + params[1]
else:
    raise ValueError('bad method')

server = SimpleXMLRPCServer(("localhost", 8000))
server.register_introspection_functions()
server.register_instance(Math())
server.serve_forever()

4. Subclass SimpleXMLRPCServer:

class MathServer(SimpleXMLRPCServer):
    def _dispatch(self, method, params):
try:
    # We are forcing the 'export_' prefix on methods that are
    # callable through XML-RPC to prevent potential security
    # problems
    func = getattr(self, 'export_' + method)
except AttributeError:
    raise Exception('method "%s" is not supported' % method)
else:
    return func(*params)

    def export_add(self, x, y):
return x + y

server = MathServer(("localhost", 8000))
server.serve_forever()

5. CGI script:

server = CGIXMLRPCRequestHandler()
server.register_function(pow)
server.handle_request()

Function Documentation

Returns a list of attribute strings, found in the specified
object, which represent callable attributes

Definition at line 146 of file server.py.

00146 
00147 def list_public_methods(obj):
00148     """Returns a list of attribute strings, found in the specified
00149     object, which represent callable attributes"""
00150 
00151     return [member for member in dir(obj)
00152                 if not member.startswith('_') and
00153                     hasattr(getattr(obj, member), '__call__')]

Here is the call graph for this function:

Here is the caller graph for this function:

def xmlrpc.server.resolve_dotted_attribute (   obj,
  attr,
  allow_dotted_names = True 
)
resolve_dotted_attribute(a, 'b.c.d') => a.b.c.d

Resolves a dotted attribute name to an object.  Raises
an AttributeError if any attribute in the chain starts with a '_'.

If the optional allow_dotted_names argument is false, dots are not
supported and this function operates similar to getattr(obj, attr).

Definition at line 122 of file server.py.

00122 
00123 def resolve_dotted_attribute(obj, attr, allow_dotted_names=True):
00124     """resolve_dotted_attribute(a, 'b.c.d') => a.b.c.d
00125 
00126     Resolves a dotted attribute name to an object.  Raises
00127     an AttributeError if any attribute in the chain starts with a '_'.
00128 
00129     If the optional allow_dotted_names argument is false, dots are not
00130     supported and this function operates similar to getattr(obj, attr).
00131     """
00132 
00133     if allow_dotted_names:
00134         attrs = attr.split('.')
00135     else:
00136         attrs = [attr]
00137 
00138     for i in attrs:
00139         if i.startswith('_'):
00140             raise AttributeError(
00141                 'attempt to access private attribute "%s"' % i
00142                 )
00143         else:
00144             obj = getattr(obj,i)
00145     return obj

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 120 of file server.py.

tuple xmlrpc.server.server = SimpleXMLRPCServer(("localhost", 8000))

Definition at line 960 of file server.py.