[Zope-dev] Proxy Object / __getattr__ / Acquisition

Steve Alexander steve@cat-box.net
Thu, 29 Aug 2002 22:50:23 +0100


sean.upton@uniontrib.com wrote:
> I am trying to implement a proxy class (specifically for the purposes of
> multi-versioned document objects (folderish proxies that contain the object
> that they proxy to).  I am using __getattr__ within my product, and the code
> pasted below works, and does not "break" Implicit acquisition (because the
> object that _CurrentVersion points to is subclassed from SimpleItem, which
> implements Implicit Acquisition). However, because of the way that this
> messes with Acquisition, certain things like accessing the ZMI pages or
> acquired methods can be quite slow (but work).  I suspect that this is
> because an instance of this class actually acquires items through the item
> it proxies to, which conveniently is contained inside it, which makes
> acquisition work for the instance of this class (albeit magnitudes slower).
> 
> I would really like to make this perform better and act properly, but I'm at
> a loss as to the right way to do this.  Thoughts?
> 
> Sean
> 
> class MVProxy(Folder):
>         """
>         Object acting as proxy to multiple document
>         implementations serving for each version of this
>         document; this is a proxy object class
>         Subclasses OFS.Folder.Folder
>         """
>         def __init__(self, id, title=''):
>                 self.id = id
>                 self.title = title
>                 timestamp = str(int(time.mktime(time.localtime())))
>                 currentId = id+'_'+timestamp
>                 current = DocumentCoreImpl(currentId, title)
>                 self._setObject(currentId, current)
>                 self._CurrentVersion = current
> 
>         def __getattr__(self, name):
>                 return getattr(self._CurrentVersion, name)


Can you use __bobo_traverse__ instead of __getattr__  ?

That should make things much faster.

--
Steve Alexander