This repository was archived by the owner on Jul 24, 2020. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import subprocess
44import sys as _sys
55
6+ import six
67from six .moves import shlex_quote
78
8- from galaxy .util import which
9+ from galaxy .util import (
10+ unicodify ,
11+ which
12+ )
913
1014STDOUT_INDICATOR = "-"
1115
1216
1317def redirecting_io (sys = _sys ):
14- """Predicate to determine if we are redicting I/O in process."""
18+ """Predicate to determine if we are redicting stdout in process."""
1519 assert sys is not None
16- return not hasattr (sys .stdout , "fileno" )
20+ try :
21+ # Need to explicitly call fileno() because sys.stdout could be a
22+ # io.StringIO object, which has a fileno() method but only raises an
23+ # io.UnsupportedOperation exception
24+ sys .stdout .fileno ()
25+ except Exception :
26+ return True
27+ else :
28+ return False
1729
1830
1931def redirect_aware_commmunicate (p , sys = _sys ):
@@ -22,9 +34,15 @@ def redirect_aware_commmunicate(p, sys=_sys):
2234 out , err = p .communicate ()
2335 if redirecting_io (sys = sys ):
2436 if out :
37+ # We don't unicodify in Python2 because sys.stdout may be a
38+ # cStringIO.StringIO object, which does not accept Unicode strings
39+ if not six .PY2 :
40+ out = unicodify (out )
2541 sys .stdout .write (out )
2642 out = None
2743 if err :
44+ if not six .PY2 :
45+ err = unicodify (err )
2846 sys .stderr .write (err )
2947 err = None
3048 return out , err
You can’t perform that action at this time.
0 commit comments