[Zope3-dev] traversing path from scratch

Steve Alexander steve@cat-box.net
Tue, 07 May 2002 09:46:20 +0100


Gary Poster wrote:
> ok, folks: I have a physical path stored from a traverser
> 
>         self.subscriber_path=getAdapter(
>             subscriber, ITraverser).getPhysicalPath()
> 
> later on, from another method in this object I want to use the stored path to 
> get the original object.  If my object were wrapped, this would be easy:
> 
>         return getAdapter(self, ITraverser).traverse(self.subscriber_path)
> 
> However, I have nothing wrapped available to me at all.  In effect, I want to 
> do
> 
>         return getAdapter(None, ITraverser).traverse(self.subscriber_path)
> 
> However, the default Traverser implementation (Zope.App.Traversing.Traverser) 
> needs to have a wrapped object to work with to get the root folder.
> 
> Any ideas?  If I could get a wrapped root object I guess that would be good 
> enough--can we have a global component that returns a wrapped root folder for 
> situations like this?  Is there a reliable way of getting the root folder?  
> Should this be turned into a component, if so?  Because of the importance of 
> this, I'd be tempted to make it a global service myself, i.e. 
> getService(None, 'RootService').getRoot() except that looks kinda stupid and 
> I can't think of what else we would use such a service for...

I think you're right.

I don't think we need a RootService, as there's already an API for 
getting the Root in ITraverser.py.

The Traverser is the only application-level thing that needs to directly 
know about the Root object.

I don't like the look of this:

   return getAdapter(None, ITraverser).traverse(self.subscriber_path)

Adapting from None doesn't make sense to me, from a 
code-that-reflects-your-intentions point of view.

I think we need a Traversal service. The Traversal service will get you 
an ITraverser, just as in the getAdapter call above. The Traversal 
service knows about the root object, so it can provide traversal in the 
absence of a wrapped object to start from.


(I'm assuming here that there's only supposed to be a single root object 
for a zope instance. If there are several root objects, then I guess 
that each root object will offer its own placeful traversal service, and 
there will need to be another means of getting the root objects. Someone 
say yagni please!)

--
Steve Alexander