Revision 1232
Added by Aaron Marcuse-Kubitza almost 13 years ago
strings.py | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import re |
4 | 4 |
|
5 |
import util |
|
6 |
|
|
5 | 7 |
def to_unicode(str_): |
6 | 8 |
if isinstance(str_, unicode): return str_ |
7 | 9 |
encodings = ['utf_8', 'latin_1'] |
... | ... | |
10 | 12 |
except UnicodeDecodeError, e: pass |
11 | 13 |
raise AssertionError(encoding+' is not a catch-all encoding') |
12 | 14 |
|
15 |
def ustr(val): |
|
16 |
'''Like built-in str() but converts to unicode object''' |
|
17 |
if not util.is_str(val): val = str(val) |
|
18 |
return to_unicode(val) |
|
19 |
|
|
13 | 20 |
def ensure_newl(str_): return str_.rstrip()+'\n' |
14 | 21 |
|
15 | 22 |
def is_multiline(str_): |
Also available in: Unified diff
strings.py: Added ustr() (like built-in str() but converts to unicode object)