Skip to content

Commit 5255e7d

Browse files
authored
Merge pull request #251 from fstagni/py2andpy3
fix: ensure unicode conversion
2 parents d680770 + 0834234 commit 5255e7d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Pilot/pilotTools.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,20 @@ def executeAndGetOutput(self, cmd, environDict=None):
787787
if not outChunk:
788788
continue
789789
dataWasRead = True
790+
# Ensure outChunk is unicode in Python 2
791+
if sys.version_info[0] < 3:
792+
if isinstance(outChunk, str):
793+
outChunk = outChunk.decode("utf-8")
790794
# Strip unicode replacement characters
791795
outChunk = str(outChunk.replace("\ufffd", ""))
796+
797+
# Ensure correct type conversion in Python 2
798+
if sys.version_info[0] < 3:
799+
# Avoid potential str() issues in Py2
800+
outChunk = unicode(outChunk) # pylint: disable=undefined-variable
801+
else:
802+
outChunk = str(outChunk) # Python 3: Ensure it's a string
803+
792804
if stream == _p.stderr:
793805
sys.stderr.write(outChunk)
794806
sys.stderr.flush()

0 commit comments

Comments
 (0)