summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream/stanzabase.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-03-18 17:34:07 -0400
committerLance Stout <lancestout@gmail.com>2011-03-18 17:34:07 -0400
commitdbf6780345bb202d4a0a49034fbfc4535e844170 (patch)
tree81270353d5f8bae818685c610ce7df94dfc6de13 /sleekxmpp/xmlstream/stanzabase.py
parent450c31334044655053b67ff984cbe4d57b445c44 (diff)
downloadslixmpp-dbf6780345bb202d4a0a49034fbfc4535e844170.tar.gz
slixmpp-dbf6780345bb202d4a0a49034fbfc4535e844170.tar.bz2
slixmpp-dbf6780345bb202d4a0a49034fbfc4535e844170.tar.xz
slixmpp-dbf6780345bb202d4a0a49034fbfc4535e844170.zip
Change namespace inclusion in strings.
ElementBase instances will display the top-most namespace by default. StanzaBase instances will NOT display the top-most namespace by default. May pass True or False to __str__ to override.
Diffstat (limited to 'sleekxmpp/xmlstream/stanzabase.py')
-rw-r--r--sleekxmpp/xmlstream/stanzabase.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/sleekxmpp/xmlstream/stanzabase.py b/sleekxmpp/xmlstream/stanzabase.py
index 753977c1..e9c7fc7a 100644
--- a/sleekxmpp/xmlstream/stanzabase.py
+++ b/sleekxmpp/xmlstream/stanzabase.py
@@ -991,11 +991,16 @@ class ElementBase(object):
"""
return self.__class__(xml=copy.deepcopy(self.xml), parent=self.parent)
- def __str__(self):
+ def __str__(self, top_level_ns=True):
"""
Return a string serialization of the underlying XML object.
+
+ Arguments:
+ top_level_ns -- Display the top-most namespace.
+ Defaults to True.
"""
- return tostring(self.xml, xmlns='', stanza_ns=self.namespace)
+ stanza_ns = '' if top_level_ns else self.namespace
+ return tostring(self.xml, xmlns='', stanza_ns=stanza_ns)
def __repr__(self):
"""
@@ -1196,10 +1201,17 @@ class StanzaBase(ElementBase):
return self.__class__(xml=copy.deepcopy(self.xml),
stream=self.stream)
- def __str__(self):
- """Serialize the stanza's XML to a string."""
+ def __str__(self, top_level_ns=False):
+ """
+ Serialize the stanza's XML to a string.
+
+ Arguments:
+ top_level_ns -- Display the top-most namespace.
+ Defaults to False.
+ """
+ stanza_ns = '' if top_level_ns else self.namespace
return tostring(self.xml, xmlns='',
- stanza_ns=self.namespace,
+ stanza_ns=stanza_ns,
stream=self.stream)