def _transform_literal_meta(self, lit_bf_meta): dt = lit_bf_meta.get('@datatype') content = lit_bf_meta.get('$') att_key = lit_bf_meta['@property'] full_obj = {} for k in lit_bf_meta.keys(): if k not in _SUPPRESSED_LITERAL: full_obj[k] = lit_bf_meta[k] # Coercion should not be needed for json->json if dt and self._coercing_literals: if is_str_type(content): content = _coerce_literal_val_to_primitive(dt, content) att_key = '^' + att_key if full_obj: if content: full_obj['$'] = content _cull_redundant_about(full_obj) return att_key, full_obj return att_key, content
def _literal_transform_meta_key_value(self, minidom_meta_element): att_key = None dt = minidom_meta_element.getAttribute('datatype') or 'xsd:string' att_str_val = minidom_meta_element.getAttribute('content') att_key = minidom_meta_element.getAttribute('property') full_obj = {} if att_key is None: _LOG.debug('"property" missing from literal meta') return None, None att_container = minidom_meta_element.attributes for i in range(att_container.length): attr = att_container.item(i) handling_code, new_name = _literal_meta_att_decision_fn(attr.name) if handling_code == ATT_TRANSFORM_CODE.IN_FULL_OBJECT: full_obj[new_name] = attr.value else: if handling_code == ATT_TRANSFORM_CODE.IN_XMLNS_OBJ: full_obj.setdefault('@xmlns', {})[new_name] = attr.value else: assert handling_code == ATT_TRANSFORM_CODE.HANDLED if not att_str_val: att_str_val, ntl = _extract_text_and_child_element_list( minidom_meta_element) att_str_val = att_str_val.strip() if len(ntl) > 1: _LOG.debug( 'Nested meta elements are not legal for LiteralMeta (offending property="%s")', att_key) return None, None if len(ntl) == 1: self._hbf_handle_child_elements(full_obj, ntl) att_key = '^' + att_key trans_val = _coerce_literal_val_to_primitive(dt, att_str_val) if trans_val is None: return None, None if full_obj: if trans_val: full_obj['$'] = trans_val _cull_redundant_about(full_obj) return att_key, full_obj return att_key, trans_val
def _literal_transform_meta_key_value(self, minidom_meta_element): att_key = None dt = minidom_meta_element.getAttribute('datatype') or 'xsd:string' att_str_val = minidom_meta_element.getAttribute('content') att_key = minidom_meta_element.getAttribute('property') full_obj = {} if att_key is None: _LOG.debug('"property" missing from literal meta') return None, None att_container = minidom_meta_element.attributes for i in range(att_container.length): attr = att_container.item(i) handling_code, new_name = _literal_meta_att_decision_fn(attr.name) if handling_code == ATT_TRANSFORM_CODE.IN_FULL_OBJECT: full_obj[new_name] = attr.value else: if handling_code == ATT_TRANSFORM_CODE.IN_XMLNS_OBJ: full_obj.setdefault('@xmlns', {})[new_name] = attr.value else: assert handling_code == ATT_TRANSFORM_CODE.HANDLED if not att_str_val: att_str_val, ntl = _extract_text_and_child_element_list(minidom_meta_element) att_str_val = att_str_val.strip() if len(ntl) > 1: _LOG.debug('Nested meta elements are not legal for LiteralMeta (offending property="%s")', att_key) return None, None if len(ntl) == 1: self._hbf_handle_child_elements(full_obj, ntl) att_key = '^' + att_key trans_val = _coerce_literal_val_to_primitive(dt, att_str_val) if trans_val is None: return None, None if full_obj: if trans_val: full_obj['$'] = trans_val _cull_redundant_about(full_obj) return att_key, full_obj return att_key, trans_val