From: Khaled Hosny Date: Sun, 26 Mar 2017 08:48:53 +0000 (+0200) Subject: [tools] Make hb-unicode-code work with Python 3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f2e6c7ce51283809033d08692a2dee7cf04aefc5;p=platform%2Fupstream%2FlibHarfBuzzSharp.git [tools] Make hb-unicode-code work with Python 3 Related to https://github.com/behdad/harfbuzz/pull/445 --- diff --git a/test/shaping/hb_test_tools.py b/test/shaping/hb_test_tools.py index 7473982..052974d 100644 --- a/test/shaping/hb_test_tools.py +++ b/test/shaping/hb_test_tools.py @@ -46,6 +46,17 @@ try: except NameError: unichr = chr +try: + unicode = unicode +except NameError: + unicode = str + +def tounicode(s, encoding='ascii', errors='strict'): + if not isinstance(s, unicode): + return s.decode(encoding, errors) + else: + return s + class ColorFormatter: class Null: @@ -445,7 +456,7 @@ class Unicode: @staticmethod def decode (s): - return u','.join ("U+%04X" % ord (u) for u in unicode (s, 'utf-8')).encode ('utf-8') + return u','.join ("U+%04X" % ord (u) for u in tounicode (s, 'utf-8')) @staticmethod def parse (s):