diff --git a/powerline/lib/unicode.py b/powerline/lib/unicode.py index b100b18f..93c097db 100644 --- a/powerline/lib/unicode.py +++ b/powerline/lib/unicode.py @@ -100,7 +100,10 @@ def safe_unicode(s): ''' try: try: - return unicode(s) + if type(s) is bytes: + return unicode(s, 'ascii') + else: + return unicode(s) except UnicodeDecodeError: try: return unicode(s, 'utf-8') @@ -125,11 +128,18 @@ class FailedUnicode(unicode): pass -def string(s): - if type(s) is not str: - return s.encode('utf-8') - else: - return s +if sys.version_info < (3,): + def string(s): + if type(s) is not str: + return s.encode('utf-8') + else: + return s +else: + def string(s): + if type(s) is not str: + return s.decode('utf-8') + else: + return s def surrogate_pair_to_character(high, low): diff --git a/tests/test_lib.py b/tests/test_lib.py index 06b28fa7..68e08a66 100644 --- a/tests/test_lib.py +++ b/tests/test_lib.py @@ -448,7 +448,6 @@ class TestUnicode(TestCase): self.assertRaises(TypeError, plu.out_u, None) def test_safe_unicode(self): - raise SkipTest('safe_unicode() function is buggy') self.assertStringsIdentical('abc', plu.safe_unicode('abc')) self.assertStringsIdentical('abc', plu.safe_unicode(b'abc')) self.assertStringsIdentical('«»', plu.safe_unicode(b'\xc2\xab\xc2\xbb')) @@ -467,7 +466,6 @@ class TestUnicode(TestCase): self.assertEqual('abc', plu.FailedUnicode('abc')) def test_string(self): - raise SkipTest('string() function is buggy') self.assertStringsIdentical(str('abc'), plu.string('abc')) self.assertStringsIdentical(str('abc'), plu.string(b'abc'))