mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-30 19:19:55 +00:00
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.
This commit is contained in:
parent
450c313340
commit
dbf6780345
1 changed files with 17 additions and 5 deletions
|
@ -991,11 +991,16 @@ class ElementBase(object):
|
||||||
"""
|
"""
|
||||||
return self.__class__(xml=copy.deepcopy(self.xml), parent=self.parent)
|
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.
|
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):
|
def __repr__(self):
|
||||||
"""
|
"""
|
||||||
|
@ -1196,10 +1201,17 @@ class StanzaBase(ElementBase):
|
||||||
return self.__class__(xml=copy.deepcopy(self.xml),
|
return self.__class__(xml=copy.deepcopy(self.xml),
|
||||||
stream=self.stream)
|
stream=self.stream)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self, top_level_ns=False):
|
||||||
"""Serialize the stanza's XML to a string."""
|
"""
|
||||||
|
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='',
|
return tostring(self.xml, xmlns='',
|
||||||
stanza_ns=self.namespace,
|
stanza_ns=stanza_ns,
|
||||||
stream=self.stream)
|
stream=self.stream)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue