Project

General

Profile

« Previous | Next » 

Revision 99

xpath.py: Created is_positive() function

View differences:

xpath.py
30 30
    
31 31
    def __eq__(self, other): return self.__dict__ == other.__dict__
32 32

  
33
def is_positive(path): return path[0].is_positive
34

  
33 35
def value(path): return path[-1].value
34 36

  
35 37
def set_value(path, value): path[-1].value = value
......
138 140
    # into separate nodes
139 141
    if parent == None: parent = doc.documentElement
140 142
    if last_only == None: last_only = create
143
    
144
    if create and not is_positive(xpath): return None
141 145
    for elem_idx, elem in enumerate(xpath):
142 146
        # Find possible matches
143 147
        children = []
......
156 160
            for attr in elem.keys:
157 161
                if not is_match: break
158 162
                is_match = (get(doc, attr, False, last_only, child) != None)\
159
                == attr[0].is_positive
163
                == is_positive(attr)
160 164
            if is_match: node = child; break
161 165
        
162 166
        # Create node
......
169 173
            if elem.value != None: xml_dom.set_value(doc, node, elem.value)
170 174
        if create:
171 175
            for attr in elem.keys + elem.attrs:
172
                if attr[0].is_positive: get(doc, attr, create, last_only, node)
176
                get(doc, attr, create, last_only, node)
173 177
        
174 178
        for branch in elem.other_branches:
175 179
            branch = copy.deepcopy(branch)

Also available in: Unified diff