Revision 3747
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/strings.py | ||
---|---|---|
68 | 68 |
if not util.is_str(val): val = str(val) |
69 | 69 |
return to_unicode(val) |
70 | 70 |
|
71 |
def urepr(value): |
|
72 |
'''Like built-in repr() but converts to unicode object''' |
|
73 |
if hasattr(value, '__repr__'): str_ = value.__repr__() |
|
74 |
else: str_ = repr(value) |
|
75 |
return to_unicode(str_) |
|
76 |
|
|
71 | 77 |
def repr_no_u(value): |
72 | 78 |
'''Like built-in repr() but removes the "u" in `u'...'`''' |
73 |
return re.sub(r"^u(?=')", r'', repr(value)) |
|
79 |
return re.sub(r"^u(?=')", r'', urepr(value))
|
|
74 | 80 |
|
75 | 81 |
##### Line endings |
76 | 82 |
|
Also available in: Unified diff
strings.py: Added urepr() and use it in repr_no_u(), to better support repr() return values with non-ASCII characters. Avoiding repr() also provides a more complete stack trace in the case of such errors.