From ee11ba100a909bff3698e1332ffb133a2ea9b3ee Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sun, 29 Dec 2019 11:05:34 +0100 Subject: [PATCH] Switch Python scripts to Python 3 The scripts had already the majority of the work needed for Python 3, and Python 2 is EOL since Jan 1st 2020, so just the scripts to Python 3. The last change required is to fix the repr() on chars, due to the text vs data changes in Python 3: repr() prints more Unicode representations now, breaking the C output (e.g. \r now is lterally printed as such, removing all the content in the line before that). As fix, use the workaround proposed in PEP-3138 [1]. This fixes the generate_fsm_test_sh test. [1] https://www.python.org/dev/peps/pep-3138/#id10 --- src/htmlparser/generate_fsm.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/htmlparser/generate_fsm.py b/src/htmlparser/generate_fsm.py index 6202c36..514788d 100755 --- a/src/htmlparser/generate_fsm.py +++ b/src/htmlparser/generate_fsm.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Copyright (c) 2008, Google Inc. # All rights reserved. @@ -282,7 +282,8 @@ class FSMGenerateC(FSMGenerateAbstract): for state in self._config.states: transition_row = [] for c in range(0, 255): - transition_row.append(' /* %06s */ %s' % (repr(chr(c)), + ch_repr = str(repr(chr(c)).encode("ASCII", "backslashreplace"), "ASCII") + transition_row.append(' /* %06s */ %s' % (ch_repr, state_table[state][c])) out.append(self._CreateStructList('%stransition_row_%s' %