memory (params): parameter jids_list values are specified with <jid>...</jid>
This commit is contained in:
parent
a29630c3b6
commit
9e0b24a4a5
3 changed files with 30 additions and 10 deletions
|
|
@ -35,6 +35,8 @@ class InvalidXMLUI(Exception):
|
|||
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
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ log = getLogger(__name__)
|
|||
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 @@ class Params(object):
|
|||
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 @@ class Params(object):
|
|||
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:
|
||||
|
|
|
|||
|
|
@ -1367,6 +1367,7 @@ def expandNewLinesToXHTML(text):
|
|||
def decapsulateDomishContent(elt):
|
||||
"""Return the inner content of a domish.Element.
|
||||
|
||||
@param elt (domish.Element)
|
||||
@return unicode
|
||||
"""
|
||||
result = ''
|
||||
|
|
@ -1376,3 +1377,17 @@ def decapsulateDomishContent(elt):
|
|||
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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue