root/lib/strings.py @ 570
1 |
# String manipulation
|
---|---|
2 |
|
3 |
def to_unicode(str_): |
4 |
if isinstance(str_, unicode): return str_ |
5 |
encodings = ['utf_8', 'latin_1'] |
6 |
for encoding in encodings: |
7 |
try: return unicode(str_, encoding) |
8 |
except UnicodeDecodeError, e: pass |
9 |
raise AssertionError(encoding+' is not a catch-all encoding') |
10 |
|
11 |
def ensure_newl(str_): return str_.rstrip()+'\n' |