Re: [Zope-dev] Proxy Object / __getattr__ / Acquisition
[EMAIL PROTECTED] writes: I am using __getattr__ within my product, and the code pasted below works ... 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). ... def __getattr__(self, name): return getattr(self._CurrentVersion, name) I am (almost) sure, you run into the same problem than I did and reported to mailto:[EMAIL PROTECTED]. You get an infinite __getattr__ loop, broken via a RuntimeError, maximal recursion exceeded which is silently ignored. Use def __getattr__(self,name): # avoid acquisition current= self.__dict__['_CurrentVersion'] if hasattr(current,name): return getattr(self._CurrentVersion,name) More info in the ZPT mailing list archives. Dieter ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
[Zope-dev] Proxy Object / __getattr__ / Acquisition
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 [EMAIL PROTECTED] |PATH_TO_THE_DARK_SIDE = 'c:\winnt\system32' +--- ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Proxy Object / __getattr__ / Acquisition
[EMAIL PROTECTED] 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 ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Proxy Object / __getattr__ / Acquisition
At 14:28 2002-08-29 -0700, [EMAIL PROTECTED] said: I am trying to implement a proxy class (specifically for the purposes of multi-versioned document objects (folderish proxies that contain the object Hi Sean, We've been stealing some code from CMFCore.Skinnable to do similar things (multi-language objects): Skinnable gets the skins when the objects is being wrapped (e.g. in the objects __of__ method) and overrides __getattr__ which uses the skins or falls back to an unbound superGetAttr method that points to the inherited __getattr__. (The superGetAttr have pussled us because it seams like superGetAttr is None, but everything still work as expected.) We replace the skin with a VeryTinyDataWrapper which (of course) implements Acquisition.Implicit. Would this work better that the way your doing it? We currently implementing this so I don't know for sure that it is faster, but it's from CMF (a key part to) so it shouldn't be to slow or? def setupCurrentLanguageData(self): #the request part is a rest from Skinnable, I don't think it can be removed. request=self.request #replace this with anything that returns lang_code=self.EasyLanguageService.getCurrentLanguage() ob = self._current_language.get(lang_code, VerySmallData()) self._v_c_language = (request, ob, {}) def __getattr__(self, name, marker=None): # OK, see if we can find the language service: if not name.startswith('_') and not name.startswith('aq_'): cl = self._v_c_language if cl is not None: request, ob, ignore = cl if not ignore.has_key(name): subob = getattr(ob, name, _marker) if subob is not _marker: # Return it in context of self, forgetting # its location and acting as if it were located # in self. return aq_base(subob) else: ignore[name] = 1 if superGetAttr is None: raise AttributeError, name return superGetAttr(self, name) def __of__(self, parent): ''' Sneakily sets up the current language then returns the wrapper that Acquisition.Implicit.__of__() would return. ''' w_self = ImplicitAcquisitionWrapper(aq_base(self), parent) try: w_self.setupCurrentLanguageData() except: # This shouldn't happen, even if the requested current language # does not exist. import sys from zLOG import LOG, ERROR LOG('CMFCore', ERROR, 'Unable to setupCurrentLanguageData()', error=sys.exc_info()) return w_self Regards, Johan Carlsson -- Torped Strategi och Kommunikation AB Johan Carlsson [EMAIL PROTECTED] Mail: Birkagatan 9 SE-113 36 Stockholm Sweden Visit: Västmannagatan 67, Stockholm, Sweden Phone +46-(0)8-32 31 23 Fax +46-(0)8-32 31 83 Mobil +46-(0)70-558 25 24 http://www.torped.se http://www.easypublisher.com ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )