Revision 4491
Added by Aaron Marcuse-Kubitza about 12 years ago
map | ||
---|---|---|
271 | 271 |
in_, out = mapping |
272 | 272 |
# All put_obj()s should return the same id_node |
273 | 273 |
nodes, id_node = xpath.put_obj(root, out, '-1', has_types, |
274 |
'$'+str(in_)) # value is placeholder that documents name |
|
274 |
'$'+strings.ustr(in_)) |
|
275 |
# value is placeholder that documents name |
|
275 | 276 |
mappings[i] = [in_, nodes] |
276 | 277 |
if id_node == None: |
277 | 278 |
warnings.warn(UserWarning('Map warning: No mappings')) |
278 | 279 |
xml_func.simplify(root) |
279 |
sys.stdout.write('Put template:\n'+str(root)) |
|
280 |
sys.stdout.write(strings.to_raw_str('Put template:\n' |
|
281 |
+strings.ustr(root))) |
|
280 | 282 |
sys.stdout.flush() |
281 | 283 |
|
282 | 284 |
def process_row(row, i): |
283 | 285 |
row_id = str(i) |
284 | 286 |
if id_node != None: xml_dom.set_value(id_node, row_id) |
285 | 287 |
for in_, out in mappings: |
286 |
log_debug('Getting '+str(in_)) |
|
288 |
log_debug('Getting '+strings.ustr(in_))
|
|
287 | 289 |
value = metadata_value(in_) |
288 | 290 |
if value == None: value = cleanup(get_value(in_, row)) |
289 |
log_debug('Putting '+repr(value)+' to '+str(out)) |
|
291 |
log_debug('Putting '+repr(value)+' to '+strings.ustr(out))
|
|
290 | 292 |
if out_is_db: # out is list of XML nodes |
291 | 293 |
for node in out: xml_dom.set_value(node, value) |
292 | 294 |
elif value != None: # out is XPath |
... | ... | |
349 | 351 |
|
350 | 352 |
# Strip XML functions not in the DB |
351 | 353 |
xml_func.process(root, is_rel_func=is_rel_func) |
352 |
if debug: log_debug('Putting stripped:\n'+str(root)) |
|
354 |
if debug: log_debug('Putting stripped:\n'+strings.ustr(root))
|
|
353 | 355 |
# only calc if debug |
354 | 356 |
|
355 | 357 |
# Import rows |
... | ... | |
421 | 423 |
if row_str_[0] == None: |
422 | 424 |
# Row # is interally 0-based, but 1-based to the user |
423 | 425 |
row_str_[0] = (term.emph('row #:')+' '+str(row_num+1) |
424 |
+'\n'+term.emph('input row:')+'\n'+str(input_row)) |
|
426 |
+'\n'+term.emph('input row:')+'\n' |
|
427 |
+strings.ustr(input_row)) |
|
425 | 428 |
if verbose_errors: row_str_[0] += ('\n' |
426 |
+term.emph('output row:')+'\n'+str(root)) |
|
429 |
+term.emph('output row:')+'\n'+strings.ustr(root))
|
|
427 | 430 |
return row_str_[0] |
428 | 431 |
|
429 | 432 |
if debug: log_debug(row_str()) # only calc if debug |
... | ... | |
435 | 438 |
|
436 | 439 |
row_root = root.cloneNode(True) # deep copy so don't modify root |
437 | 440 |
xml_func.process(row_root, on_error, is_rel_func, out_db) |
438 |
if debug: log_debug('Putting processed:\n'+str(row_root))
|
|
439 |
# only calc if debug |
|
441 |
if debug: log_debug('Putting processed:\n' |
|
442 |
+strings.ustr(row_root)) # only calc if debug
|
|
440 | 443 |
if not xml_dom.is_empty(row_root): |
441 | 444 |
assert xml_dom.has_one_child(row_root) |
442 | 445 |
try: |
... | ... | |
475 | 478 |
|
476 | 479 |
def main(): |
477 | 480 |
try: main_() |
478 |
except Parser.SyntaxError, e: raise SystemExit(str(e)) |
|
481 |
except Parser.SyntaxError, e: raise SystemExit(strings.ustr(e))
|
|
479 | 482 |
|
480 | 483 |
if __name__ == '__main__': |
481 | 484 |
profile_to = opts.get_env_var('profile_to', None) |
Also available in: Unified diff
Replaced str() with strings.ustr() (or equivalent) everywhere needed, to avoid future UnicodeEncodeErrors