Revision 4491
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
37 | 37 |
|
38 | 38 |
class ExceptionWithName(DbException): |
39 | 39 |
def __init__(self, name, cause=None): |
40 |
DbException.__init__(self, 'for name: '+strings.as_tt(str(name)), cause) |
|
40 |
DbException.__init__(self, 'for name: ' |
|
41 |
+strings.as_tt(strings.ustr(name)), cause) |
|
41 | 42 |
self.name = name |
42 | 43 |
|
43 | 44 |
class ExceptionWithValue(DbException): |
... | ... | |
48 | 49 |
|
49 | 50 |
class ExceptionWithNameType(DbException): |
50 | 51 |
def __init__(self, type_, name, cause=None): |
51 |
DbException.__init__(self, 'for type: '+strings.as_tt(str(type_))
|
|
52 |
+'; name: '+strings.as_tt(name), cause) |
|
52 |
DbException.__init__(self, 'for type: '+strings.as_tt(strings.ustr(
|
|
53 |
type_))+'; name: '+strings.as_tt(name), cause)
|
|
53 | 54 |
self.type = type_ |
54 | 55 |
self.name = name |
55 | 56 |
|
... | ... | |
387 | 388 |
|
388 | 389 |
## Log or return query |
389 | 390 |
|
390 |
query = str(get_cur_query(cur, query)) |
|
391 |
query = strings.ustr(get_cur_query(cur, query))
|
|
391 | 392 |
# Put the src comment on a separate line in the log file |
392 | 393 |
query = query.replace('\t', '\n', 1) |
393 | 394 |
|
lib/db_xml.py | ||
---|---|---|
65 | 65 |
return put(db, node, row_ins_ct_ref, on_error, col_defaults, in_table, |
66 | 66 |
parent_ids_loc, next) |
67 | 67 |
|
68 |
def augment_error(e): exc.add_msg(e, 'node:\n'+str(node)) |
|
68 |
def augment_error(e): exc.add_msg(e, 'node:\n'+strings.ustr(node))
|
|
69 | 69 |
def on_error_(e): |
70 | 70 |
augment_error(e) |
71 | 71 |
on_error(e) |
... | ... | |
193 | 193 |
in_table = sql_gen.as_Table(in_table) |
194 | 194 |
sql_io.mk_errors_table(db, in_table) |
195 | 195 |
in_table.set_srcs([in_table], overwrite=False) |
196 |
db.src = str(in_table) |
|
196 |
db.src = strings.ustr(in_table)
|
|
197 | 197 |
|
198 | 198 |
db.autoanalyze = True # but don't do this in row-based import |
199 | 199 |
db.autoexplain = True # but don't do this in row-based import |
... | ... | |
213 | 213 |
|
214 | 214 |
# Subset in_table |
215 | 215 |
in_table = copy.copy(full_in_table) # don't modify input! |
216 |
in_table.name = str(in_table) # prepend schema |
|
216 |
in_table.name = strings.ustr(in_table) # prepend schema
|
|
217 | 217 |
cur = sql.run_query_into(db, sql.mk_select(db, full_in_table, |
218 | 218 |
limit=this_limit, start=start), into=in_table, add_pkey_=True) |
219 | 219 |
# full_in_table will be shadowed (hidden) by created temp table |
lib/util.py | ||
---|---|---|
4 | 4 |
|
5 | 5 |
import dicts |
6 | 6 |
import objects |
7 |
import strings |
|
7 | 8 |
|
8 | 9 |
#### Function wrappers for statements |
9 | 10 |
|
... | ... | |
25 | 26 |
|
26 | 27 |
class ConstraintError(ValueError): |
27 | 28 |
def __init__(self, check_func, value): |
28 |
ValueError.__init__(self, str(value)+' must satisfy constraint '
|
|
29 |
+check_func.__name__) |
|
29 |
ValueError.__init__(self, strings.ustr(value)
|
|
30 |
+' must satisfy constraint '+check_func.__name__)
|
|
30 | 31 |
|
31 | 32 |
def cast(type_, val): |
32 | 33 |
'''Passes None through. Does not cast a subclass to a superclass (which |
... | ... | |
223 | 224 |
|
224 | 225 |
def __getitem__(self, key): return self.list[self.key_idxs[key]] |
225 | 226 |
|
226 |
def __str__(self): return '{\n'+(''.join(str(k)+': '+str(v)+'\n'
|
|
227 |
for k, v in zip(self.keys, self.list)))+'}\n' |
|
227 |
def __str__(self): return '{\n'+(''.join(strings.ustr(k)+': '
|
|
228 |
+strings.ustr(v)+'\n' for k, v in zip(self.keys, self.list)))+'}\n'
|
|
228 | 229 |
|
229 | 230 |
#### Named tuples |
230 | 231 |
|
lib/exc.py | ||
---|---|---|
40 | 40 |
return ''.join(get_traceback_str(t) for t in tracebacks) |
41 | 41 |
|
42 | 42 |
def e_msg(e): |
43 |
if len(e.args) == 0: return str(e) |
|
43 |
if len(e.args) == 0: return strings.ustr(e)
|
|
44 | 44 |
assert util.is_str(e.args[0]) |
45 | 45 |
return strings.ustr(e.args[0]).rstrip() |
46 | 46 |
|
lib/xpath.py | ||
---|---|---|
257 | 257 |
if target != None: value_ = xml_dom.value(target) |
258 | 258 |
else: |
259 | 259 |
warnings.warn(UserWarning('XPath reference target missing: ' |
260 |
+str(value_)+'\nXPath: '+str(xpath)))
|
|
260 |
+strings.ustr(value_)+'\nXPath: '+strings.ustr(xpath)))
|
|
261 | 261 |
value_ = None |
262 | 262 |
|
263 | 263 |
# Check each match |
lib/objects.py | ||
---|---|---|
7 | 7 |
|
8 | 8 |
def __str__(self): return util.class_name(self)+repr(self.__dict__) |
9 | 9 |
|
10 |
def __repr__(self): return str(self)
|
|
10 |
def __repr__(self): return self.__str__()
|
|
11 | 11 |
|
12 | 12 |
def __eq__(self, other): |
13 | 13 |
return (other != None and other.__class__ == self.__class__ |
lib/xml_dom.py | ||
---|---|---|
73 | 73 |
|
74 | 74 |
def only_child(node): |
75 | 75 |
if not has_one_child(node): |
76 |
raise Exception('Must contain only one child:\n'+str(node)) |
|
76 |
raise Exception('Must contain only one child:\n'+strings.ustr(node))
|
|
77 | 77 |
return node.firstChild |
78 | 78 |
|
79 | 79 |
def is_simple(node): |
... | ... | |
367 | 367 |
def __Element_write_opening(self, writer, indent='', addindent='', newl=''): |
368 | 368 |
writer.write(indent+'<'+escape(self.tagName)) |
369 | 369 |
for attr_idx in xrange(self.attributes.length): |
370 |
writer.write(' '+str(self.attributes.item(attr_idx))) |
|
370 |
writer.write(' '+strings.ustr(self.attributes.item(attr_idx)))
|
|
371 | 371 |
writer.write('>'+newl) |
372 | 372 |
minidom.Element.write_opening = __Element_write_opening |
373 | 373 |
|
lib/sql_io.py | ||
---|---|---|
238 | 238 |
elif is_func_result(in_col): in_col = table # omit col name |
239 | 239 |
return strings.ustr(in_col) |
240 | 240 |
|
241 |
str_ = str(out_table) |
|
241 |
str_ = strings.ustr(out_table)
|
|
242 | 242 |
if is_func: |
243 | 243 |
str_ += '(' |
244 | 244 |
|
245 | 245 |
try: value_in_col = mapping['value'] |
246 | 246 |
except KeyError: |
247 |
str_ += ', '.join((str(k)+'='+in_col_str(v) |
|
247 |
str_ += ', '.join((strings.ustr(k)+'='+in_col_str(v)
|
|
248 | 248 |
for k, v in mapping.iteritems())) |
249 | 249 |
else: str_ += in_col_str(value_in_col) |
250 | 250 |
|
... | ... | |
254 | 254 |
try: in_col = mapping[out_col] |
255 | 255 |
except KeyError: str_ += '_pkeys' |
256 | 256 |
else: # has a rank column, so hierarchical |
257 |
str_ += '['+str(out_col)+'='+in_col_str(in_col)+']' |
|
257 |
str_ += '['+strings.ustr(out_col)+'='+in_col_str(in_col)+']'
|
|
258 | 258 |
return str_ |
259 | 259 |
|
260 | 260 |
def put_table(db, out_table, in_tables, mapping, row_ct_ref=None, default=None, |
bin/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