Returns the given string as a unicode string (if possible).
(string)
| 32 | #### STRING FUNCTIONS ############################################################################## |
| 33 | |
| 34 | def decode_utf8(string): |
| 35 | """ Returns the given string as a unicode string (if possible). |
| 36 | """ |
| 37 | if isinstance(string, str): |
| 38 | for encoding in (("utf-8",), ("windows-1252",), ("utf-8", "ignore")): |
| 39 | try: |
| 40 | return string.decode(*encoding) |
| 41 | except: |
| 42 | pass |
| 43 | return string |
| 44 | return unicode(string) |
| 45 | |
| 46 | def encode_utf8(string): |
| 47 | """ Returns the given string as a Python byte string (if possible). |
no test coverage detected
searching dependent graphs…