def vobj_to_typed(val, root, typelist): tag = root.tag tag = tag[1 + tag.rindex('}'):] if tag in typelist: types = typelist[tag] if isinstance(types, tuple): if is_sequence(val): val = u' '.join(val) for t in types: if type_checkers[t](val): append_typed_el(root, t, val) break else: append_typed_el(root, 'unknown', val) elif types == 'text-list': if not is_sequence(val): val = [val] for v in val: append_typed_el(root, 'text', v) else: append_typed_el(root, types, val) else: if is_sequence(val): val = u' '.join(val) append_typed_el(root, 'unknown', val)
def vobj_to_typed(val, root, typelist): tag = root.tag tag = tag[1 + tag.rindex('}'):] if tag in typelist: types = typelist[tag] if isinstance(types, tuple): if is_sequence(val): val = u' '.join(val) for t in types: if type_checkers[t](val): append_typed_el(root, t, val) break else: append_typed_el(root, 'unknown', val) elif types == 'text-list': if not is_sequence(val): val = [val] for v in val: if is_sequence(v): v = ",".join(v) append_typed_el(root, 'text', v) else: append_typed_el(root, types, val) else: if is_sequence(val): val = u' '.join(val) append_typed_el(root, 'unknown', val)
def vobj_to_str(vobj, root, attributes): """Fill a XCard element's properties and text from the vobject's properties :type vobj: :vobject-class:`VBase` :param vobj: the vcard content element :type root: :lxml-class:`_Element` :param root: the xCard element to be filled :type attributes: [str] :param attributes: the list of attributes to be filled """ for n in attributes: val = getattr(vobj, n, None) if val: # vobject disagrees with rfc6531 if n == 'family': n = 'surname' el = root.makeelement(VCARD_NSB + n.lower(), nsmap=NSMAP) root.append(el) if is_sequence(val): val = u' '.join(val) el.text = val