[PEAK] I don't understand uponAssembly()
Doug Quale
quale1 at charter.net
Thu Mar 24 10:02:07 EST 2005
The doc for config.makeRoot says
makeRoot ( **options )
Create a configuration root, suitable for use as a parent
component This creates and returns a new IConfigurationRoot with
its default configuration loading from peak.ini. The returned root
component will "know" it is a root, so any components that use it
as a parent will get their uponAssembly() events invoked
immediately.
but I don't understand how this works.
>>> class k(binding.Component):
... def uponAssembly(self):
... print 'assembling %r' % self
...
>>> x = k(None)
assembling <__main__.k object at 0xb793ff2c>
So specifying None as the parent gets uponAssembly() called
immediately. That makes sense.
With no parent specified (parent=NOTGIVEN), uponAssembly() isn't
called when the instance is created:
>>> x = k()
>>>
but if I ask for the parent, I find out it's None and uponAssembly()
is called:
>>> binding.getParentComponent(x)
assembling <__main__.k object at 0xb795c40c>
This seems OK too since peak bindings are lazy (probably including the
parentComponent binding).
If instead I make a root and use it as parent:
>>> x = k(config.makeRoot())
>>>
I find uponAssembly() isn't called, but based on the makeRoot doc I
thought it would be. And if I ask for the parent
>>> binding.getParentComponent(x)
<peak.config.config_components.ConfigurationRoot object at 0xb793fa4c>
I get a ConfigurationRoot but still no call to uponAssembly().
More information about the PEAK
mailing list