[PEAK] assembling components from ZConfig

Phillip J. Eby pje at telecommunity.com
Sat Oct 23 17:03:22 EDT 2004


At 11:11 AM 10/23/04 +0300, alexander smishlajev wrote:
>hello!
>
>this problem appears on the mailing list from time to time, but i did not 
>notice any clear generic solution.
>
>suppose i have a ZConfig component schema like this:
>
>  <component prefix="lovely.spam">
>   <sectiontype name="SPAM" datatype=".Spam.fromZConfig" />
>   <sectiontype name="BEACON" datatype=".Beacon.fromZConfig" >
>    <multisection name="*" type="SPAM" attribute="components"
>     required="yes"
>    />
>   </sectiontype>
>  </component>
>
>when i run this, beacon is served with spam, as expected, but spam 
>components get neither parent nor component name, and do not receive 
>assembly events.

Does the 'Beacon' class have a binding called 'components'?  If not, the 
items assigned to it will not get a parent.


>     class Beacon(Assembler):
>
>         components = [] # filled from ZConfig
>         _need_assembly_ = [("components", True)]

It should suffice to have 'components = binding.Make(list)' or 
'components=binding.Require("to be filled by ZConfig")' or some such, and 
without any need for an 'Assembler' class.


>all Spam components get a component name 'components'.  can i give 
>distinct name for each of them?

Sort of.  If you have a binding called '_name', then the ZConfig section 
name will be passed to it.  So, e.g. '_name = binding.Require("ZConfig 
section name")' will allow this.  Actually, it doesn't even need to be a 
binding; you could use '_name = None' and then it will be 'None' unless set 
by ZConfig.




More information about the PEAK mailing list