[Zope] the joy of hacking ZPublisher

Jim Abramson jabramson at wgen.net
Wed May 18 12:50:06 EDT 2005


In my Zope 2.7 Product, I'm trying to implement a special folder, which
intercepts the publishing call to any subobject and wraps the entire
call in another.

A concrete example: where the default action would be to traverse
/MyProduct/SpecialFolder/something, and publish the attr 'something'
from SpecialFolder, I want this to happen instead:

doSomethingBeforeCallingTheRequestedObj()
try:
    return mapply( something, blahblah...)
finally:
    doSomethingAfterCallingTheRequestedObj()

Why? I need to do stuff to the REQUEST before the object is called (this
part wasn't difficult), and then do something *after* it's called - no
matter what the results were.  But only for publishables that live in or
beneath the Special Folder.

In fact I have something working, but one big problem - it breaks
management screens in a bad way.  The implementation is pasted below.
Is there some much simpler way to accomplish this behavior?  And am I
short-circuiting security machinery in some dangerous way?


class Wrapper(Implicit):
    """voodoo"""
    
    id = meta_type = title = "Wrapper"
    
    def __init__(self, publishable):
        self.pub = publishable

    def index_html(self):
        """
        render the results to the client
        """
        REQUEST = self.REQUEST
        print self.__class__.__name__, 'calling', self.pub
        try:
            return mapply(self.pub, REQUEST.args, REQUEST,
                        call_object,1,
                        missing_name,
                        dont_publish_class,
                        REQUEST, bind=1)
        finally:
            print self.__class__.__name__, 'done'
            print ''
            print ''
            
    __call__ = index_html
    
Globals.InitializeClass(Wrapper)    


class SpecialFolder(Folder):

    def __bobo_traverse__ (self,REQUEST,key):
        print '__bobo_traverse__', REQUEST.URL, key
        stack = REQUEST['TraversalRequestNameStack']
        target = getattr(self,key)
        if stack: return target
        return Wrapper(target).__of__(self)
        

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope/attachments/20050518/4a52a0a5/attachment.htm


More information about the Zope mailing list