changeset 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 cc31dd72526d
files frontends/src/tools/xmlui.py src/memory/params.py src/tools/xml_tools.py
diffstat 3 files changed, 30 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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:
--- 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)