From f4da28b1f153ccf293b367363a1a4d83c056e4e1 Mon Sep 17 00:00:00 2001 From: cclauss Date: Sun, 30 Dec 2018 12:58:34 +0100 Subject: [PATCH] Python 3 fixes to gen-os2-unicode-ranges.py (#1521) In Python 3, __reload()__ was moved and __sys.setdefaultencoding()__ because the default is already utf-8. Also __Error()__ is an _undefined name_ and __Exception()__ creates a generic exception. --- src/gen-os2-unicode-ranges.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/gen-os2-unicode-ranges.py b/src/gen-os2-unicode-ranges.py index d768313dd..8cf598588 100644 --- a/src/gen-os2-unicode-ranges.py +++ b/src/gen-os2-unicode-ranges.py @@ -10,8 +10,11 @@ import io import re import sys -reload(sys) -sys.setdefaultencoding('utf-8') +try: + reload(sys) + sys.setdefaultencoding('utf-8') +except NameError: + pass # Python 3 print ("""static OS2Range _hb_os2_unicode_ranges[] = {""") @@ -32,12 +35,12 @@ with io.open(input_file, mode="r", encoding="utf-8") as f: current_bit = fields[0] fields = fields[1:] elif len(fields) > 3: - raise Error("bad input :(.") + raise Exception("bad input :(.") name = fields[0] ranges = re.split("-", fields[1]) if len(ranges) != 2: - raise Error("bad input :(.") + raise Exception("bad input :(.") v = tuple((int(ranges[0], 16), int(ranges[1], 16), int(current_bit), name)) all_ranges.append(v)