← Back to team overview

yellow team mailing list archive

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

 

Francesco Banconi has proposed merging lp:~frankban/python-shelltoolbox/called-process-error-fixes into lp:python-shelltoolbox.

Requested reviews:
  Launchpad Yellow Squad (yellow)

For more details, see:
https://code.launchpad.net/~frankban/python-shelltoolbox/called-process-error-fixes/+merge/105786

== 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

-- 
https://code.launchpad.net/~frankban/python-shelltoolbox/called-process-error-fixes/+merge/105786
Your team Launchpad Yellow Squad is requested to review the proposed merge of lp:~frankban/python-shelltoolbox/called-process-error-fixes into lp:python-shelltoolbox.
=== modified file 'shelltoolbox/__init__.py'
--- shelltoolbox/__init__.py	2012-03-19 11:42:36 +0000
+++ shelltoolbox/__init__.py	2012-05-15 09:45:32 +0000
@@ -418,9 +418,13 @@
         close_fds=kwargs.pop('close_fds', True), **kwargs)
     stdout, stderr = process.communicate()
     if process.returncode:
-        output = ''.join(filter(None, [stdout, stderr]))
-        raise subprocess.CalledProcessError(
-            process.returncode, repr(args), output=output)
+        exception = subprocess.CalledProcessError(
+            process.returncode, repr(args))
+        # The output argument of `CalledProcessError` was introduced in Python
+        # 2.7. Monkey patch the output here to avoid TypeErrors in older
+        # versions of Python, still preserving the output in Python 2.7.
+        exception.output = ''.join(filter(None, [stdout, stderr]))
+        raise exception
     return stdout
 
 


Follow ups