Convert data to a (utf-8 encoded) byte-string if it isn't a byte-string already.
(data)
| 392 | |
| 393 | |
| 394 | def to_bytestring(data): |
| 395 | """ |
| 396 | Convert data to a (utf-8 encoded) byte-string if it isn't a byte-string |
| 397 | already. |
| 398 | """ |
| 399 | if not isinstance(data, bytes): |
| 400 | data = str(data).encode("utf-8") |
| 401 | return data |
| 402 | |
| 403 | |
| 404 | def optimal_mode(data): |
no outgoing calls
no test coverage detected