Return a unicode string for a string be it bytes or unicode.
(s)
| 134 | |
| 135 | |
| 136 | def as_unicode(s): |
| 137 | """ |
| 138 | Return a unicode string for a string be it bytes or unicode. |
| 139 | """ |
| 140 | if isinstance(s, str): |
| 141 | return s |
| 142 | if s == b"": |
| 143 | return "" |
| 144 | if not s: |
| 145 | return s |
| 146 | assert isinstance(s, bytes), "s must be bytes but is: {}".format(s) |
| 147 | return UnicodeDammit(s).unicode_markup |
no test coverage detected