1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-05 19:35:48 +03:00

Ensure files get closed when they go out of scope

This is automatic in CPython but not guaranteed by the language. Be friendly
to other Python implementations.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine
2022-03-04 20:02:00 +01:00
parent 1177f37648
commit aeb8d66525
4 changed files with 56 additions and 48 deletions

View File

@@ -407,14 +407,17 @@ 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', 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', encoding='utf-8'):
if line not in generated_output:
raise LostContent(merged_file, line)
with open(generated_output_file, 'r', encoding='utf-8') as out_fd:
generated_output = set(out_fd)
with open(main_input_file, 'r', encoding='utf-8') as in_fd:
for line in in_fd:
if line not in generated_output:
raise LostContent('original file', line)
for merged_file in merged_files:
with open(merged_file, 'r', encoding='utf-8') as in_fd:
for line in in_fd:
if line not in generated_output:
raise LostContent(merged_file, line)
def finish_output(changelog, output_file, input_file, merged_files):
"""Write the changelog to the output file.