[PEAK] assembling components from ZConfig

alexander smishlajev alex at ank-sia.com
Sat Oct 23 04:11:20 EDT 2004


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.

to overcome this, i did the following:

     class Assembler(binding.Component):

         # list of subcomponents requiring assembly
         # for each subcomponent, this list must contain
         # 2-element tuple: (attribute_name, attr_is_list)
         _need_assembly_ = []

         def __assembly(self):
             for (_attr, _is_list) in self._need_assembly_:
                 _children = getattr(self, _attr)
                 if not _is_list:
                     _children = [_children]
                 for _child in _children:
                     _child.setParentComponent(self, _attr, suggest=True)
         __assembly = binding.Make(__assembly, uponAssembly=True)

     class Beacon(Assembler):

         components = [] # filled from ZConfig
         _need_assembly_ = [("components", True)]

is there anything i am doing wrong by any means?

all Spam components get a component name 'components'.  can i give 
distinct name for each of them?  if yes, how?  (note: specifying custom 
name in .setParentComponent() does not help.)

best wishes,
alex.





More information about the PEAK mailing list