Revision 1681
Added by Aaron Marcuse-Kubitza almost 13 years ago
bin/map | ||
---|---|---|
27 | 27 |
def get_with_prefix(map_, prefixes, key): |
28 | 28 |
'''Gets all entries for the given key with any of the given prefixes''' |
29 | 29 |
values = [] |
30 |
for prefix in ['']+prefixes: # also lookup with no prefix
|
|
31 |
try: value = map_[prefix+key]
|
|
30 |
for key_ in strings.with_prefixes(['']+prefixes, key): # also with no prefix
|
|
31 |
try: value = map_[key_]
|
|
32 | 32 |
except KeyError, e: continue # keep going |
33 | 33 |
values.append(value) |
34 | 34 |
|
... | ... | |
226 | 226 |
|
227 | 227 |
in_db.close() |
228 | 228 |
elif in_is_xml: |
229 |
if prefixes != []: prefix = './{'+(','.join(['.']+prefixes))+'}/' |
|
230 |
# also lookup with no prefix |
|
231 |
else: prefix = '' |
|
232 |
|
|
233 | 229 |
rows = xpath.get(doc0_root, in_root, limit=end) |
234 | 230 |
if rows == []: raise SystemExit('Map error: Root "'+in_root |
235 | 231 |
+'" not found in input') |
232 |
|
|
236 | 233 |
def get_value(in_, row): |
237 |
nodes = xpath.get(row, prefix+in_, allow_rooted=False) |
|
234 |
in_ = './{'+(','.join(strings.with_prefixes(['']+prefixes, |
|
235 |
in_)))+'}' # also with no prefix |
|
236 |
nodes = xpath.get(row, in_, allow_rooted=False) |
|
238 | 237 |
if nodes != []: return xml_dom.value(nodes[0]) |
239 | 238 |
else: return None |
239 |
|
|
240 | 240 |
row_ct = map_rows(get_value, rows) |
241 | 241 |
else: # input is CSV |
242 | 242 |
map_ = dict(mappings) |
Also available in: Unified diff
bin/map: Changed XML input prefix handling to prepend prefix directly to XPath instead of separating it from the XPath with a "/". Changed get_with_prefix() to use new strings.with_prefixes().