@@ -68,16 +68,16 @@ def __init__(self):
6868 self .root_node : _U8Node = _U8Node (0 , 0 , 0 , 0 )
6969 self .imet_header : IMETHeader = IMETHeader ()
7070
71- def load (self , u8_data : bytes ) -> None :
71+ def load (self , u8 : bytes ) -> None :
7272 """
7373 Loads raw U8 data into a new U8 object. This allows for extracting the file and updating its contents.
7474
7575 Parameters
7676 ----------
77- u8_data : bytes
77+ u8 : bytes
7878 The data for the U8 file to load.
7979 """
80- with io .BytesIO (u8_data ) as u8_data :
80+ with io .BytesIO (u8 ) as u8_data :
8181 # Read the first 4 bytes of the file to ensure that it's a U8 archive.
8282 u8_data .seek (0x0 )
8383 self .u8_magic = u8_data .read (4 )
@@ -126,7 +126,7 @@ def load(self, u8_data: bytes) -> None:
126126 # Seek back before the root node so that it gets read with all the rest.
127127 u8_data .seek (u8_data .tell () - 12 )
128128 # Iterate over the number of nodes that the root node lists.
129- for node in range (root_node_size ):
129+ for _ in range (root_node_size ):
130130 node_type = int .from_bytes (u8_data .read (1 ))
131131 node_name_offset = int .from_bytes (u8_data .read (3 ))
132132 node_data_offset = int .from_bytes (u8_data .read (4 ))
@@ -160,7 +160,7 @@ def dump(self) -> bytes:
160160 # This is 0 because the header size DOES NOT include the initial 32 bytes describing the file.
161161 header_size = 0
162162 # Add 12 bytes for each node, since that's how many bytes each one is made up of.
163- for node in range (len (self .u8_node_list )):
163+ for _ in range (len (self .u8_node_list )):
164164 header_size += 12
165165 # Add the number of bytes used for each file/folder name in the string table.
166166 for file_name in self .file_name_list :
@@ -170,13 +170,13 @@ def dump(self) -> bytes:
170170 # Adjust all nodes to place file data in the same order as the nodes. Why isn't it already like this?
171171 current_data_offset = data_offset
172172 current_name_offset = 0
173- for node in range (len (self .u8_node_list )):
174- if self .u8_node_list [node ].type == 0 :
175- self .u8_node_list [node ].data_offset = _align_value (current_data_offset , 32 )
176- current_data_offset += _align_value (self .u8_node_list [node ].size , 32 )
173+ for idx in range (len (self .u8_node_list )):
174+ if self .u8_node_list [idx ].type == 0 :
175+ self .u8_node_list [idx ].data_offset = _align_value (current_data_offset , 32 )
176+ current_data_offset += _align_value (self .u8_node_list [idx ].size , 32 )
177177 # Calculate the name offsets, including the extra 1 for the NULL byte at the end of each name.
178- self .u8_node_list [node ].name_offset = current_name_offset
179- current_name_offset += len (self .file_name_list [node ]) + 1
178+ self .u8_node_list [idx ].name_offset = current_name_offset
179+ current_name_offset += len (self .file_name_list [idx ]) + 1
180180 # Begin joining all the U8 archive data into bytes.
181181 u8_data = b''
182182 # Magic number.
@@ -300,7 +300,7 @@ def _pack_u8_dir(u8_archive: U8Archive, current_path, node_count, parent_node):
300300 return u8_archive , node_count
301301
302302
303- def pack_u8 (input_path , generate_imet = False , imet_titles :List [str ]= None ) -> bytes :
303+ def pack_u8 (input_path , generate_imet = False , imet_titles :List [str ] | None = None ) -> bytes :
304304 """
305305 Packs the provided file or folder into a new U8 archive, and returns the raw file data for it.
306306
@@ -513,13 +513,15 @@ def get_channel_names(self, target_languages: int | List[int]) -> str | List[str
513513 raise ValueError (f"The specified language is not valid!" )
514514 return self .channel_names [target_languages ]
515515 # If multiple channel names were requested.
516- else :
516+ elif type ( target_languages ) == List :
517517 channel_names = []
518518 for lang in target_languages :
519519 if lang not in self .LocalizedTitles :
520520 raise ValueError (f"The specified language at index { target_languages .index (lang )} is not valid!" )
521521 channel_names .append (self .channel_names [lang ])
522522 return channel_names
523+ else :
524+ raise TypeError ("Target languages must be type int or List[int]!" )
523525
524526 def set_channel_names (self , channel_names : Tuple [int , str ] | List [Tuple [int , str ]]) -> None :
525527 """
@@ -544,7 +546,7 @@ def set_channel_names(self, channel_names: Tuple[int, str] | List[Tuple[int, str
544546 f"42 characters!" )
545547 self .channel_names [channel_names [0 ]] = channel_names [1 ]
546548 # If a list of channel names was provided.
547- else :
549+ elif type ( channel_names ) == list :
548550 for name in channel_names :
549551 if name [0 ] not in self .LocalizedTitles :
550552 raise ValueError (f"The target language \" { name [0 ]} \" for the name at index { channel_names .index (name )} "
@@ -553,3 +555,5 @@ def set_channel_names(self, channel_names: Tuple[int, str] | List[Tuple[int, str
553555 raise ValueError (f"The channel name \" { name [1 ]} \" at index { channel_names .index (name )} is too long! "
554556 f"Channel names cannot exceed 42 characters!" )
555557 self .channel_names [name [0 ]] = name [1 ]
558+ else :
559+ raise TypeError ("Channel names must be type Tuple[int, str] or List[Tuple[int, str]]!" )
0 commit comments