Пример #1
0
    def _transform_meta_key_value(self, minidom_meta_element):
        """Checks if the minidom_meta_element can be represented as a
            key/value pair in a object.

        Returns (key, value) ready for JSON serialization, OR
                `None, None` if the element can not be treated as simple pair.
        If `None` is returned, then more literal translation of the
            object may be required.
        """
        xt = minidom_meta_element.getAttribute('xsi:type')
        if _LITERAL_META_PAT.match(xt):
            return self._literal_transform_meta_key_value(minidom_meta_element)
        elif _RESOURCE_META_PAT.match(xt):
            return self._resource_transform_meta_key_value(minidom_meta_element)
        else:
            _LOG.debug('xsi:type attribute "%s" not LiteralMeta or ResourceMeta', xt)
            return None, None
Пример #2
0
    def _transform_meta_key_value(self, minidom_meta_element):
        '''Checks if the minidom_meta_element can be represented as a
            key/value pair in a object.

        Returns (key, value) ready for JSON serialization, OR
                `None, None` if the element can not be treated as simple pair.
        If `None` is returned, then more literal translation of the
            object may be required.
        '''
        xt = minidom_meta_element.getAttribute('xsi:type')
        if _LITERAL_META_PAT.match(xt):
            return self._literal_transform_meta_key_value(minidom_meta_element)
        elif _RESOURCE_META_PAT.match(xt):
            return self._resource_transform_meta_key_value(
                minidom_meta_element)
        else:
            _LOG.debug(
                'xsi:type attribute "%s" not LiteralMeta or ResourceMeta', xt)
            return None, None
Пример #3
0
 def _recursive_convert_dict(self, obj):
     _cull_redundant_about(obj)  # rule 10...
     meta_list = _get_index_list_of_values(obj, 'meta')
     to_inject = {}
     for meta in meta_list:
         xt = meta['@xsi:type']
         if _RESOURCE_META_PAT.match(xt):
             mk, mv = self._transform_resource_meta(meta)
         else:
             assert _LITERAL_META_PAT.match(xt)
             mk, mv = self._transform_literal_meta(meta)
         _add_value_to_dict_bf(to_inject, mk, mv)
     if ('meta' in obj) and self.remove_old_structs:
         del obj['meta']
     for k, v in to_inject.items():
         _add_value_to_dict_bf(obj, k, v)
     for k, v in obj.items():
         if isinstance(v, dict):
             self._recursive_convert_dict(v)
         elif isinstance(v, list):
             self._recursive_convert_list(v)
 def _recursive_convert_dict(self, obj):
     _cull_redundant_about(obj)  # rule 10...
     meta_list = _get_index_list_of_values(obj, 'meta')
     to_inject = {}
     for meta in meta_list:
         xt = meta['@xsi:type']
         if _RESOURCE_META_PAT.match(xt):
             mk, mv = self._transform_resource_meta(meta)
         else:
             assert _LITERAL_META_PAT.match(xt)
             mk, mv = self._transform_literal_meta(meta)
         _add_value_to_dict_bf(to_inject, mk, mv)
     if ('meta' in obj) and self.remove_old_structs:
         del obj['meta']
     for k, v in to_inject.items():
         _add_value_to_dict_bf(obj, k, v)
     for k, v in obj.items():
         if isinstance(v, dict):
             self._recursive_convert_dict(v)
         elif isinstance(v, list):
             self._recursive_convert_list(v)