Closed soxofaan closed 4 years ago
oh wait, this will probably not work under python 2. So version sniffing will be necessary unfortunately
I force-pushed a reworked version that re-introduces the version sniffing to make sure things keep working under python 2.
Note that under python 2, even though the object looks like <open file '<stdin>', mode 'r' at 0x10dd440c0>
, the data read from it return as str
but that is equivalent with bytes from Python 3.
quick experiment about python 2 and 3 handling binary data on stdin:
$ head -c 10 /bin/ls | python2 -c "import sys; x=sys.stdin.read(); print type(x), repr(x)"
<type 'str'> '\xcf\xfa\xed\xfe\x07\x00\x00\x01\x03\x00'
$ head -c 10 /bin/ls | python3 -c "import sys; x=sys.stdin.buffer.read(); print(type(x), repr(x))"
<class 'bytes'> b'\xcf\xfa\xed\xfe\x07\x00\x00\x01\x03\x00'
Thank you. I appreciate the investigation and comment referencing the upstream bug, and the explicit check against file_obj.mode
. For this reason I prefer this over #75, but thank you also to @cnjr2 for finding the original workaround.
An alternative solution for #74 that does not require version sniffing like #75