Project

General

Profile

« Previous | Next » 

Revision 447

xml_func.py: Use on_error exception handler to allow caller to print exceptions instead of raising them

View differences:

xml_func.py
90 90
funcs = {'_alt': alt, '_range': range_, '_avg': avg, '_date': date,
91 91
    '_name': name, '_namePart': name_part}
92 92

  
93
def process(node):
93
def process(node, on_error=exc.raise_):
94 94
    name = node.tagName
95 95
    if name.startswith('_') and name in funcs:
96 96
        try: value = funcs[name](xml_dom.NodeTextEntryIter(node))
97 97
        except SyntaxException, e:
98
            exc.add_msg(e, 'function:\n'+str(node))
99
            xml_dom.remove(node)
100
            raise
98
            node_str = str(node)
99
            exc.add_msg(e, 'function:\n'+node_str)
100
            xml_dom.replace(node, node.ownerDocument.createComment(node_str))
101
            on_error(e)
101 102
        else: xml_dom.replace_with_text(node, value)
102 103
    else:
103
        for child in xml_dom.NodeElemIter(node): process(child)
104
        for child in xml_dom.NodeElemIter(node): process(child, on_error)

Also available in: Unified diff