Index: contrib/xmlrpc.py
===================================================================
--- contrib/xmlrpc.py	(revision 0)
+++ contrib/xmlrpc.py	(revision 0)
@@ -0,0 +1,147 @@
+import xmlrpclib
+
+class SimpleXMLRPCView:
+    """ Simple XMLRPC View.
+
+        Simple XML-RPC server that allows functions and a single instance
+        to be installed to handle requests.
+    """
+        def __init__(self, logRequests=1):
+        self.funcs = {}
+        self.logRequests = logRequests
+        self.instance = None
+
+    def register_instance(self, instance):
+        """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
+            it's 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 SimpleXMLRPCView.
+
+            If a registered function matches a XML-RPC request, then it
+            will be called instead of the registered instance.
+        """
+
+        self.instance = instance
+
+    def 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.
+
+            If an instance is also registered then it will only be called
+            if a matching function is not found.
+        """
+
+        if name is None:
+            name = function.__name__
+        self.funcs[name] = function
+
+    def _dispatch(self, method, params):
+        """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
+            it's 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 SimpleXMLRPCView.
+        """
+
+        def resolve_dotted_attribute(obj, attr):
+            """resolve_dotted_attribute(math, 'cos.__doc__') => math.cos.__doc__
+
+                Resolves a dotted attribute name to an object. Raises
+                an AttributeError if any attribute in the chain starts
+                with a '_'.
+            """
+            for i in attr.split('.'):
+                if i.startswith('_'):
+                    raise AttributeError(
+                        'attempt to access private attribute "%s"' % i
+                        )
+                else:
+                    obj = getattr(obj,i)
+            return obj
+
+        func = None
+        try:
+            # check to see if a matching function has been registered
+            func = self.funcs[method]
+        except KeyError:
+            if self.instance is not None:
+                # check for a _dispatch method
+                if hasattr(self.instance, '_dispatch'):
+                    return apply(
+                        getattr(self.instance,'_dispatch'),
+                        (method, params)
+                        )
+                else:
+                    # call instance method directly
+                    try:
+                        func = resolve_dotted_attribute(
+                            self.instance,
+                            method
+                            )
+                    except AttributeError:
+                        pass
+
+        if func is not None:
+            return apply(func, params)
+        else:
+            raise Exception('method "%s" is not supported' % method)
+
+    def __call__(request):
+        """ SimpleXMLRPCView is callable so it can be installed as a view.
+
+            Django calls it with 'request', which is a HttpRequest            
+        """
+
+        if request.META['REQUEST_METHOD'] != 'POST':
+            return HttpResponseServerError('Non POST methods not allowed.')
+        
+        try:
+            # get arguments
+            data = request.raw_post_data
+            params, method = xmlrpclib.loads(data)
+
+            # generate response
+            try:
+                response = self._dispatch(method, params)
+                # wrap response in a singleton tuple
+                response = (response,)
+            except:
+                # report exception back to server
+                response = xmlrpclib.dumps(
+                    xmlrpclib.Fault(1, "%s:%s" % (sys.exc_type, sys.exc_value))
+                    )
+            else:
+                response = xmlrpclib.dumps(response, methodresponse=1)
+        except:
+            # internal error, report as HTTP server error
+            return HttpResponseServerError('internal error')
+        else:
+            # got a valid XML RPC response
+            return HttpResponse(response, mimetype="text/xml")
+        
+
+
