(x, charset="utf-8", errors="strict")
| 4 | |
| 5 | |
| 6 | def to_bytes(x, charset="utf-8", errors="strict"): |
| 7 | if x is None: |
| 8 | return None |
| 9 | if isinstance(x, bytes): |
| 10 | return x |
| 11 | if isinstance(x, str): |
| 12 | return x.encode(charset, errors) |
| 13 | if isinstance(x, (int, float)): |
| 14 | return str(x).encode(charset, errors) |
| 15 | return bytes(x) |
| 16 | |
| 17 | |
| 18 | def to_unicode(x, charset="utf-8", errors="strict"): |
searching dependent graphs…