From 9b06d05be72fed64d97cf01aff7e2171613afe84 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Sun, 31 Jul 2022 21:58:03 +0200 Subject: [PATCH] python preview filter: avoid printing spurious encoding value --- src/filters/rclpython.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/filters/rclpython.py b/src/filters/rclpython.py index 1d812dcf..a83ae1b9 100755 --- a/src/filters/rclpython.py +++ b/src/filters/rclpython.py @@ -51,6 +51,12 @@ _css_classes = { _TEXT: 'text', } +# python3.8 token.py sends an ENCODING token which we ignore +try: + token_encoding_type = token.ENCODING +except: + token_encoding_type = 62 + _HTML_HEADER = """\ @@ -146,17 +152,21 @@ class Parser: def __call__(self, toktype, toktext, startpos, endpos, line): """ Token handler. """ + srow, scol = startpos + erow, ecol = endpos if 0: print("type %s %s text %s start %s %s end %s %s
\n" % \ (toktype, token.tok_name[toktype], toktext, \ - srow, scol,erow,ecol)) - srow, scol = startpos - erow, ecol = endpos + srow, scol,erow,ecol), file=sys.stderr) + # calculate new positions oldpos = self.pos newpos = self.lines[srow] + scol self.pos = newpos + len(toktext) + if toktype == token_encoding_type: + return + # handle newlines if toktype in [token.NEWLINE, tokenize.NL]: self.out.write(b'\n')