diff --git a/catkin_tools/execution/io.py b/catkin_tools/execution/io.py index 6086261f..3f8b39e1 100644 --- a/catkin_tools/execution/io.py +++ b/catkin_tools/execution/io.py @@ -25,6 +25,19 @@ MAX_LOGFILE_HISTORY = 10 +if type(u'') == str: + def _encode(string): + """Encode a Python 3 str into bytes. + :type data: str + """ + return string.encode('utf-8') +else: + def _encode(string): + """Encode a Python 2 str into bytes. + :type data: str + """ + return string.decode('utf-8').encode('utf-8') + class IOBufferContainer(object): @@ -109,7 +122,7 @@ def _encode(self, data): """Encode a Python str into bytes. :type data: str """ - return data.encode('utf-8') + return _encode(data) def _decode(self, data): """Decode bytes into Python str.