[Zope] help with magic method "__of__"

Ken Manheimer klm@digicool.com
Mon, 12 Apr 1999 20:13:00 -0400


On Saturday, April 10, 1999 1:13 PM, Karl & Mel llwo@dbtech.net wrote"

> As I've been reading the code over and over and over (two weeks now) 
> and have thrown out three attempts.  I keep seeing things like
> 
> self.data[id].__of__(self)
> msg=msg.__of__(self)
> r=map(lambda x, p=self: x.__of__(p), r)
> 
> How does the magic method '__of__()'  work?

I'm afraid i can only give you a sketchy answer.  

__of__ is a cue for acquisition - it wraps the instance in question with
the context of what you want to be considered the instance's container.
(The creation of a new, enwrapping instance is to avoid creating any
reference loops that would defeat garbage collection.)  This way
attribute lookups in the new instance can fall through to the attributes
of the container, even if the reference is not explicitly made through
the container.

I was hoping to find a document on the site that explains this better,
but the closest i could come is one of the acquisition docs that
explains something else in terms of __of__ -
http://www.digicool.com/releases/ExtensionClass/Acquisition.html .
Maybe someone else can point out a better document - or explain the
concept (which i've only been exposed to, not yet really explored)
better than i have...

Ken Manheimer
klm@digicool.com