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