Revision 2105
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/xml_func.py | ||
---|---|---|
10 | 10 |
import exc |
11 | 11 |
import format |
12 | 12 |
import maps |
13 |
import sql |
|
13 | 14 |
import strings |
14 | 15 |
import term |
15 | 16 |
import units |
... | ... | |
53 | 54 |
|
54 | 55 |
##### Public functions |
55 | 56 |
|
56 |
def process(node, on_error=exc.raise_): |
|
57 |
def process(node, on_error=exc.raise_, db=None):
|
|
57 | 58 |
for child in xml_dom.NodeElemIter(node): process(child, on_error) |
58 | 59 |
name = node.tagName |
59 |
if name.startswith('_') and name in funcs:
|
|
60 |
if name.startswith('_') and name != '_': # '_' is default root node name
|
|
60 | 61 |
try: |
61 |
value = funcs[name](xml_dom.NodeTextEntryIter(node), node) |
|
62 |
items = xml_dom.NodeTextEntryIter(node) |
|
63 |
try: func = funcs[name] |
|
64 |
except KeyError: |
|
65 |
if db != None: # DB with relational functions available |
|
66 |
value = sql.put(db, name, dict(items)) |
|
67 |
else: value = pop_value(list(items)) # pass value through |
|
68 |
else: value = func(items, node) # local XML function |
|
69 |
|
|
62 | 70 |
xml_dom.replace_with_text(node, value) |
63 | 71 |
except Exception, e: # also catch non-wrapped exceptions (XML func bugs) |
64 | 72 |
# Save in case another exception raised, overwriting sys.exc_info() |
Also available in: Unified diff
xml_func.py: process(): If DB with relational functions available (passed in via db param), call any non-local XML functions as relational funcs