Revision 4078
Added by Aaron Marcuse-Kubitza over 12 years ago
xml_func.py | ||
---|---|---|
77 | 77 |
def simplify(node): |
78 | 78 |
'''Simplifies the XML functions in an XML tree. |
79 | 79 |
* Merges nodes tagged as mergable |
80 |
* Applies a pass-through optimization for aggregating functions with one arg
|
|
80 |
* Applies pass-through optimizations for XML functions
|
|
81 | 81 |
''' |
82 | 82 |
for child in xml_dom.NodeElemIter(node): simplify(child) |
83 | 83 |
merge_tagged(node) |
84 | 84 |
|
85 |
name = node.tagName |
|
86 |
if not is_func_name(name): return # not a function |
|
85 |
func_name = node.tagName
|
|
86 |
if not is_func_name(func_name): return # not a function
|
|
87 | 87 |
|
88 |
items = list(xml_dom.NodeElemIter(node))
|
|
88 |
params = list(xml_dom.NodeElemIter(node))
|
|
89 | 89 |
|
90 |
if len(items) == 1 and items[0].tagName.isdigit(): # single numeric param |
|
91 |
# pass-through optimization for aggregating functions with one arg |
|
92 |
xml_dom.replace(node, items[0].firstChild) # use first arg's value |
|
90 |
# Pass-through optimizations |
|
91 |
if len(params) == 1: # single arg |
|
92 |
param = params[0] |
|
93 |
name = param.tagName |
|
94 |
value = param.firstChild |
|
95 |
|
|
96 |
is_agg_func = name.isdigit() |
|
97 |
is_if_no_cond = func_name = '_if' # no if condition means False |
|
98 |
if is_agg_func or (is_if_no_cond and name == 'else'): |
|
99 |
xml_dom.replace(node, value) |
|
100 |
elif is_if_no_cond and name == 'then': xml_dom.remove(node) |
|
93 | 101 |
|
94 | 102 |
def process(node, on_error=exc.reraise, is_rel_func=None, db=None): |
95 | 103 |
'''Evaluates the XML functions in an XML tree. |
Also available in: Unified diff
xml_func.py: simplify(): Apply pass-through optimizations for _if statements with no condition (which means false). This faciliates automated testing after an _if statement has been added, because the put template provided as part of the automated test will only change for those datasources that actually have a condition entry for the _if statement, which greatly reduces the number of tests that need to be accepted. (Note that the path before the _if will still be included as an empty path if there are no other mappings to that table, because the _if statement does not surround it.)