Add support for Python3 in parser script

pull/10/head v0.1.1
nirenjan 2016-05-06 07:39:02 -07:00
parent 224b08a8e2
commit 710ef00109
1 changed files with 12 additions and 2 deletions

View File

@ -63,8 +63,18 @@ class MapTable():
@classmethod @classmethod
def add_to_table(cls, input_val, map_val): def add_to_table(cls, input_val, map_val):
utf8_str = unichr(input_val).encode('utf-8') try:
utf8_vals = [ord(c) for c in utf8_str] uchr = unichr(input_val)
except NameError:
# Python 3 doesn't have unichr, but chr should work
uchr = chr(input_val)
utf8_str = uchr.encode('utf-8')
# Python2 returns the encoded result as a string, wheras
# Python3 returns the result as a bytearray. Converting
# the string (or bytearray) into a bytearray ensures that
# this can be run in both Python2 and Python3
utf8_vals = [c for c in bytearray(utf8_str)]
value_so_far = 0 value_so_far = 0
level = cls.root level = cls.root