Fix iterable substanzas when added as normal plugin.

If an iterable plugin was an enabled, it wasn't added to
the iterables list.
This commit is contained in:
Lance Stout 2011-12-11 17:04:58 -08:00
parent 16c72e8efd
commit 62e6d6fb4c
2 changed files with 13 additions and 8 deletions

View file

@ -290,12 +290,11 @@ class ElementBase(object):
# Initialize values using provided XML # Initialize values using provided XML
for child in self.xml.getchildren(): for child in self.xml.getchildren():
if child.tag in self.plugin_tag_map: if child.tag in self.plugin_tag_map:
plugin = self.plugin_tag_map[child.tag] plugin_class = self.plugin_tag_map[child.tag]
self.plugins[plugin.plugin_attrib] = plugin(child, self) plugin = plugin_class(child, self)
for sub in self.plugin_iterables: self.plugins[plugin.plugin_attrib] = plugin
if child.tag == "{%s}%s" % (sub.namespace, sub.name): if plugin_class in self.plugin_iterables:
self.iterables.append(sub(child, self)) self.iterables.append(plugin)
break
def setup(self, xml=None): def setup(self, xml=None):
"""Initialize the stanza's XML contents. """Initialize the stanza's XML contents.
@ -346,7 +345,10 @@ class ElementBase(object):
""" """
if attrib not in self.plugins: if attrib not in self.plugins:
plugin_class = self.plugin_attrib_map[attrib] plugin_class = self.plugin_attrib_map[attrib]
self.plugins[attrib] = plugin_class(parent=self) plugin = plugin_class(parent=self)
self.plugins[attrib] = plugin
if plugin_class in self.plugin_iterables:
self.iterables.append(plugin)
return self return self
def _get_stanza_values(self): def _get_stanza_values(self):

View file

@ -68,7 +68,10 @@ class TestElementBase(SleekTest):
'baz': '', 'baz': '',
'foo2': {'bar': '', 'foo2': {'bar': '',
'baz': 'b'}, 'baz': 'b'},
'substanzas': [{'__childtag__': '{foo}subfoo', 'substanzas': [{'__childtag__': '{foo}foo2',
'bar': '',
'baz': 'b'},
{'__childtag__': '{foo}subfoo',
'bar': 'c', 'bar': 'c',
'baz': ''}]} 'baz': ''}]}
self.failUnless(values == expected, self.failUnless(values == expected,