diff options
author | Damien George <damien.p.george@gmail.com> | 2016-04-14 14:37:04 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-04-14 14:37:04 +0100 |
commit | 2243d68345cc3446b26c792c1424c81bcf858216 (patch) | |
tree | 3ffaecf1cacd9db3a04e132215e94d9b97e0c64b /py/makeqstrdata.py | |
parent | 49bb04ee64d719c83ae3f2ded4c9f9578707bd84 (diff) | |
download | micropython-2243d68345cc3446b26c792c1424c81bcf858216.tar.gz micropython-2243d68345cc3446b26c792c1424c81bcf858216.zip |
py/makeqstrdata: Reinstate Python2 compatibility.
Diffstat (limited to 'py/makeqstrdata.py')
-rw-r--r-- | py/makeqstrdata.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py index 7cad46e6ec..325207c05a 100644 --- a/py/makeqstrdata.py +++ b/py/makeqstrdata.py @@ -9,11 +9,15 @@ from __future__ import print_function import re import sys -# codepoint2name is different in Python 2 to Python 3 +# Python 2/3 compatibility: +# - iterating through bytes is different +# - codepoint2name lives in a different module import platform if platform.python_version_tuple()[0] == '2': + ord_bytes = ord from htmlentitydefs import codepoint2name elif platform.python_version_tuple()[0] == '3': + ord_bytes = lambda x:x from html.entities import codepoint2name codepoint2name[ord('-')] = 'hyphen'; @@ -114,7 +118,7 @@ def make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr): # qstr contains non-printable codes so render entire thing as hex pairs qbytes = qstr.encode('utf8') qlen = len(qbytes) - qdata = ''.join(('\\x%02x' % b) for b in qbytes) + qdata = ''.join(('\\x%02x' % ord_bytes(b)) for b in qbytes) if qlen >= (1 << (8 * cfg_bytes_len)): print('qstr is too long:', qstr) assert False |