# HG changeset patch # User souliane # Date 1450185139 -3600 # Node ID 681fe91abcc09ec706b3f8744db9f1b7580b6c56 # Parent a12e5e866d2529bfd4d2b05da4b3dbf003f07e0f memory (params): parameter jids_list values are specified with ... diff -r a12e5e866d25 -r 681fe91abcc0 frontends/src/tools/xmlui.py --- a/frontends/src/tools/xmlui.py Tue Dec 15 13:33:35 2015 +0100 +++ b/frontends/src/tools/xmlui.py Tue Dec 15 14:12:19 2015 +0100 @@ -35,6 +35,8 @@ class ClassNotRegistedError(Exception): pass + +# FIXME: this method is duplicated in frontends.tools.xmlui.getText def getText(node): """Get child text nodes @param node: dom Node diff -r a12e5e866d25 -r 681fe91abcc0 src/memory/params.py --- 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 ... and not + 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: diff -r a12e5e866d25 -r 681fe91abcc0 src/tools/xml_tools.py --- a/src/tools/xml_tools.py Tue Dec 15 13:33:35 2015 +0100 +++ b/src/tools/xml_tools.py Tue Dec 15 14:12:19 2015 +0100 @@ -1367,6 +1367,7 @@ def decapsulateDomishContent(elt): """Return the inner content of a domish.Element. + @param elt (domish.Element) @return unicode """ result = '' @@ -1376,3 +1377,17 @@ except AttributeError: result += child # child is unicode return result + + +# FIXME: this method is duplicated from frontends.tools.xmlui.getText +def getText(node): + """Get child text nodes of a domish.Element. + + @param node (domish.Element) + @return: joined unicode text of all nodes + """ + data = [] + for child in node.childNodes: + if child.nodeType == child.TEXT_NODE: + data.append(child.wholeText) + return u"".join(data)