Mercurial > libervia-backend
diff src/memory/params.py @ 1740:681fe91abcc0
memory (params): parameter jids_list values are specified with <jid>...</jid>
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 15 Dec 2015 14:12:19 +0100 |
parents | a12e5e866d25 |
children | 9a48e09044eb |
line wrap: on
line diff
--- a/src/memory/params.py Tue Dec 15 13:33:35 2015 +0100 +++ b/src/memory/params.py Tue Dec 15 14:12:19 2015 +0100 @@ -28,7 +28,7 @@ from twisted.internet import defer from twisted.python.failure import Failure from twisted.words.protocols.jabber import jid -from sat.tools.xml_tools import paramsXML2XMLUI +from sat.tools.xml_tools import paramsXML2XMLUI, getText # TODO: params should be rewritten using Twisted directly instead of minidom # general params should be linked to sat.conf and kept synchronised @@ -374,15 +374,13 @@ log.error(_(u'Parameter (%(cat)s, %(param)s) of type list has more than one default option!') % {'cat': cat, 'param': param}) raise exceptions.DataError elif node.getAttribute('type') == 'jids_list': - if not value_to_use: - log.debug(u"jids list value is empty") - return [] - jids = value_to_use.split('\t') + assert not value_to_use # only accept <jid>...</jid> and not <param value...> + jids = [getText(jid_) for jid_ in node.getElementsByTagName("jid")] to_delete = [] for idx, value in enumerate(jids): try: jids[idx] = jid.JID(value) - except jid.InvalidFormat: + except (RuntimeError, jid.InvalidFormat, AttributeError): log.warning(u"Incorrect jid value found in jids list: [{}]".format(value)) to_delete.append(value) for value in to_delete: @@ -679,11 +677,16 @@ except NotFoundErr: pass elif dest_params[name].getAttribute('type') == 'jids_list': - jids = profile_value.split('\t') # FIXME: it's not good to use tabs as separator ! + jids = [getText(jid_) for jid_ in dest_params[name].getElementsByTagName("jid")] for jid_ in jids: - jid_elt = prof_xml.createElement('jid') - jid_elt.appendChild(prof_xml.createTextNode(jid_)) - dest_params[name].appendChild(jid_elt) + try: + jid.JID(jid_) + except (RuntimeError, jid.InvalidFormat, AttributeError): + log.warning(u"Incorrect jid value found in jids list: [{}]".format(jid_)) + else: + jid_elt = prof_xml.createElement('jid') + jid_elt.appendChild(prof_xml.createTextNode()) + dest_params[name].appendChild(jid_elt) else: dest_params[name].setAttribute('value', profile_value) if new_node: