mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
fix for streaming aliases
This commit is contained in:
parent
477dddc059
commit
23c3446fa7
3 changed files with 39 additions and 5 deletions
14
news/sa.rst
Normal file
14
news/sa.rst
Normal file
|
@ -0,0 +1,14 @@
|
|||
**Added:** None
|
||||
|
||||
**Changed:** None
|
||||
|
||||
**Deprecated:** None
|
||||
|
||||
**Removed:** None
|
||||
|
||||
**Fixed:**
|
||||
|
||||
* Fixed streaming ``!(alias)`` repr evaluation where bytes where not
|
||||
streamed.
|
||||
|
||||
**Security:** None
|
|
@ -58,6 +58,28 @@ def _f():
|
|||
aliases['f'] = _f
|
||||
print(![f].returncode)
|
||||
""", "42\n", 0),
|
||||
# test uncaptured streaming alias
|
||||
("""
|
||||
def _test_stream(args, stdin, stdout, stderr):
|
||||
print('hallo on err', file=stderr)
|
||||
print('hallo on out', file=stdout)
|
||||
return 1
|
||||
|
||||
aliases['test-stream'] = _test_stream
|
||||
x = ![test-stream]
|
||||
print(x.returncode)
|
||||
""", "hallo on out\nhallo on err\n1\n", 0),
|
||||
# test captured streaming alias
|
||||
("""
|
||||
def _test_stream(args, stdin, stdout, stderr):
|
||||
print('hallo on err', file=stderr)
|
||||
print('hallo on out', file=stdout)
|
||||
return 1
|
||||
|
||||
aliases['test-stream'] = _test_stream
|
||||
x = !(test-stream)
|
||||
print(x.returncode)
|
||||
""", "hallo on err\n1\n", 0),
|
||||
]
|
||||
|
||||
|
||||
|
@ -86,4 +108,3 @@ def test_script(case):
|
|||
assert exp_out == out
|
||||
assert exp_rtn == p.returncode
|
||||
|
||||
|
||||
|
|
|
@ -893,7 +893,7 @@ def proxy_four(f, args, stdin, stdout, stderr, spec):
|
|||
"""Calls a proxy function which takes four parameter: args, stdin, stdout,
|
||||
and stderr.
|
||||
"""
|
||||
return f(args, stdin, stdout)
|
||||
return f(args, stdin, stdout, stderr)
|
||||
|
||||
|
||||
PROXIES = (proxy_zero, proxy_one, proxy_two, proxy_three, proxy_four)
|
||||
|
@ -1440,13 +1440,12 @@ class CommandPipeline:
|
|||
"""
|
||||
# get approriate handles
|
||||
proc = self.proc
|
||||
uninew = self.spec.universal_newlines
|
||||
# get the correct stdout
|
||||
stdout = proc.stdout
|
||||
if ((stdout is None or not safe_readable(stdout)) and
|
||||
self.spec.captured_stdout is not None):
|
||||
stdout = self.spec.captured_stdout
|
||||
if uninew and hasattr(stdout, 'buffer'):
|
||||
if hasattr(stdout, 'buffer'):
|
||||
stdout = stdout.buffer
|
||||
if not stdout or not safe_readable(stdout):
|
||||
# we get here if the process is not bacgroundable or the
|
||||
|
@ -1462,7 +1461,7 @@ class CommandPipeline:
|
|||
if ((stderr is None or not safe_readable(stderr)) and
|
||||
self.spec.captured_stderr is not None):
|
||||
stderr = self.spec.captured_stderr
|
||||
if uninew and hasattr(stderr, 'buffer'):
|
||||
if hasattr(stderr, 'buffer'):
|
||||
stderr = stderr.buffer
|
||||
# read from process while it is running
|
||||
timeout = builtins.__xonsh_env__.get('XONSH_PROC_FREQUENCY')
|
||||
|
|
Loading…
Add table
Reference in a new issue