Revision 97
Added by Aaron Marcuse-Kubitza about 13 years ago
scripts/lib/xpath.py | ||
---|---|---|
10 | 10 |
self.name = name |
11 | 11 |
self.value = value |
12 | 12 |
self.is_attr = is_attr |
13 |
self.is_positive = True |
|
13 | 14 |
self.is_ptr = False |
14 | 15 |
self.keys = [] |
15 | 16 |
self.attrs = [] |
... | ... | |
17 | 18 |
|
18 | 19 |
def __repr__(self): |
19 | 20 |
str_ = '' |
21 |
if self.is_positive: str_ += '!' |
|
20 | 22 |
if self.is_attr: str_ += '@' |
21 | 23 |
str_ += self.name |
22 | 24 |
if self.keys != []: str_ += repr(self.keys) |
... | ... | |
41 | 43 |
parser = Parser(str_) |
42 | 44 |
|
43 | 45 |
def _path(): |
46 |
is_positive = not parser.str_('!') |
|
47 |
|
|
44 | 48 |
tree = [] |
45 | 49 |
while True: |
46 | 50 |
# Split path |
... | ... | |
77 | 81 |
|
78 | 82 |
if not parser.str_('/'): break |
79 | 83 |
|
84 |
tree[0].is_positive = is_positive |
|
85 |
|
|
86 |
# Value |
|
80 | 87 |
if parser.str_('='): |
81 | 88 |
if parser.str_('"'): |
82 | 89 |
value = parser.re(r'[^"]*') |
... | ... | |
148 | 155 |
is_match = elem.value == None or xml_dom.value(child) == elem.value |
149 | 156 |
for attr in elem.keys: |
150 | 157 |
if not is_match: break |
151 |
is_match = get(doc, attr, False, last_only, child) != None |
|
158 |
is_match = (get(doc, attr, False, last_only, child) != None)\ |
|
159 |
== attr[0].is_positive |
|
152 | 160 |
if is_match: node = child; break |
153 | 161 |
|
154 | 162 |
# Create node |
... | ... | |
161 | 169 |
if elem.value != None: xml_dom.set_value(doc, node, elem.value) |
162 | 170 |
if create: |
163 | 171 |
for attr in elem.keys + elem.attrs: |
164 |
get(doc, attr, create, last_only, node) |
|
172 |
if attr[0].is_positive: get(doc, attr, create, last_only, node)
|
|
165 | 173 |
|
166 | 174 |
for branch in elem.other_branches: |
167 | 175 |
branch = copy.deepcopy(branch) |
Also available in: Unified diff
xpath.py: Added support for negative attribute assertions with !