Forward bytes from a subprocess call to the console, without attempting to decode them. The assumption is that the subprocess call already returned bytes in a suitable encoding.
(val)
| 78 | |
| 79 | |
| 80 | def forward_bytes_to_stdout(val): |
| 81 | """ |
| 82 | Forward bytes from a subprocess call to the console, without attempting to |
| 83 | decode them. |
| 84 | |
| 85 | The assumption is that the subprocess call already returned bytes in |
| 86 | a suitable encoding. |
| 87 | """ |
| 88 | if hasattr(sys.stdout, 'buffer'): |
| 89 | # use the underlying binary output if there is one |
| 90 | sys.stdout.buffer.write(val) |
| 91 | elif hasattr(sys.stdout, 'encoding'): |
| 92 | # round-trip the encoding if necessary |
| 93 | sys.stdout.write(val.decode(sys.stdout.encoding)) |
| 94 | else: |
| 95 | # make a best-guess at the encoding |
| 96 | sys.stdout.write(val.decode('utf8', errors='replace')) |
| 97 | |
| 98 | |
| 99 | def temp_file_name(): |
no test coverage detected