Minor fixes

This commit is contained in:
Ivan Kravets
2020-03-06 00:43:57 +02:00
parent 59e1c88726
commit 3ef96cb215
2 changed files with 14 additions and 14 deletions

View File

@ -18,6 +18,7 @@
from __future__ import absolute_import
import hashlib
import io
import os
import re
import sys
@ -82,7 +83,7 @@ class LibBuilderFactory(object):
fname, piotool.SRC_BUILD_EXT + piotool.SRC_HEADER_EXT
):
continue
with open(join(root, fname)) as fp:
with io.open(join(root, fname), errors="ignore") as fp:
content = fp.read()
if not content:
continue

View File

@ -53,7 +53,7 @@ class InoToCPPConverter(object):
self._safe_encoding = None
def read_safe_contents(self, path):
last_exc = None
error_reported = False
for encoding in (
"utf-8",
None,
@ -66,18 +66,17 @@ class InoToCPPConverter(object):
contents = fp.read()
self._safe_encoding = encoding
return contents
except UnicodeDecodeError as e:
last_exc = e
click.secho(
"Unicode decode error has occurred, please remove invalid "
"(non-ASCII or non-UTF8) characters from %s file or convert it to UTF-8"
% path,
fg="yellow",
err=True,
)
if last_exc:
raise last_exc
return None
except UnicodeDecodeError:
if not error_reported:
error_reported = True
click.secho(
"Unicode decode error has occurred, please remove invalid "
"(non-ASCII or non-UTF8) characters from %s file or convert it to UTF-8"
% path,
fg="yellow",
err=True,
)
return ""
def write_safe_contents(self, path, contents):
with io.open(