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.
This commit is contained in:
mathieui 2020-12-01 18:57:34 +01:00
parent 15bf6bc827
commit 4eb2bb7da8

View file

@ -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):