Updated typehints from str values to bytes

This commit is contained in:
Martin Gaňo
2022-01-03 01:02:16 +01:00
parent f7983fd313
commit 140f5be289
6 changed files with 13 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env python
# SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
import os
@@ -107,7 +107,7 @@ class FATFS:
parent_dir = self.root_directory.recursive_search(path_from_root, self.root_directory)
self.root_directory.new_directory(name=name, parent=parent_dir, path_from_root=path_from_root)
def write_content(self, path_from_root: List[str], content: str) -> None:
def write_content(self, path_from_root: List[str], content: bytes) -> None:
"""
fat fs invokes root directory to recursively find the required file and writes the content
"""
@@ -167,7 +167,7 @@ class FATFS:
normal_path = os.path.normpath(folder_relative_path)
split_path = normal_path.split(os.sep)
if os.path.isfile(real_path):
with open(real_path, "rb") as file:
with open(real_path, 'rb') as file:
content = file.read()
file_name, extension = os.path.splitext(split_path[-1])
extension = extension[1:] # remove the dot from the extension

View File

@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
import os
@@ -42,7 +42,7 @@ class File:
def name_equals(self, name: str, extension: str) -> bool:
return self.name == name and self.extension == extension
def write(self, content: str) -> None:
def write(self, content: bytes) -> None:
self.entry.update_content_size(len(content))
# we assume that the correct amount of clusters is allocated
current_cluster = self._first_cluster
@@ -207,7 +207,7 @@ class Directory:
directory.init_directory()
target_dir.entities.append(directory)
def write_to_file(self, path: List[str], content: str) -> None:
def write_to_file(self, path: List[str], content: bytes) -> None:
"""
Writes to file existing in the directory structure.

View File

@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
import argparse
@@ -18,7 +18,7 @@ def crc32(input_values: List[int], crc: int) -> int:
return binascii.crc32(bytearray(input_values), crc)
def required_clusters_count(cluster_size: int, content: str) -> int:
def required_clusters_count(cluster_size: int, content: bytes) -> int:
# compute number of required clusters for file text
return (len(content) + cluster_size - 1) // cluster_size
@@ -66,7 +66,7 @@ def clean_second_half_byte(bytes_array: bytearray, address: int) -> None:
bytes_array[address] &= 0x0f
def split_content_into_sectors(content: str, sector_size: int) -> List[str]:
def split_content_into_sectors(content: bytes, sector_size: int) -> List[bytes]:
result = []
clusters_cnt = required_clusters_count(cluster_size=sector_size, content=content)

View File

@@ -49,7 +49,6 @@ class FatFSGen(unittest.TestCase):
fatfs.create_file('TESTF', extension='TXT')
fatfs.write_filesystem(CFG['output_file'])
file_system = fatfs.read_filesystem(CFG['output_file'])
self.assertEqual(file_system[0x2000:0x200c], b'TESTF TXT\x20') # check entry name and type
self.assertEqual(file_system[0x1000:0x1006], b'\xf8\xff\xff\xff\x0f\x00') # check fat

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env python
# SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
import os
@@ -132,6 +132,7 @@ class WLFatFSGen(unittest.TestCase):
fatfs.wl_write_filesystem(CFG['output_file'])
with open(CFG['output_file'], 'rb') as fs_file:
file_system = bytearray(fs_file.read())
self.assertEqual(file_system[0x7060:0x7070], b'TESTFIL2 \x00\x00\x01\x00')
self.assertEqual(file_system[0x7070:0x7080], b'!\x00\x00\x00\x00\x00\x01\x00\x01\x00\x05\x00\x0b\x00\x00\x00')
self.assertEqual(file_system[0x8040:0x8050], b'LASTFILE \x00\x00\x01\x00')

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env python
# SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
from typing import List, Optional
@@ -180,7 +180,7 @@ class WLFATFS:
def wl_create_directory(self, name: str, path_from_root: Optional[List[str]] = None) -> None:
self.plain_fatfs.create_directory(name, path_from_root)
def wl_write_content(self, path_from_root: List[str], content: str) -> None:
def wl_write_content(self, path_from_root: List[str], content: bytes) -> None:
self.plain_fatfs.write_content(path_from_root, content)