From 0d688b38db8edaef39f8d6b5349761e7c0cb047e Mon Sep 17 00:00:00 2001 From: Martin Landa Date: Wed, 24 Aug 2022 10:26:59 +0200 Subject: [PATCH 1/2] force mkhtml to use UTF-8 --- tools/mkhtml.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/tools/mkhtml.py b/tools/mkhtml.py index a6028dc03af..6821d03dc93 100644 --- a/tools/mkhtml.py +++ b/tools/mkhtml.py @@ -90,13 +90,6 @@ def fatal(message): ) -def _get_encoding(): - encoding = locale.getdefaultlocale()[1] - if not encoding: - encoding = 'UTF-8' - return encoding - - def decode(bytes_): """Decode bytes with default locale and return (unicode) string @@ -107,8 +100,7 @@ def decode(bytes_): if isinstance(bytes_, unicode): return bytes_ if isinstance(bytes_, bytes): - enc = _get_encoding() - return bytes_.decode(enc) + return bytes_.decode('UTF-8') return unicode(bytes_) From 48d979cea61c6acc9b01af43dfe028943ebcd1b5 Mon Sep 17 00:00:00 2001 From: Martin Landa Date: Fri, 26 Aug 2022 18:10:10 +0200 Subject: [PATCH 2/2] decode: +encoding --- tools/mkhtml.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/mkhtml.py b/tools/mkhtml.py index 6821d03dc93..5a736f60945 100644 --- a/tools/mkhtml.py +++ b/tools/mkhtml.py @@ -90,17 +90,18 @@ def fatal(message): ) -def decode(bytes_): +def decode(bytes_, encoding='UTF-8'): """Decode bytes with default locale and return (unicode) string No-op if parameter is not bytes (assumed unicode string). :param bytes bytes_: the bytes to decode + :param str encoding: encoding """ if isinstance(bytes_, unicode): return bytes_ if isinstance(bytes_, bytes): - return bytes_.decode('UTF-8') + return bytes_.decode(encoding) return unicode(bytes_) @@ -347,7 +348,7 @@ def read_file(name): if PY2: return s else: - return decode(s) + return decode(s, encoding='ISO-8859-1') except IOError: return ""