Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force mkhtml to use UTF-8 #2533

Merged
merged 2 commits into from
Aug 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 4 additions & 11 deletions tools/mkhtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,18 @@ def fatal(message):
)


def _get_encoding():
encoding = locale.getdefaultlocale()[1]
if not encoding:
encoding = 'UTF-8'
return encoding


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):
enc = _get_encoding()
return bytes_.decode(enc)
return bytes_.decode(encoding)
return unicode(bytes_)


Expand Down Expand Up @@ -355,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 ""

Expand Down