[Zope-dev] Proxy Object / __getattr__ / Acquisition
sean.upton@uniontrib.com
sean.upton@uniontrib.com
Thu, 29 Aug 2002 14:28:40 -0700
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)
+-----------------------------------------------------------
| Sean Upton
| Site Technology Supervisor SignOnSanDiego.com
| Development & Integration The San Diego Union-Tribune
| 619.718.5241 sean.upton@uniontrib.com
| PATH_TO_THE_DARK_SIDE = 'c:\winnt\system32'
+-----------------------------------------------------------