Converts bytes into some human-readable representation. Unprintable bytes such as the nul byte are escaped. For example: >>> b = bytes([102, 111, 111, 10, 0]) >>> s = bytes_to_human_readable_repr(b) >>> print(s) foo\n\x00 >>> print(repr(s)) 'foo\\
(b: bytes)
| 138 | |
| 139 | |
| 140 | def bytes_to_human_readable_repr(b: bytes) -> str: |
| 141 | """Converts bytes into some human-readable representation. Unprintable |
| 142 | bytes such as the nul byte are escaped. For example: |
| 143 | |
| 144 | >>> b = bytes([102, 111, 111, 10, 0]) |
| 145 | >>> s = bytes_to_human_readable_repr(b) |
| 146 | >>> print(s) |
| 147 | foo\n\x00 |
| 148 | >>> print(repr(s)) |
| 149 | 'foo\\n\\x00' |
| 150 | """ |
| 151 | return repr(b)[2:-1] |
| 152 | |
| 153 | |
| 154 | class DecodeError(Exception): |
searching dependent graphs…