Project

General

Profile

« Previous | Next » 

Revision 26

In data2xml, fixed pointer handling to deal with pointer targets that are themselves pointers

View differences:

xpath.py
82 82
    
83 83
    def _value(self): return self._match_re(r'[\w.|]+', required=True)
84 84

  
85
types_id_level = 1
85
instance_level = 1
86 86

  
87
def obj(path):
88
    obj_path = deepcopy(path[:instance_level+1])
89
    obj_path[-1].is_ptr = False # prevent pointer w/o target
90
    return obj_path
91

  
87 92
def set_id(path, id_, has_types=True):
88
    if has_types: id_level = types_id_level
93
    if has_types: id_level = instance_level
89 94
    else: id_level = 0
90 95
    path[id_level].attrs.append([XpathElem('id', id_, is_attr=True)])
91 96

  
......
125 130
        # Follow pointer
126 131
        if elem.is_ptr:
127 132
            path = deepcopy(path[elem_idx+1:]) # rest of path
128
            attrs = path[types_id_level].attrs
133
            attrs = path[instance_level].attrs
129 134
            if len(attrs) >= 1 and value(attrs[0]) == None:
130 135
                # backward (child-to-parent) pointer with target ID attr
131 136
                set_value(attrs[0], xml_util.get_id(node))
132 137
            else: # forward (parent-to-child) pointer
133 138
                id_ = xml_util.value(node)
134
                obj_path = path[:types_id_level+1] # target object
139
                obj_path = obj(path) # target object
135 140
                if id_ == None or get(doc, obj_path, False, True) == None:
136 141
                    # no target or target attrs don't match
137 142
                    if not create: return None
138 143
                    
139 144
                    # Use last target object's ID + 1
140
                    last_path = deepcopy(obj_path)
141
                    last_path[-1].attrs = [] # just get by tag name
142
                    last = get(doc, last_path, False, True)
145
                    obj_path[-1].attrs = [] # just get by tag name
146
                    last = get(doc, obj_path, False, True)
143 147
                    if last != None: id_ = str(int(xml_util.get_id(last)) + 1)
144 148
                    else: id_ = '0'
145 149
                    

Also available in: Unified diff