waf/common: Fix UTF-8 encoding of HTML inliner output on Python3.

This commit is contained in:
Chris Johns 2019-10-29 13:37:43 +11:00
parent bb47f890c8
commit c576e9bf0d

View File

@ -359,12 +359,20 @@ def doc_singlehtml(ctx, source_dir, conf_dir, sources):
# The inliner does not handle internal href's correctly and places the # The inliner does not handle internal href's correctly and places the
# input's file name in the href. Strip these. # input's file name in the href. Strip these.
# #
if sys.version_info[0] < 3:
with open(tgt, 'r') as i: with open(tgt, 'r') as i:
before = i.read() before = i.read()
after = before.replace('index.html', '') else:
with open(tgt, 'r', encoding = 'ascii', errors = 'surrogateescape') as i:
before = i.read()
i.close() i.close()
after = before.replace('index.html', '')
if sys.version_info[0] < 3:
with open(tgt, 'w') as o: with open(tgt, 'w') as o:
o.write(after) o.write(after)
else:
with open(tgt, 'w', encoding = 'ascii', errors = 'surrogateescape') as o:
o.write(after)
o.close() o.close()
return r return r