Project

General

Profile

« Previous | Next » 

Revision 1577

xpath.py: Added append() to recursively append subpath to every leaf of a path tree. parse(): Use append() to fix bug in split path parsing where subpath was not added to every leaf of the tree, only the main leaf of the main branch and the main leaves of the other branches of the last element.

View differences:

lib/xpath.py
61 61
    path[-1] = copy.copy(path[-1]) # don't modify other copies of the path
62 62
    path[-1].value = value
63 63

  
64
def append(path, subpath, i=0):
65
    '''Recursively appends subpath to every leaf of a path tree'''
66
    if i >= len(path): path += subpath
67
    else:
68
        append(path, subpath, i+1)
69
        for branch in path[i].other_branches: append(branch, subpath)
70

  
64 71
def backward_id(elem):
65 72
    if len(elem.keys) >= 1 and value(elem.keys[0]) == None: return elem.keys[0]
66 73
    else: return None
......
115 122
                try: last = tree[-1]
116 123
                except IndexError: parser.syntax_err('./{')
117 124
                last.other_branches = _paths()
125
                tree += last.other_branches.pop(0) # use first path for now
118 126
                parser.str_('}', required=True)
119
                if parser.str_('/'): # common subpath after {}
120
                    subpath = _path()
121
                    for branch in last.other_branches: branch += subpath
122
                tree += last.other_branches.pop(0) # use first path for now
127
                if parser.str_('/'): append(tree, _path()) # subpath after {}
123 128
                break # anything after split path has already been parsed
124 129
            
125 130
            elem = XpathElem(is_attr=parser.str_('@'), name=_value())

Also available in: Unified diff