diff --git a/python/catkin/environment_cache.py b/python/catkin/environment_cache.py index ebe14328c..3defa5211 100755 --- a/python/catkin/environment_cache.py +++ b/python/catkin/environment_cache.py @@ -59,9 +59,7 @@ def generate_environment_script(env_script): # fetch environment after calling setup python_code = 'import os; print(dict(os.environ))' output = subprocess.check_output([env_script, sys.executable, '-c', python_code]) - if hasattr(sys.stdout, 'encoding') and sys.stdout.encoding: - output = output.decode(sys.stdout.encoding) - env_after = ast.literal_eval(output) + env_after = ast.literal_eval(output.decode('utf8')) # calculate added and modified environment variables added = {} diff --git a/python/catkin/tidy_xml.py b/python/catkin/tidy_xml.py index 2b2524625..c35e841f1 100644 --- a/python/catkin/tidy_xml.py +++ b/python/catkin/tidy_xml.py @@ -83,5 +83,5 @@ def tidy_xml(filename): data = data[:match.start()] + '?' + data[match.end():] with open(filename, 'w') as fhand: - fhand.write(data.encode('utf-8')) + fhand.write(data) return True diff --git a/test/unit_tests/test_environment_cache.py b/test/unit_tests/test_environment_cache.py index 01c621916..dc27e5e91 100644 --- a/test/unit_tests/test_environment_cache.py +++ b/test/unit_tests/test_environment_cache.py @@ -65,7 +65,7 @@ def test_generate_environment_script(self): catkin.environment_cache.os.environ = fake_environ rootdir = tempfile.mkdtemp() env_file = os.path.join(rootdir, 'env.sh') - with open(env_file, 'ab') as fhand: + with open(env_file, 'a') as fhand: fhand.write('''\ #! /usr/bin/env sh export FOO=/foo:/bar diff --git a/test/unit_tests/test_terminal_color.py b/test/unit_tests/test_terminal_color.py index d3f36d2e8..e2afc5612 100644 --- a/test/unit_tests/test_terminal_color.py +++ b/test/unit_tests/test_terminal_color.py @@ -7,6 +7,11 @@ 'Please adjust your pythonpath before running this test: %s' % str(e) ) +try: + char = unichr +except NameError: + char = chr + class TerminalColorTest(unittest.TestCase): @@ -18,7 +23,7 @@ def test_terminal_colors(self): test = sanitize(test) rslt = 'This has bad stuff @! @/ @_ @| OK!\033[0m' assert fmt(test) == rslt - test = u'\u2018@' + test = char(2018) test = sanitize(test) - rslt = u'\u2018@@' + rslt = char(2018) assert test == rslt diff --git a/test/unit_tests/test_tidy_xml.py b/test/unit_tests/test_tidy_xml.py index de91c5bac..1080fa5cc 100644 --- a/test/unit_tests/test_tidy_xml.py +++ b/test/unit_tests/test_tidy_xml.py @@ -9,11 +9,16 @@ raise ImportError( 'Please adjust your pythonpath before running this test: %s' % str(impe)) +try: + char = unichr +except NameError: + char = chr + class TidyXmlTest(unittest.TestCase): def test_safe_xml_regex(self): - for data in [u'\u0000', u'\u000e']: + for data in [char(0), char(14)]: self.assertIsNotNone(_SAFE_XML_REGEX.match(data)) def test_tiny_xml(self): @@ -24,7 +29,7 @@ def test_tiny_xml(self): utf8_file = os.path.join(rootdir, 'utf8.xml') with open(utf8_file, 'ab') as fhand: - fhand.write(u'\u0000') + fhand.write(char(0).encode('utf8)')) tidy_xml(utf8_file) with open(utf8_file, 'r') as fhand: contents = fhand.read() @@ -32,7 +37,7 @@ def test_tiny_xml(self): iso_file = os.path.join(rootdir, 'iso.xml') with open(iso_file, 'ab') as fhand: - fhand.write(u'\u0000') + fhand.write(char(0).encode('ascii')) tidy_xml(iso_file) with open(iso_file, 'r') as fhand: contents = fhand.read()