From 4eb2bb7da855e67f1fff0d86470cc78c06e64c95 Mon Sep 17 00:00:00 2001 From: mathieui Date: Tue, 1 Dec 2020 18:57:34 +0100 Subject: ElementBase: serialize JID objects as strings automatically This is a shortcut to avoid defining custom methods each time a substanza containing a JID exists in a plugin. Same thing with attributes, there is no place where we do not want this. --- slixmpp/xmlstream/stanzabase.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/slixmpp/xmlstream/stanzabase.py b/slixmpp/xmlstream/stanzabase.py index 7eaf78a5..925f2abc 100644 --- a/slixmpp/xmlstream/stanzabase.py +++ b/slixmpp/xmlstream/stanzabase.py @@ -745,6 +745,8 @@ class ElementBase(object): getattr(self, set_method)(value, **kwargs) else: if attrib in self.sub_interfaces: + if isinstance(value, JID): + value = str(value) if lang == '*': return self._set_all_sub_text(attrib, value, @@ -863,6 +865,8 @@ class ElementBase(object): if value is None or value == '': self.__delitem__(name) else: + if isinstance(value, JID): + value = str(value) self.xml.attrib[name] = value def _del_attr(self, name): -- cgit v1.2.3