[Zope3-checkins] CVS: Zope3/src/zope/app/publication - xmlrpc.py:1.7

Stephan Richter srichter at cosmos.phy.tufts.edu
Mon Aug 4 20:19:38 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/publication
In directory cvs.zope.org:/tmp/cvs-serv1822/src/zope/app/publication

Modified Files:
	xmlrpc.py 
Log Message:
After wanting to fix XML-RPC for over a year, I finally got around to do
it. You can now specify view names, create default views and of course you
do not have access to the object's methods directly anymore.

Added some tests for all of this.

Updated XML-RPC directives. Made them also a bit more consistent with the 
browser ones.

This should make the XML-RPC code ready for the beta.


=== Zope3/src/zope/app/publication/xmlrpc.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/publication/xmlrpc.py:1.6	Wed May 28 11:46:10 2003
+++ Zope3/src/zope/app/publication/xmlrpc.py	Mon Aug  4 19:19:04 2003
@@ -11,33 +11,73 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""
+"""XML-RPC Publication Handler.
+
+This module specifically implements a custom nameTraverse() method.
 
 $Id$
 """
-
-from zope.proxy import removeAllProxies
+from zope.app.context import ContextWrapper
 from zope.app.publication.zopepublication import ZopePublication
-from zope.component import queryView
+from zope.component import queryView, queryDefaultViewName
+from zope.proxy import removeAllProxies
+from zope.publisher.interfaces.xmlrpc import IXMLRPCPresentation
+from zope.security.checker import ProxyFactory
 
 class XMLRPCPublication(ZopePublication):
-    """XML-RPC publication handling.
-
-       There is nothing special here right now.
-    """
+    """XML-RPC publication handling."""
 
     def traverseName(self, request, ob, name):
+        """Traverse the name.
+
+        The method should try the following things in this order:
 
+        1. Check whether ob is a view; if so try to find a public method
+           having the passed name.
+
+        2. If the ob is not a view, then we try to find a view for it. This
+           can be done in two ways:
+
+           (a) Look whether there is a view registered for this name.
+
+           (b) Check whether the default view has a matching method called name.
+
+        3. See whether the object has a subobject of this name. This test is
+           done last, since this is done by ZopePublication, and it knows how
+           to create all the correct error messages. No need for us to do that.
+
+        """
         naked_ob = removeAllProxies(ob)
-        view = queryView(ob, 'methods', request, self)
 
-        if hasattr(ob, name):
-            return getattr(ob, name)
-        if view is not self and hasattr(view, name):
-            return getattr(view, name)
-        else:
-            return super(XMLRPCPublication, self).traverseName(request,
-                                                               ob, name)
+        # Use the real view name
+        view_name = name
+        if view_name.startswith('@@'):
+            view_name = view_name[2:]
+
+        # If ob is a presentation object, then we just get the method
+        if IXMLRPCPresentation.isImplementedBy(naked_ob) and \
+               hasattr(ob, view_name):
+            return ProxyFactory(
+                ContextWrapper(getattr(ob, view_name), ob, name=view_name))
+
+        # Let's check whether name could be a view 
+        view = queryView(ob, view_name, request)
+        if view is not None:
+            return ProxyFactory(ContextWrapper(view, ob, name=view_name))
+
+        # Now let's see whether we have a default view with a matching method
+        # name
+        defaultName = queryDefaultViewName(ob, request)
+
+        if defaultName is not None:
+            view = queryView(ob, defaultName, request, object)
+            if hasattr(view, view_name):
+                return ProxyFactory(ContextWrapper(getattr(view, view_name), ob,
+                                                   name=view_name))
+
+        # See whether we have a subobject
+        return super(XMLRPCPublication, self).traverseName(request, ob, name)
+
 
 # For now, have a factory that returns a singleton
 class XMLRPCPublicationFactory:




More information about the Zope3-Checkins mailing list