Returns the given value as a Unicode string (if possible).
(v, encoding="utf-8")
| 12 | #### UNICODE ####################################################################################### |
| 13 | |
| 14 | def decode_string(v, encoding="utf-8"): |
| 15 | """ Returns the given value as a Unicode string (if possible). |
| 16 | """ |
| 17 | if isinstance(encoding, basestring): |
| 18 | encoding = ((encoding,),) + (("windows-1252",), ("utf-8", "ignore")) |
| 19 | if isinstance(v, str): |
| 20 | for e in encoding: |
| 21 | try: return v.decode(*e) |
| 22 | except: |
| 23 | pass |
| 24 | return v |
| 25 | return unicode(v) |
| 26 | |
| 27 | def encode_string(v, encoding="utf-8"): |
| 28 | """ Returns the given value as a Python byte string (if possible). |
nothing calls this directly
no test coverage detected
searching dependent graphs…