[Zope3-checkins] SVN: Zope3/branches/jim-default-traversal/src/zope/app/ Make SimpleComponentTraverser the default traverser for

Jim Fulton jim at zope.com
Tue Aug 10 15:55:53 EDT 2004


Log message for revision 26976:
  Make SimpleComponentTraverser the default traverser for
  all objects, not just those that implement something.  This was an
  attempt to fix a collector item, but it turned out to have nothing to
  do with it.  This is a big enough change that I don't want to
  introduce it until X3.0 final is out.
  We'll stick this off on this branch for now.
  
  


Changed:
  U   Zope3/branches/jim-default-traversal/src/zope/app/pagetemplate/configure.zcml
  U   Zope3/branches/jim-default-traversal/src/zope/app/publication/traversers.py
  U   Zope3/branches/jim-default-traversal/src/zope/app/traversing/browser/configure.zcml
  U   Zope3/branches/jim-default-traversal/src/zope/app/xmlrpc/configure.zcml


-=-
Modified: Zope3/branches/jim-default-traversal/src/zope/app/pagetemplate/configure.zcml
===================================================================
--- Zope3/branches/jim-default-traversal/src/zope/app/pagetemplate/configure.zcml	2004-08-10 19:49:07 UTC (rev 26975)
+++ Zope3/branches/jim-default-traversal/src/zope/app/pagetemplate/configure.zcml	2004-08-10 19:55:52 UTC (rev 26976)
@@ -24,8 +24,20 @@
       factory=".urlquote.URLQuote"
       name="url"/> 
 
- <content class="zope.tales.tales.Iterator">
+  <content class="zope.tales.tales.Iterator">
     <allow interface="zope.tales.interfaces.ITALESIterator" />
- </content>
+  </content>
 
+  <view
+      for=".viewpagetemplatefile.BoundPageTemplate"
+      type="zope.publisher.interfaces.browser.IBrowserRequest"
+      provides="zope.publisher.interfaces.browser.IBrowserPublisher"
+      factory="zope.app.publication.traversers.MethodTraverser"
+      permission="zope.Public"
+      >
+      Provide a traverser adapter for BoundPageTemplate objects that 
+      marks them as having no default page.  This is necessary to
+      actually publish them.
+  </view>
+
 </configure>

Modified: Zope3/branches/jim-default-traversal/src/zope/app/publication/traversers.py
===================================================================
--- Zope3/branches/jim-default-traversal/src/zope/app/publication/traversers.py	2004-08-10 19:49:07 UTC (rev 26975)
+++ Zope3/branches/jim-default-traversal/src/zope/app/publication/traversers.py	2004-08-10 19:55:52 UTC (rev 26976)
@@ -44,6 +44,38 @@
             raise NotFound(ob, name)
         return view
 
+class MethodTraverser(object):
+    """Support traversal of methods
+
+    This adapter actually prevents traversal:
+
+      >>> ob = object()      # don't really care what object
+      >>> request = object() # request is ignored
+      >>> adapter = MethodTraverser(ob, request)
+      >>> try:
+      ...     adapter.publishTraverse(request, 'foo')
+      ... except NotFound, v:
+      ...     print (v.ob, v.name) == (ob, 'foo')
+      True
+
+    Method objects are their own browser default:
+
+      >>> adapter.browserDefault(request) == (ob, None)
+      True
+      
+    """
+    def __init__(self, context, request):
+        self.context = context
+        self.request = request
+    
+    def browserDefault(self, request):
+        return self.context, None
+
+    def publishTraverse(self, request, name):
+        raise NotFound(self.context, name)
+
+    
+
 class FileContentTraverser(SimpleComponentTraverser):
     """Browser traverser for file content.
 

Modified: Zope3/branches/jim-default-traversal/src/zope/app/traversing/browser/configure.zcml
===================================================================
--- Zope3/branches/jim-default-traversal/src/zope/app/traversing/browser/configure.zcml	2004-08-10 19:49:07 UTC (rev 26975)
+++ Zope3/branches/jim-default-traversal/src/zope/app/traversing/browser/configure.zcml	2004-08-10 19:55:52 UTC (rev 26976)
@@ -3,7 +3,7 @@
     xmlns:browser="http://namespaces.zope.org/browser">
 
   <view
-      for="zope.interface.Interface"
+      for="*"
       type="zope.publisher.interfaces.browser.IBrowserRequest"
       provides="zope.publisher.interfaces.browser.IBrowserPublisher"
       factory="zope.app.publication.traversers.SimpleComponentTraverser"
@@ -11,6 +11,14 @@
       />
 
   <view
+      for="types.MethodType"
+      type="zope.publisher.interfaces.browser.IBrowserRequest"
+      provides="zope.publisher.interfaces.browser.IBrowserPublisher"
+      factory="zope.app.publication.traversers.MethodTraverser"
+      permission="zope.Public"
+      />
+
+  <view
       for="zope.app.container.interfaces.IItemContainer"
       type="zope.publisher.interfaces.browser.IBrowserRequest"
       provides="zope.publisher.interfaces.browser.IBrowserPublisher"

Modified: Zope3/branches/jim-default-traversal/src/zope/app/xmlrpc/configure.zcml
===================================================================
--- Zope3/branches/jim-default-traversal/src/zope/app/xmlrpc/configure.zcml	2004-08-10 19:49:07 UTC (rev 26975)
+++ Zope3/branches/jim-default-traversal/src/zope/app/xmlrpc/configure.zcml	2004-08-10 19:55:52 UTC (rev 26976)
@@ -4,7 +4,7 @@
     >
 
   <view 
-      for="zope.interface.Interface"
+      for="*"
       type="zope.publisher.interfaces.xmlrpc.IXMLRPCRequest"
       provides="zope.publisher.interfaces.xmlrpc.IXMLRPCPublisher"
       factory="zope.app.publication.traversers.SimpleComponentTraverser"



More information about the Zope3-Checkins mailing list