diff options
author | Lance Stout <lancestout@gmail.com> | 2010-08-13 12:24:47 -0400 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2010-08-13 12:24:47 -0400 |
commit | c20fab0f6c28bcbfbe54db687be056a9b5088ad4 (patch) | |
tree | 5119149fc15b54463d52d16e940b68c2f336a43d /sleekxmpp | |
parent | c721fb412618662d33fa73fb9f9e1f0c4f045fef (diff) | |
download | slixmpp-c20fab0f6c28bcbfbe54db687be056a9b5088ad4.tar.gz slixmpp-c20fab0f6c28bcbfbe54db687be056a9b5088ad4.tar.bz2 slixmpp-c20fab0f6c28bcbfbe54db687be056a9b5088ad4.tar.xz slixmpp-c20fab0f6c28bcbfbe54db687be056a9b5088ad4.zip |
Updated ElementBase.setup, and added unit tests.
Diffstat (limited to 'sleekxmpp')
-rw-r--r-- | sleekxmpp/xmlstream/stanzabase.py | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/sleekxmpp/xmlstream/stanzabase.py b/sleekxmpp/xmlstream/stanzabase.py index 6762792f..b11d59ee 100644 --- a/sleekxmpp/xmlstream/stanzabase.py +++ b/sleekxmpp/xmlstream/stanzabase.py @@ -76,6 +76,38 @@ class ElementBase(object): self.iterables.append(sub(child, self)) break + def setup(self, xml=None): + """ + Initialize the stanza's XML contents. + + Will return True if XML was generated according to the stanza's + definition. + + Arguments: + xml -- Optional XML object to use for the stanza's content + instead of generating XML. + """ + if self.xml is None: + self.xml = xml + + if self.xml is None: + # Generate XML from the stanza definition + for ename in self.name.split('/'): + new = ET.Element("{%s}%s" % (self.namespace, ename)) + if self.xml is None: + self.xml = new + else: + last_xml.append(new) + last_xml = new + if self.parent is not None: + self.parent().xml.append(self.xml) + + # We had to generate XML + return True + else: + # We did not generate XML + return False + @property def attrib(self): #backwards compatibility return self @@ -159,22 +191,6 @@ class ElementBase(object): def findall(self, xpath): return self.xml.findall(xpath) - def setup(self, xml=None): - if self.xml is None: - self.xml = xml - if self.xml is None: - for ename in self.name.split('/'): - new = ET.Element("{%(namespace)s}%(name)s" % {'name': self.name, 'namespace': self.namespace}) - if self.xml is None: - self.xml = new - else: - self.xml.append(new) - if self.parent is not None: - self.parent().xml.append(self.xml) - return True #had to generate XML - else: - return False - def enable(self, attrib): self.initPlugin(attrib) return self |