Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Unified Diff: subprocess2.py

Issue 7860041: Update subprocess2.check_output() to behave like subprocess.check_output(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Update callers to reset to previous expected behavior Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « scm.py ('k') | tests/subprocess2_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: subprocess2.py
diff --git a/subprocess2.py b/subprocess2.py
index 5678127aff4e96c1f60e114eec6a2012f9e828b9..895f5a5e19d7e89a09ffd1f2f3e6304d2bac0d03 100644
--- a/subprocess2.py
+++ b/subprocess2.py
@@ -248,7 +248,9 @@ def communicate(args, timeout=None, **kwargs):
def call(args, **kwargs):
"""Emulates subprocess.call().
- Automatically convert stdout=PIPE or stderr=PIPE to VOID.
+ Automatically convert stdout=PIPE or stderr=PIPE to VOID since in no case they
+ can be returned, no exception is thrown in this code path where stdout is not
+ None.
Dirk Pranke 2011/09/09 18:10:38 Grammar nit: "Automatically converts stdout=PIPE o
M-A Ruel 2011/09/09 18:59:21 Looks like the docstring was unclear since it's no
"""
if kwargs.get('stdout') == PIPE:
kwargs['stdout'] = VOID
@@ -281,16 +283,12 @@ def capture(args, **kwargs):
Returns stdout.
- Discards returncode.
- - Discards stderr. By default sets stderr=STDOUT.
- - Blocks stdin by default since no output will be visible.
+ - Blocks stdin by default if not specified since no output will be visible.
"""
- if kwargs.get('stdin') is None:
- kwargs['stdin'] = VOID
- if kwargs.get('stdout') is None:
- kwargs['stdout'] = PIPE
- if kwargs.get('stderr') is None:
- kwargs['stderr'] = STDOUT
- return communicate(args, **kwargs)[0][0]
+ kwargs.setdefault('stdin', VOID)
+
+ # Similar to check_output, deny using stdout arg.
Dirk Pranke 2011/09/09 18:10:38 Grammar nit: "Like check_output(), we ignore any s
M-A Ruel 2011/09/09 18:59:21 No it's denied. Clarified comment.
+ return communicate(args, stdout=PIPE, **kwargs)[0][0]
def check_output(args, **kwargs):
@@ -298,15 +296,10 @@ def check_output(args, **kwargs):
Captures stdout of a process call and returns stdout only.
- - Discards stderr. By default sets stderr=STDOUT.
- Throws if return code is not 0.
- Works even prior to python 2.7.
- - Blocks stdin by default since no output will be visible.
+ - Blocks stdin by default if not specified since no output will be visible.
+ - As per doc, "The stdout argument is not allowed as it is used internally."
"""
- if kwargs.get('stdin') is None:
- kwargs['stdin'] = VOID
- if kwargs.get('stdout') is None:
- kwargs['stdout'] = PIPE
- if kwargs.get('stderr') is None:
- kwargs['stderr'] = STDOUT
- return check_call_out(args, **kwargs)[0]
+ kwargs.setdefault('stdin', VOID)
+ return check_call_out(args, stdout=PIPE, **kwargs)[0]
« no previous file with comments | « scm.py ('k') | tests/subprocess2_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698