Re: [Zope] How to see if two objects are the same (minor fix)
Ron Bickers <[EMAIL PROTECTED]> wrote: > > From my previous post, it looked like the parent was changing. I had > the first two lines swapped. Fixed below. > > > > I want to see if an object is the one aqcuired from the root, but I'm > hitting walls. > > > > > > This returns the following when in the root folder context: > > > > 0 > > It returns the following in a folder where there is another myObject: > > > > 0 > > What am I missing in the comparison? You are seeing the result of a (mis)feature of acquisition: the objects you are comparing are actually AcquisitionImplicitWrappers around the real 'myObject'; because the two wrappers are different, and because the underlying object doesn't define a custom '__cmp__()' method, the two wrappers are compared for identity (which is bogus). I recently fixed this in response to a Collector issue: http://classic.zope.org:8080/Collector/1650/view You can get the patch from that page, or just wait for Zope 2.3 (RSN, I'm sure). Tres. -- === Tres Seaver[EMAIL PROTECTED] Digital Creations "Zope Dealers" http://www.zope.org ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] How to see if two objects are the same (minor fix)
Ron Bickers writes: > I want to see if an object is the one aqcuired from the root, but I'm > hitting walls. > > > > > > This returns the following when in the root folder context: > > > > 0 What you see here, is Zope's (more precisely ExtensionClass's) acquisition magic: when you access "object.attribute", you (usually) will not get the object corresponding to "attribute" but a new object: "attribute.__of__(object)" i.e. the attribute object in the context of "object". When you look up an attribute of this object, it will first in the object itself and when it does not success there, it will look in the context. That is what you like with acquisition. The downside: When you access the "same" object via different contexts, you will in fact get different objects (as the contexts are different). "is" will return false, as it should be. But, even, if you use "==", you will get "false". There have been some discussion in the list, whether this is the best behaviour. What can you do? You can use the "aq_base" attribute to strip away any context and get to the base object. At least in Zope 2.2.1, "aq_base" was not exposed to DTML. Thus, you would need an external method, say "getBaseObject", to get at the base: def getBaseObject(object): return getattr(object,'aq_base',object) With this function, you can compare the base objects: Be careful, however: Even, if such a test returns true for two objects, the objects may nevertheless have different behaviour (as the contexts are different). Dieter ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
[Zope] How to see if two objects are the same (minor fix)
From my previous post, it looked like the parent was changing. I had the first two lines swapped. Fixed below. I want to see if an object is the one aqcuired from the root, but I'm hitting walls. This returns the following when in the root folder context: 0 It returns the following in a folder where there is another myObject: 0 What am I missing in the comparison? Thanks! ___ Ron Bickers Logic Etc, Inc. [EMAIL PROTECTED] ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
[Zope] How to see if two objects are the same
I want to see if an object is the one aqcuired from the root, but I'm hitting walls. This returns the following when in the root folder context: 0 It returns the following in a folder where there is another myObject: 0 What am I missing in the comparison? Thanks! ___ Ron Bickers Logic Etc, Inc. [EMAIL PROTECTED] ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )