Fix encoding read error

When using
: with open(fname, 'r') as file:
hits the accented letter á in Vrána in the file
: data/wxWidgets-small/src/stc/scintilla/lexers/LexCSS.cxx
it results in a
: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe1 in position 119: invalid continuation byte

We are reading source code, so we likely don't care about dropping non-ascii; using
: with codecs.open(fname, 'r', encoding="latin-1") as file:
ignores this problem.
This commit is contained in:
Michael Hohn
2021-11-21 16:42:11 -08:00
committed by =Michael Hohn
parent 85ddaaafe1
commit f0aa815a9a

View File

@@ -1,6 +1,7 @@
import sys
import os
import re
import codecs
MIN_PYTHON = (3, 7)
if sys.version_info < MIN_PYTHON:
@@ -97,7 +98,7 @@ def load_lines(root, path, line_from, line_to):
if not os.path.exists(fname):
dbg("Missing file: %s" % fname)
return []
with open(fname, 'r') as file:
with codecs.open(fname, 'r', encoding="latin-1") as file:
lines = file.readlines()
return [line.rstrip("\n\r").replace("\t", " ")
for line in lines[line_from-1 : line_to-1+1]]