Revision 4041
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/xml_func.py | ||
---|---|---|
74 | 74 |
|
75 | 75 |
def is_xml_func(node): return is_xml_func_name(node.tagName) |
76 | 76 |
|
77 |
def simplify(node): |
|
78 |
'''Simplifies the XML functions in an XML tree. |
|
79 |
* Merges nodes tagged as mergable |
|
80 |
* Applies a pass-through optimization for aggregating functions with one arg |
|
81 |
''' |
|
82 |
for child in xml_dom.NodeElemIter(node): simplify(child) |
|
83 |
merge_tagged(node) |
|
84 |
|
|
85 |
name = node.tagName |
|
86 |
if not is_func_name(name): return # not a function |
|
87 |
|
|
88 |
items = list(xml_dom.NodeElemIter(node)) |
|
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 |
|
93 |
|
|
77 | 94 |
def process(node, on_error=exc.reraise, is_rel_func=None, db=None): |
78 | 95 |
'''Evaluates the XML functions in an XML tree. |
79 | 96 |
@param is_rel_func None|f(str) Tests if a name is a relational function. |
Also available in: Unified diff
xml_func.py: Added simplify()