Project

General

Profile

« Previous | Next » 

Revision 171

xpath.py: Changed backward (child-to-parent) pointer ID abbr expansion to happen in get() when source node's tag name is known. This deals with XPath elements that are '.' being used as a pointer source.

View differences:

scripts/lib/xpath.py
38 38
def set_value(path, value): path[-1].value = value
39 39

  
40 40
def backward_id(elem):
41
    if len(elem.keys) >= 1 and value(elem.keys[0]) == None and\
42
    len(elem.keys[0]) == 1: return elem.keys[0]
41
    if len(elem.keys) >= 1 and value(elem.keys[0]) == None: return elem.keys[0]
43 42
    else: return None
44 43

  
45 44
def expand_abbr(name, repl):
......
107 106
        # Expand * abbrs
108 107
        for i in reversed(xrange(len(tree))):
109 108
            elem = tree[i]
110
            id_ = backward_id(elem)
111
            if id_ != None: elem = id_[0]; offset = -2
112
            elif elem.is_ptr: offset = 2
109
            if elem.is_ptr: offset = 2
113 110
            else: offset = 1
114
            before, abbr, after = elem.name.partition('*')
115 111
            try: repl = tree[i+offset].name
116
            except IndexError: continue # no replacement elem
117
            elem.name = expand_abbr(elem.name, repl)
112
            except IndexError: pass # no replacement elem
113
            else: elem.name = expand_abbr(elem.name, repl)
118 114
        
119 115
        return tree
120 116
    
......
195 191
    # Follow pointer
196 192
    if elem.is_ptr:
197 193
        xpath = copy.deepcopy(xpath)
198
        id_elem = backward_id(xpath[instance_level])
199
        if id_elem != None:
200
            # backward (child-to-parent) pointer with target ID attr
201
            set_value(id_elem, xml_dom.get_id(node))
194
        id_path = backward_id(xpath[instance_level])
195
        if id_path != None: # backward (child-to-parent) pointer with ID key
196
            id_path[0].name = expand_abbr(id_path[0].name, node.tagName)
197
            set_value(id_path, xml_dom.get_id(node)) # modify id key of xpath
202 198
        else: # forward (parent-to-child) pointer
203 199
            id_ = xml_dom.value(node)
204 200
            obj_xpath = obj(xpath) # target object

Also available in: Unified diff