From 9c6187d8ad6b15fda5d655de9caa459681ec3749 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 18 May 2021 14:49:02 +0200 Subject: [PATCH] Explicitly use UTF-8 in assemble_changelog Changelog contents should be UTF-8 text files. So explicitly open all files as UTF-8. This makes the script independent of the ambient locale (except with respect to exception messages, but we can live with that). Signed-off-by: Gilles Peskine --- scripts/assemble_changelog.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/assemble_changelog.py b/scripts/assemble_changelog.py index 169995523..b8a63c9e9 100755 --- a/scripts/assemble_changelog.py +++ b/scripts/assemble_changelog.py @@ -264,7 +264,7 @@ class ChangeLog: def write(self, filename): """Write the changelog to the specified file. """ - with open(filename, 'w') as out: + with open(filename, 'w', encoding='utf-8') as out: out.write(self.header) out.write(self.top_version_title) for title, body in self.categories.items(): @@ -407,12 +407,12 @@ def check_output(generated_output_file, main_input_file, merged_files): is also present in an output file. This is not perfect but good enough for now. """ - generated_output = set(open(generated_output_file, 'r')) - for line in open(main_input_file, 'r'): + generated_output = set(open(generated_output_file, 'r', encoding='utf-8')) + for line in open(main_input_file, 'r', encoding='utf-8'): if line not in generated_output: raise LostContent('original file', line) for merged_file in merged_files: - for line in open(merged_file, 'r'): + for line in open(merged_file, 'r', encoding='utf-8'): if line not in generated_output: raise LostContent(merged_file, line) @@ -455,14 +455,14 @@ def merge_entries(options): Write the new changelog to options.output. Remove the merged entries if options.keep_entries is false. """ - with open(options.input, 'r') as input_file: + with open(options.input, 'r', encoding='utf-8') as input_file: changelog = ChangeLog(input_file, TextChangelogFormat) files_to_merge = list_files_to_merge(options) if not files_to_merge: sys.stderr.write('There are no pending changelog entries.\n') return for filename in files_to_merge: - with open(filename, 'r') as input_file: + with open(filename, 'r', encoding='utf-8') as input_file: changelog.add_file(input_file) finish_output(changelog, options.output, options.input, files_to_merge) if not options.keep_entries: