feat(tools): Enforce utf-8 encoding with open() function

This commit is contained in:
Marek Fiala
2024-07-23 15:59:09 +02:00
committed by Rocha Euripedes
parent efebd8831f
commit a0f32ae1a0

View File

@@ -1,11 +1,12 @@
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD # SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0 # SPDX-License-Identifier: Unlicense OR CC0-1.0
import logging import logging
import os import os
import re import re
import ssl import ssl
import sys import sys
from threading import Event, Thread from threading import Event
from threading import Thread
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
import pexpect import pexpect
@@ -47,7 +48,7 @@ def on_message(client, userdata, msg): # type: (mqtt.Client, tuple, mqtt.client
event_client_received_binary.set() event_client_received_binary.set()
return return
recv_binary = binary + '.received' recv_binary = binary + '.received'
with open(recv_binary, 'w') as fw: with open(recv_binary, 'w', encoding='utf-8') as fw:
fw.write(msg.payload) fw.write(msg.payload)
raise ValueError('Received binary (saved as: {}) does not match the original file: {}'.format(recv_binary, binary)) raise ValueError('Received binary (saved as: {}) does not match the original file: {}'.format(recv_binary, binary))