man/{docgen,simplecpp}: Force UTF-8 reading and writing regardless of locale
When encountering non-ASCII UTF-8 characters in source files (as exists in Crispy Doom), the Python scripts would fail to work with a UnicodeDecodeError if the locale was not a UTF-8 one (eg, the C locale as encountered in chroot build environments). Let's just use UTF-8 on both open() and replace print() statements with sys.stdout.buffer.write(). This guarantees that all input and output is UTF-8 regardless.
This commit is contained in:
parent
eaf851e095
commit
bf3747bfdd
2 changed files with 6 additions and 6 deletions
10
man/docgen
10
man/docgen
|
|
@ -300,7 +300,7 @@ class Parameter:
|
|||
# Read list of wiki pages
|
||||
|
||||
def read_wikipages():
|
||||
f = open("wikipages")
|
||||
f = open("wikipages", encoding='UTF-8')
|
||||
|
||||
try:
|
||||
for line in f:
|
||||
|
|
@ -356,7 +356,7 @@ def process_file(file):
|
|||
|
||||
current_config_file = None
|
||||
|
||||
f = open(file)
|
||||
f = open(file, encoding='UTF-8')
|
||||
|
||||
try:
|
||||
param = None
|
||||
|
|
@ -422,7 +422,7 @@ def process_files(path):
|
|||
process_file(path)
|
||||
|
||||
def print_template(template_file, content):
|
||||
f = open(template_file)
|
||||
f = open(template_file, encoding='UTF-8')
|
||||
|
||||
try:
|
||||
for line in f:
|
||||
|
|
@ -432,7 +432,7 @@ def print_template(template_file, content):
|
|||
print_template(filename, content)
|
||||
else:
|
||||
line = line.replace("@content", content)
|
||||
print(line.rstrip())
|
||||
sys.stdout.buffer.write(line.rstrip().encode('UTF-8'))
|
||||
|
||||
finally:
|
||||
f.close()
|
||||
|
|
@ -452,7 +452,7 @@ def wiki_output(targets, template):
|
|||
read_wikipages()
|
||||
|
||||
for t in targets:
|
||||
print(t.wiki_output())
|
||||
sys.stdout.buffer.write(t.wiki_output().encode('UTF-8'))
|
||||
|
||||
def plaintext_output(targets, template_file):
|
||||
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ def parse_stream(stream):
|
|||
raise Exception("Mismatched #if in '%s'" % stream.name)
|
||||
|
||||
def parse_file(filename):
|
||||
f = open(filename)
|
||||
f = open(filename, encoding='UTF-8')
|
||||
|
||||
try:
|
||||
parse_stream(f)
|
||||
|
|
|
|||
Loading…
Reference in a new issue