Revision 280
Added by Aaron Marcuse-Kubitza about 13 years ago
xml_func.py | ||
---|---|---|
5 | 5 |
import ex |
6 | 6 |
import xml_dom |
7 | 7 |
|
8 |
class SyntaxException(ex.ExceptionWithCause): pass |
|
8 |
class SyntaxException(Exception): |
|
9 |
def __init__(self, cause=None): |
|
10 |
Exception.__init__(self, 'Invalid syntax in XML function %(func)s: '+ |
|
11 |
str(cause)) |
|
9 | 12 |
|
10 | 13 |
def map_items(func, items): |
11 | 14 |
return [(name, func(value)) for name, value in items] |
... | ... | |
65 | 68 |
|
66 | 69 |
def process(node): |
67 | 70 |
name = node.tagName |
68 |
if name.startswith('_') and name in funcs: xml_dom.replace_with_text(node, |
|
69 |
funcs[name](xml_dom.NodeTextEntryIter(node))) |
|
71 |
if name.startswith('_') and name in funcs: |
|
72 |
try: value = funcs[name](xml_dom.NodeTextEntryIter(node)) |
|
73 |
except SyntaxException, e: ex.repl_msg(e, {'func': name}); raise |
|
74 |
else: xml_dom.replace_with_text(node, value) |
|
70 | 75 |
else: |
71 | 76 |
for child in xml_dom.NodeElemIter(node): process(child) |
Also available in: Unified diff
xml_func.py: Add function name to SyntaxException message