Skip to content

Commit

Permalink
Added better error handling for parsing strings and a setting to chan…
Browse files Browse the repository at this point in the history
…ge default encoding
  • Loading branch information
tw1lac committed Nov 5, 2023
1 parent 95f0370 commit 8ff7609
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions export_mdl/import_stuff/mdx_parser/binary_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ def gets(self, size: int) -> str:
return string_struct.decode(encoding=self.default_enc)
except UnicodeDecodeError:
for enc in constants.ENCODINGS.values():
string = self.try_get_encoded_string(string_struct, enc)
string = self.try_get_decoded_string(string_struct, enc)
if string is not None:
return string
return str(string_struct)

def try_get_encoded_string(self, string_struct: bytes, encoding: str):
def try_get_decoded_string(self, string_struct: bytes, encoding: str):
try:
return string_struct.decode(encoding=encoding)
except UnicodeError:
Expand Down

0 comments on commit 8ff7609

Please sign in to comment.