comparison 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
comparison
equal deleted inserted replaced
1739:a12e5e866d25 1740:681fe91abcc0
26 from sat.core.log import getLogger 26 from sat.core.log import getLogger
27 log = getLogger(__name__) 27 log = getLogger(__name__)
28 from twisted.internet import defer 28 from twisted.internet import defer
29 from twisted.python.failure import Failure 29 from twisted.python.failure import Failure
30 from twisted.words.protocols.jabber import jid 30 from twisted.words.protocols.jabber import jid
31 from sat.tools.xml_tools import paramsXML2XMLUI 31 from sat.tools.xml_tools import paramsXML2XMLUI, getText
32 32
33 # TODO: params should be rewritten using Twisted directly instead of minidom 33 # TODO: params should be rewritten using Twisted directly instead of minidom
34 # general params should be linked to sat.conf and kept synchronised 34 # general params should be linked to sat.conf and kept synchronised
35 # this need an overall simplification to make maintenance easier 35 # this need an overall simplification to make maintenance easier
36 36
372 log.error(_(u'Parameter (%(cat)s, %(param)s) of type list has no default option!') % {'cat': cat, 'param': param}) 372 log.error(_(u'Parameter (%(cat)s, %(param)s) of type list has no default option!') % {'cat': cat, 'param': param})
373 else: 373 else:
374 log.error(_(u'Parameter (%(cat)s, %(param)s) of type list has more than one default option!') % {'cat': cat, 'param': param}) 374 log.error(_(u'Parameter (%(cat)s, %(param)s) of type list has more than one default option!') % {'cat': cat, 'param': param})
375 raise exceptions.DataError 375 raise exceptions.DataError
376 elif node.getAttribute('type') == 'jids_list': 376 elif node.getAttribute('type') == 'jids_list':
377 if not value_to_use: 377 assert not value_to_use # only accept <jid>...</jid> and not <param value...>
378 log.debug(u"jids list value is empty") 378 jids = [getText(jid_) for jid_ in node.getElementsByTagName("jid")]
379 return []
380 jids = value_to_use.split('\t')
381 to_delete = [] 379 to_delete = []
382 for idx, value in enumerate(jids): 380 for idx, value in enumerate(jids):
383 try: 381 try:
384 jids[idx] = jid.JID(value) 382 jids[idx] = jid.JID(value)
385 except jid.InvalidFormat: 383 except (RuntimeError, jid.InvalidFormat, AttributeError):
386 log.warning(u"Incorrect jid value found in jids list: [{}]".format(value)) 384 log.warning(u"Incorrect jid value found in jids list: [{}]".format(value))
387 to_delete.append(value) 385 to_delete.append(value)
388 for value in to_delete: 386 for value in to_delete:
389 jids.remove(value) 387 jids.remove(value)
390 return jids 388 return jids
677 try: 675 try:
678 option.removeAttribute('selected') 676 option.removeAttribute('selected')
679 except NotFoundErr: 677 except NotFoundErr:
680 pass 678 pass
681 elif dest_params[name].getAttribute('type') == 'jids_list': 679 elif dest_params[name].getAttribute('type') == 'jids_list':
682 jids = profile_value.split('\t') # FIXME: it's not good to use tabs as separator ! 680 jids = [getText(jid_) for jid_ in dest_params[name].getElementsByTagName("jid")]
683 for jid_ in jids: 681 for jid_ in jids:
684 jid_elt = prof_xml.createElement('jid') 682 try:
685 jid_elt.appendChild(prof_xml.createTextNode(jid_)) 683 jid.JID(jid_)
686 dest_params[name].appendChild(jid_elt) 684 except (RuntimeError, jid.InvalidFormat, AttributeError):
685 log.warning(u"Incorrect jid value found in jids list: [{}]".format(jid_))
686 else:
687 jid_elt = prof_xml.createElement('jid')
688 jid_elt.appendChild(prof_xml.createTextNode())
689 dest_params[name].appendChild(jid_elt)
687 else: 690 else:
688 dest_params[name].setAttribute('value', profile_value) 691 dest_params[name].setAttribute('value', profile_value)
689 if new_node: 692 if new_node:
690 prof_xml.documentElement.appendChild(dest_cat) 693 prof_xml.documentElement.appendChild(dest_cat)
691 694