(st, encoding="utf-8")
| 59 | if PY2: |
| 60 | |
| 61 | def to_bytes(st, encoding="utf-8"): |
| 62 | # type: (AnyStr, Text) -> bytes |
| 63 | if isinstance(st, unicode): |
| 64 | return st.encode(encoding) |
| 65 | elif isinstance(st, (str, bytes)): |
| 66 | return st |
| 67 | else: |
| 68 | raise ValueError("Cannot convert %s to bytes" % type(st)) |
| 69 | |
| 70 | def to_unicode(st, encoding="utf-8"): |
| 71 | # type: (AnyStr, Text) -> Text |