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

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 comment and docstring, they were unclear 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..034463fd20da0dfcad53ff2ccde1e61112cd98ad 100644
--- a/subprocess2.py
+++ b/subprocess2.py
@@ -249,6 +249,8 @@ def call(args, **kwargs):
"""Emulates subprocess.call().
Automatically convert stdout=PIPE or stderr=PIPE to VOID.
+ In no case they can be returned since no code path raises
+ subprocess2.CalledProcessError.
"""
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)
+
+ # Like check_output, deny the caller from using stdout arg.
+ 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