From 37b571c55ab00b3107a480027f0ba212831bf7ed Mon Sep 17 00:00:00 2001 From: Nathan Fritz Date: Wed, 21 Apr 2010 23:51:37 -0700 Subject: added pubsub#event stanzas, multi-subtypes iterable stanzas, pubsub#event test coverage --- sleekxmpp/xmlstream/stanzabase.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'sleekxmpp/xmlstream/stanzabase.py') diff --git a/sleekxmpp/xmlstream/stanzabase.py b/sleekxmpp/xmlstream/stanzabase.py index f72aa6e2..ae9e9df7 100644 --- a/sleekxmpp/xmlstream/stanzabase.py +++ b/sleekxmpp/xmlstream/stanzabase.py @@ -60,8 +60,11 @@ class ElementBase(tostring.ToString): for child in self.xml.getchildren(): if child.tag in self.plugin_tag_map: self.plugins[self.plugin_tag_map[child.tag].plugin_attrib] = self.plugin_tag_map[child.tag](xml=child, parent=self) - if self.subitem is not None and child.tag == "{%s}%s" % (self.subitem.namespace, self.subitem.name): - self.iterables.append(self.subitem(xml=child, parent=self)) + if self.subitem is not None: + for sub in self.subitem: + if child.tag == "{%s}%s" % (sub.namespace, sub.name): + self.iterables.append(sub(xml=child, parent=self)) + break @property @@ -263,7 +266,10 @@ class ElementBase(tostring.ToString): for pluginkey in self.plugins: out[pluginkey] = self.plugins[pluginkey].getValues() if self.iterables: - iterables = [x.getValues() for x in self.iterables] + iterables = [] + for stanza in self.iterables: + iterables.append(stanza.getValues()) + iterables[-1].update({'__childtag__': "{%s}%s" % (stanza.namespace, stanza.name)}) out['substanzas'] = iterables return out @@ -271,9 +277,13 @@ class ElementBase(tostring.ToString): for interface in attrib: if interface == 'substanzas': for subdict in attrib['substanzas']: - sub = self.subitem(parent=self) - sub.setValues(subdict) - self.iterables.append(sub) + if '__childtag__' in subdict: + for subclass in self.subitem: + if subdict['__childtag__'] == "{%s}%s" % (subclass.namespace, subclass.name): + sub = subclass(parent=self) + sub.setValues(subdict) + self.iterables.append(sub) + break elif interface in self.interfaces: self[interface] = attrib[interface] elif interface in self.plugin_attrib_map and interface not in self.plugins: -- cgit v1.2.3