Converts a string argument to a byte string
(value, encoding="utf8")
| 611 | |
| 612 | |
| 613 | def to_bytestring(value, encoding="utf8"): |
| 614 | """Converts a string argument to a byte string""" |
| 615 | if isinstance(value, bytes): |
| 616 | return value |
| 617 | if not isinstance(value, str): |
| 618 | raise TypeError('%r is not a string' % value) |
| 619 | |
| 620 | return value.encode(encoding) |
| 621 | |
| 622 | |
| 623 | def has_fileno(obj): |