Revision 3748
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/strings.py | ||
---|---|---|
63 | 63 |
except UnicodeDecodeError, e: pass |
64 | 64 |
raise AssertionError(encoding+' is not a catch-all encoding') |
65 | 65 |
|
66 |
def ustr(val): |
|
66 |
def ustr(value):
|
|
67 | 67 |
'''Like built-in str() but converts to unicode object''' |
68 |
if not util.is_str(val): val = str(val) |
|
69 |
return to_unicode(val) |
|
68 |
if util.is_str(value): str_ = value # already a string |
|
69 |
elif hasattr(value, '__str__'): str_ = value.__str__() |
|
70 |
else: str_ = str(value) |
|
71 |
return to_unicode(str_) |
|
70 | 72 |
|
71 | 73 |
def urepr(value): |
72 | 74 |
'''Like built-in repr() but converts to unicode object''' |
Also available in: Unified diff
strings.py: ustr(): Call str() method manually like urepr() to avoid Unicode errors when the returning string is non-ASCII