Permalink
Browse files

Add Python 2.6 support - closes #7

  • Loading branch information...
1 parent f1b8eb6 commit e5c4c00dddb1d7465bb55925f0d5a4830d7ac3a6 @voltagex voltagex committed Oct 2, 2012
Showing with 28 additions and 1 deletion.
  1. +22 −0 check_output.py
  2. +6 −1 geturl
View
22 check_output.py
@@ -0,0 +1,22 @@
+#from https://gist.github.com/1027906
+import subprocess
+
+def check_output(*popenargs, **kwargs):
+ r"""Run command with arguments and return its output as a byte string.
+
+ Backported from Python 2.7 as it's implemented as pure python on stdlib.
+
+ >>> check_output(['/usr/bin/python', '--version'])
+ Python 2.6.2
+ """
+ process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
+ output, unused_err = process.communicate()
+ retcode = process.poll()
+ if retcode:
+ cmd = kwargs.get("args")
+ if cmd is None:
+ cmd = popenargs[0]
+ error = subprocess.CalledProcessError(retcode, cmd)
+ error.output = output
+ raise error
+ return output
View
7 geturl
@@ -1,6 +1,11 @@
#!/usr/bin/python
-from subprocess import check_output, CalledProcessError
+from subprocess import CalledProcessError
+try:
+ from subprocess import check_output
+except ImportError:
+ from check_output import check_output
+
import json
import sys
import os

0 comments on commit e5c4c00

Please sign in to comment.