Merge lp:~frankban/python-shelltoolbox/called-process-error-fixes into lp:python-shelltoolbox

Proposed by Francesco Banconi
Status: Merged
Approved by: Graham Binns
Approved revision: 16
Merged at revision: 16
Proposed branch: lp:~frankban/python-shelltoolbox/called-process-error-fixes
Merge into: lp:python-shelltoolbox
Diff against target: 18 lines (+7/-3)
1 file modified
shelltoolbox/__init__.py (+7/-3)
To merge this branch: bzr merge lp:~frankban/python-shelltoolbox/called-process-error-fixes
Reviewer Review Type Date Requested Status
Graham Binns (community) code Approve
Review via email: mp+105786@code.launchpad.net

Description of the change

== Changes ==

Updated the run function to be compatible with Python < 2.7.
See comments in the diff.

== Tests ==

$ python tests.py ...........................................................
----------------------------------------------------------------------
Ran 59 tests in 0.119s

OK

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'shelltoolbox/__init__.py'
2--- shelltoolbox/__init__.py 2012-03-19 11:42:36 +0000
3+++ shelltoolbox/__init__.py 2012-05-15 09:45:32 +0000
4@@ -418,9 +418,13 @@
5 close_fds=kwargs.pop('close_fds', True), **kwargs)
6 stdout, stderr = process.communicate()
7 if process.returncode:
8- output = ''.join(filter(None, [stdout, stderr]))
9- raise subprocess.CalledProcessError(
10- process.returncode, repr(args), output=output)
11+ exception = subprocess.CalledProcessError(
12+ process.returncode, repr(args))
13+ # The output argument of `CalledProcessError` was introduced in Python
14+ # 2.7. Monkey patch the output here to avoid TypeErrors in older
15+ # versions of Python, still preserving the output in Python 2.7.
16+ exception.output = ''.join(filter(None, [stdout, stderr]))
17+ raise exception
18 return stdout
19
20

Subscribers

People subscribed via source and target branches