Skip to content

Commit 16ba8b7

Browse files
committed
Merge branch 'feature/add_utf_8_decoding' into 'master'
feat(tools): Enforced utf-8 encoding with Python open() functions Closes IDF-10654 See merge request espressif/esp-idf!32303
2 parents 955f7a3 + 2c814ef commit 16ba8b7

File tree

40 files changed

+115
-124
lines changed

40 files changed

+115
-124
lines changed

components/efuse/efuse_table_gen.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ def verify_duplicate_name(self):
126126
field_name = p.field_name + p.group
127127
if field_name != '' and len(duplicates.intersection([field_name])) != 0:
128128
fl_error = True
129-
print('Field at %s, %s, %s, %s have dublicate field_name' %
129+
print('Field at %s, %s, %s, %s have duplicate field_name' %
130130
(p.field_name, p.efuse_block, p.bit_start, p.bit_count))
131131
if fl_error is True:
132132
raise InputError('Field names must be unique')
133133

134134
def check_struct_field_name(self):
135-
# check that stuctured fields have a root field
135+
# check that structured fields have a root field
136136
for p in self:
137137
if '.' in p.field_name:
138138
name = ''
@@ -454,7 +454,7 @@ def process_input_file(file, type_table):
454454

455455
def ckeck_md5_in_file(md5, filename):
456456
if os.path.exists(filename):
457-
with open(filename, 'r') as f:
457+
with open(filename, 'r', encoding='utf-8') as f:
458458
for line in f:
459459
if md5 in line:
460460
return True
@@ -478,12 +478,12 @@ def create_output_files(name, output_table, debug):
478478
if ckeck_md5_in_file(output_table.md5_digest_table, file_c_path) is False:
479479
status('Creating efuse *.h file ' + file_h_path + ' ...')
480480
output = output_table.to_header(file_name)
481-
with open(file_h_path, 'w') as f:
481+
with open(file_h_path, 'w', encoding='utf-8') as f:
482482
f.write(output)
483483

484484
status('Creating efuse *.c file ' + file_c_path + ' ...')
485485
output = output_table.to_c_file(file_name, debug)
486-
with open(file_c_path, 'w') as f:
486+
with open(file_c_path, 'w', encoding='utf-8') as f:
487487
f.write(output)
488488
else:
489489
print('Source files do not require updating correspond to csv file.')

components/esp_security/test_apps/crypto_drivers/main/gen_digital_signature_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def generate_tests_cases(target): # type: (str) -> None
6969

7070
messages = [random.randrange(0, 1 << max_key_size) for x in range(NUM_MESSAGES)]
7171

72-
with open('digital_signature_test_cases.h', 'w') as f:
72+
with open('digital_signature_test_cases.h', 'w', encoding='utf-8') as f:
7373
f.write('/*\n')
7474
year = datetime.datetime.now().year
7575
f.write(' * SPDX-FileCopyrightText: {year} Espressif Systems (Shanghai) CO LTD\n'.format(year=year))

components/esp_system/check_system_init_priorities.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def main() -> None:
5050
glob_iter = glob.glob(os.path.join(idf_path, 'components', '**', f'*.{extension}'), recursive=True)
5151
source_files_iters.append(glob_iter)
5252
for filename in itertools.chain(*source_files_iters):
53-
with open(filename, 'r') as f_obj:
53+
with open(filename, 'r', encoding='utf-8') as f_obj:
5454
file_contents = f_obj.read()
5555
if ESP_SYSTEM_INIT_FN_STR not in file_contents:
5656
continue
@@ -88,7 +88,7 @@ def sort_key(entry: StartupEntry) -> typing.Tuple[str, int, str]:
8888
# 3. Load startup entries list from STARTUP_ENTRIES_FILE, removing comments and empty lines
8989
#
9090
startup_entries_expected_lines = []
91-
with open(os.path.join(idf_path, STARTUP_ENTRIES_FILE), 'r') as startup_entries_expected_file:
91+
with open(os.path.join(idf_path, STARTUP_ENTRIES_FILE), 'r', encoding='utf-8') as startup_entries_expected_file:
9292
for line in startup_entries_expected_file:
9393
if line.startswith('#') or len(line.strip()) == 0:
9494
continue

components/espcoredump/espcoredump.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#
55
# SPDX-License-Identifier: Apache-2.0
66
#
7-
87
import json
98
import logging
109
import os.path
@@ -26,7 +25,7 @@ def get_prefix_map_gdbinit_path(prog_path): # type: (str) -> Any
2625
logging.warning('%s does not exist. Please build the app with "idf.py build"', desc_path)
2726
return ''
2827

29-
with open(desc_path, 'r') as f:
28+
with open(desc_path, 'r', encoding='utf-8') as f:
3029
project_desc = json.load(f)
3130

3231
return project_desc.get('debug_prefix_map_gdbinit')

components/hal/test_apps/crypto/main/key_manager/gen_key_manager_test_cases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def write_to_c_header(init_key: bytes, k1: bytes, k2_info: bytes, k1_encrypted_3
138138
test_data_xts_aes_128: list, k1_encrypted_64: list,
139139
xts_test_data_xts_aes_256: list, pubx: bytes,
140140
puby: bytes, k1_G_0: bytes, k1_G_1: bytes) -> None:
141-
with open('key_manager_test_cases.h', 'w') as file:
141+
with open('key_manager_test_cases.h', 'w', encoding='utf-8') as file:
142142
header_content = """#include <stdint.h>
143143
144144
#define TEST_COUNT 5

components/partition_table/gen_esp32part.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ def main():
676676

677677
if input_is_binary:
678678
output = table.to_csv()
679-
with sys.stdout if args.output == '-' else open(args.output, 'w') as f:
679+
with sys.stdout if args.output == '-' else open(args.output, 'w', encoding='utf-8') as f:
680680
f.write(output)
681681
else:
682682
output = table.to_binary()

components/partition_table/gen_extra_subtypes_inc.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#!/usr/bin/env python
22
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
33
# SPDX-License-Identifier: Apache-2.0
4-
54
import argparse
65

76

87
def gen_header_file(path: str, subtypes: str) -> None:
98
HDR_MESSAGE = '/* Automatically generated file. DO NOT EDIT. */\n\n'
109
PARTTOOL_USAGE = 'If you want to use parttool.py manually, please use the following as an extra argument:'
11-
with open(path, 'w') as f:
10+
with open(path, 'w', encoding='utf-8') as f:
1211
f.write(HDR_MESSAGE)
1312
if subtypes:
1413
f.write('/*\n\t' + PARTTOOL_USAGE + '\n\t')

components/partition_table/parttool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def parse_esptool_args(esptool_args):
9292
partition_table = gen.PartitionTable.from_binary(f.read())
9393

9494
if partition_table is None:
95-
with open(partition_table_file, 'r') as f:
95+
with open(partition_table_file, 'r', encoding='utf-8') as f:
9696
f.seek(0)
9797
partition_table = gen.PartitionTable.from_csv(f.read())
9898
else:

components/ulp/esp32ulp_mapgen.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env python
2-
# esp32ulp_mapgen utility converts a symbol list provided by nm into an export script
3-
# for the linker and a header file.
4-
#
52
# SPDX-FileCopyrightText: 2016-2024 Espressif Systems (Shanghai) CO LTD
63
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# esp32ulp_mapgen utility converts a symbol list provided by nm into an export script
6+
# for the linker and a header file.
77
import argparse
88
import os
99
import textwrap
@@ -64,7 +64,7 @@ def main() -> None:
6464

6565
args = parser.parse_args()
6666

67-
with open(args.outputfile + '.h', 'w') as f_h, open(args.outputfile + '.ld', 'w') as f_ld:
67+
with open(args.outputfile + '.h', 'w', encoding='utf-8') as f_h, open(args.outputfile + '.ld', 'w', encoding='utf-8') as f_ld:
6868
gen_ld_h_from_sym(args.symfile, f_ld, f_h, int(args.base_addr, 0))
6969

7070

conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def real_func(item: str, value: float, target: str) -> None:
316316
"""
317317

318318
def _find_perf_item(operator: str, path: str) -> float:
319-
with open(path) as f:
319+
with open(path, encoding='utf-8') as f:
320320
data = f.read()
321321
match = re.search(fr'#define\s+IDF_PERFORMANCE_{operator}_{item.upper()}\s+([\d.]+)', data)
322322
return float(match.group(1)) # type: ignore

0 commit comments

Comments
 (0)