python preview filter: avoid printing spurious encoding value
This commit is contained in:
parent
70723a5280
commit
9b06d05be7
@ -51,6 +51,12 @@ _css_classes = {
|
|||||||
_TEXT: 'text',
|
_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 = """\
|
_HTML_HEADER = """\
|
||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
||||||
"http://www.w3.org/TR/html4/loose.dtd">
|
"http://www.w3.org/TR/html4/loose.dtd">
|
||||||
@ -146,17 +152,21 @@ class Parser:
|
|||||||
def __call__(self, toktype, toktext, startpos, endpos, line):
|
def __call__(self, toktype, toktext, startpos, endpos, line):
|
||||||
""" Token handler.
|
""" Token handler.
|
||||||
"""
|
"""
|
||||||
|
srow, scol = startpos
|
||||||
|
erow, ecol = endpos
|
||||||
if 0:
|
if 0:
|
||||||
print("type %s %s text %s start %s %s end %s %s<br>\n" % \
|
print("type %s %s text %s start %s %s end %s %s<br>\n" % \
|
||||||
(toktype, token.tok_name[toktype], toktext, \
|
(toktype, token.tok_name[toktype], toktext, \
|
||||||
srow, scol,erow,ecol))
|
srow, scol,erow,ecol), file=sys.stderr)
|
||||||
srow, scol = startpos
|
|
||||||
erow, ecol = endpos
|
|
||||||
# calculate new positions
|
# calculate new positions
|
||||||
oldpos = self.pos
|
oldpos = self.pos
|
||||||
newpos = self.lines[srow] + scol
|
newpos = self.lines[srow] + scol
|
||||||
self.pos = newpos + len(toktext)
|
self.pos = newpos + len(toktext)
|
||||||
|
|
||||||
|
if toktype == token_encoding_type:
|
||||||
|
return
|
||||||
|
|
||||||
# handle newlines
|
# handle newlines
|
||||||
if toktype in [token.NEWLINE, tokenize.NL]:
|
if toktype in [token.NEWLINE, tokenize.NL]:
|
||||||
self.out.write(b'\n')
|
self.out.write(b'\n')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user