Skip to content

Commit

Permalink
bugfix where python3 woudln't accept binary stdin
Browse files Browse the repository at this point in the history
closes #325
  • Loading branch information
Andrew Moffat committed Oct 6, 2016
1 parent 9a8e28f commit 1460f6e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.2 -

* bugfix for python3+ where binary data was passed into a process's stdin [#325](https://github.com/amoffat/sh/issues/325)
* Introduced execution contexts which allow baking of common special keyword arguments into all commands [#269](https://github.com/amoffat/sh/issues/269)
* `Command` and `which` now can take an optional `paths` parameter which specifies the search paths [#226](https://github.com/amoffat/sh/issues/226)
* `_preexec_fn` option for executing a function after the child process forks but before it execs [#260](https://github.com/amoffat/sh/issues/260)
Expand Down
4 changes: 4 additions & 0 deletions sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1725,6 +1725,10 @@ def determine_how_to_read_input(input_obj):
log_msg = "string"
get_chunk = get_iter_string_reader(input_obj)

elif isinstance(input_obj, bytes):
log_msg = "bytes"
get_chunk = get_iter_string_reader(input_obj)

else:
log_msg = "general iterable"
get_chunk = get_iter_chunk_reader(iter(input_obj))
Expand Down
12 changes: 11 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,16 @@ def test_with_context_args(self):
self.assertTrue(out == "")


def test_binary_input(self):
py = create_tmp_test("""
import sys
data = sys.stdin.read()
sys.stdout.write(data)
""")
data = b'1234'
out = python(py.name, _in=data)
self.assertEqual(out, "1234")


def test_err_to_out(self):
py = create_tmp_test("""
Expand All @@ -652,7 +662,7 @@ def test_err_to_out(self):
sys.stderr.flush()
""")
stdout = python(py.name, _err_to_out=True)
self.assertTrue(stdout == "stdoutstderr")
self.assertEqual(stdout, "stdoutstderr")


def test_err_piped(self):
Expand Down

0 comments on commit 1460f6e

Please sign in to comment.