Converts `text` to Unicode (if it's not already), assuming utf-8 input.
(text)
| 78 | |
| 79 | |
| 80 | def convert_to_unicode(text): |
| 81 | """Converts `text` to Unicode (if it's not already), assuming utf-8 input.""" |
| 82 | if six.PY3: |
| 83 | if isinstance(text, str): |
| 84 | return text |
| 85 | elif isinstance(text, bytes): |
| 86 | return text.decode("utf-8", "ignore") |
| 87 | else: |
| 88 | raise ValueError("Unsupported string type: %s" % (type(text))) |
| 89 | elif six.PY2: |
| 90 | if isinstance(text, str): |
| 91 | return text.decode("utf-8", "ignore") |
| 92 | elif isinstance(text, unicode): |
| 93 | return text |
| 94 | else: |
| 95 | raise ValueError("Unsupported string type: %s" % (type(text))) |
| 96 | else: |
| 97 | raise ValueError("Not running on Python2 or Python 3?") |
| 98 | |
| 99 | |
| 100 | def printable_text(text): |
no test coverage detected