summaryrefslogtreecommitdiffstatshomepage
path: root/stmhal/make-stmconst.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-11-16 23:29:02 +1100
committerDamien George <damien.p.george@gmail.com>2016-11-16 23:29:02 +1100
commitc5621529c9c48aa501e96553e967dec780b64f25 (patch)
tree229008cd2c1e0ee0d65600b439b810b609f9fe13 /stmhal/make-stmconst.py
parent4d9dce775989b344a8ebd91bdfa6bcd0d5dc4c74 (diff)
downloadmicropython-c5621529c9c48aa501e96553e967dec780b64f25.tar.gz
micropython-c5621529c9c48aa501e96553e967dec780b64f25.zip
stmhal/make-stmconst.py: Add support for files with invalid utf8 bytes.
Diffstat (limited to 'stmhal/make-stmconst.py')
-rw-r--r--stmhal/make-stmconst.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/stmhal/make-stmconst.py b/stmhal/make-stmconst.py
index 05c0c08c96..7afafe7206 100644
--- a/stmhal/make-stmconst.py
+++ b/stmhal/make-stmconst.py
@@ -42,12 +42,17 @@ class Lexer:
)
def __init__(self, filename):
- self.file = open(filename, 'rt')
+ self.file = open(filename, 'rb')
self.line_number = 0
def next_match(self, strictly_next=False):
while True:
line = self.file.readline()
+ try:
+ line = str(line, 'utf8')
+ except ValueError:
+ # some files have invalid utf8 bytes, so filter them out
+ line = ''.join(chr(l) for l in line if l <= 126)
self.line_number += 1
if len(line) == 0:
return ('EOF', None)