Read a pickle from stdin and pickle it back to stdout
(stream_in=None, stream_out=None, protocol=None)
| 105 | |
| 106 | |
| 107 | def pickle_echo(stream_in=None, stream_out=None, protocol=None): |
| 108 | """Read a pickle from stdin and pickle it back to stdout""" |
| 109 | if stream_in is None: |
| 110 | stream_in = sys.stdin |
| 111 | if stream_out is None: |
| 112 | stream_out = sys.stdout |
| 113 | |
| 114 | # Force the use of bytes streams under Python 3 |
| 115 | if hasattr(stream_in, "buffer"): |
| 116 | stream_in = stream_in.buffer |
| 117 | if hasattr(stream_out, "buffer"): |
| 118 | stream_out = stream_out.buffer |
| 119 | |
| 120 | input_bytes = _read_all_bytes(stream_in) |
| 121 | stream_in.close() |
| 122 | obj = loads(input_bytes) |
| 123 | repickled_bytes = dumps(obj, protocol=protocol) |
| 124 | stream_out.write(repickled_bytes) |
| 125 | stream_out.close() |
| 126 | |
| 127 | |
| 128 | def call_func(payload, protocol): |
no test coverage detected
searching dependent graphs…