comparison sat/memory/disco.py @ 2712:c3f59c1dcb0a

core (memory/disco): normalise booleans in extensions
author Goffi <goffi@goffi.org>
date Sat, 01 Dec 2018 14:40:32 +0100
parents 56f94936df1e
children 378188abe941
comparison
equal deleted inserted replaced
2711:9adf44996e58 2712:c3f59c1dcb0a
390 """ 390 """
391 client = self.host.getClient(profile_key) 391 client = self.host.getClient(profile_key)
392 entity = jid.JID(entity_jid_s) 392 entity = jid.JID(entity_jid_s)
393 disco_infos = yield self.getInfos(client, entity, node, use_cache) 393 disco_infos = yield self.getInfos(client, entity, node, use_cache)
394 extensions = {} 394 extensions = {}
395 # FIXME: should extensions be serialised using tools.common.data_format?
395 for form_type, form in disco_infos.extensions.items(): 396 for form_type, form in disco_infos.extensions.items():
396 fields = [] 397 fields = []
397 for field in form.fieldList: 398 for field in form.fieldList:
398 data = {"type": field.fieldType} 399 data = {"type": field.fieldType}
399 for attr in ("var", "label", "desc"): 400 for attr in ("var", "label", "desc"):
400 value = getattr(field, attr) 401 value = getattr(field, attr)
401 if value is not None: 402 if value is not None:
402 data[attr] = value 403 data[attr] = value
403 404
404 values = [field.value] if field.value is not None else field.values 405 values = [field.value] if field.value is not None else field.values
406 if field.fieldType == u"boolean":
407 values = [C.boolConst(C.bool(v)) for v in values]
405 fields.append((data, values)) 408 fields.append((data, values))
406 409
407 extensions[form_type or ""] = fields 410 extensions[form_type or ""] = fields
408 411
409 defer.returnValue( 412 defer.returnValue((
410 ( 413 disco_infos.features,
411 disco_infos.features, 414 [(cat, type_, name or "")
412 [ 415 for (cat, type_), name in disco_infos.identities.items()],
413 (cat, type_, name or "") 416 extensions))
414 for (cat, type_), name in disco_infos.identities.items()
415 ],
416 extensions,
417 )
418 )
419 417
420 def items2tuples(self, disco_items): 418 def items2tuples(self, disco_items):
421 """convert disco items to tuple of strings 419 """convert disco items to tuple of strings
422 420
423 @param disco_items(iterable[disco.DiscoItem]): items 421 @param disco_items(iterable[disco.DiscoItem]): items