[Zope] "virtual" subobjects

Phillip J. Eby pje@telecommunity.com
Fri, 06 Aug 1999 09:54:26 -0500


At 11:42 PM 8/5/99 -0700, Amos Latteier wrote:
>Later you can consult the REQUEST to determine what the path info was.
>
>Actually, now that I think of it you'll need something a little more
>complex, since you need to actually publish something in the end.
>ZPublisher will try for the 'index_html' method, but that's just more of
>the same, so you can either explicitly do some testing in __bobo_traverse__
>to return 'index_html' when asked, or you can rely on __call__.
>
>Here's a minimally working example,
>
>  class PathEater:
>      "Eats path info for breakfast"
>    
>      def __init__(self):
>          self.steps=[]
>    
>      def __bobo_traverse__(self, request, name):
>          self.steps.append(name)
>          return self
>          
>      def __call__(self):
>          "Publish method"
>          return "I ate %s" % self.steps
>
>If you want to experiment with stuff like this I highly recommend using
>ZPublisher.Test and ignoring the Zope framework until you understand object
>publishing on a more basic Pythonic level.

By the way, speaking of the Zope framework...  If you're going to do
something like the above in Zope, keep in mind that this will do terrible
horrible nasty things unless you name the steps attribute _v_steps so that
it doesn't get stored in the object database.  Otherwise every hit to a
PathEater will create worthless transactions modifying the 'steps'
attribute on disk.  Ugh!


>So in your example you want to write an object that will gobble up all the
>entry names that follow it. Here's how that could be done,
>
>    def __bobo_traverse__(self, REQUEST, name):
>        "I am my own sub-object"
>        return self
>
>I think I learned this trick from Phillip Eby, but I can't remember ;-)

Well, *I* got it from Jim Fulton, so there.  :)