From c8b4f301355d60acfe1abe0a26e48057ec2db456 Mon Sep 17 00:00:00 2001 From: "Nathan-J. Hirschauer" Date: Sun, 11 Jun 2023 20:37:06 +0200 Subject: [PATCH] [8DOT3] Improve test coverage, removing unused exception handling os.path.splitext always returns a tuple with two elements, so IndexError cannot be raised. --- pyfatfs/EightDotThree.py | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/pyfatfs/EightDotThree.py b/pyfatfs/EightDotThree.py index 64062fc..57d0ac3 100644 --- a/pyfatfs/EightDotThree.py +++ b/pyfatfs/EightDotThree.py @@ -214,23 +214,17 @@ def map_chars(name: bytes) -> bytes: return _name dir_name = dir_name.upper() - try: - # Shorten to 8 chars; strip invalid characters - basename = os.path.splitext(dir_name)[0][0:8].strip() - basename = basename.encode(parent_dir_entry._encoding, - errors="replace") - basename = map_chars(basename).decode(parent_dir_entry._encoding) - except IndexError: - basename = "" - - try: - # Shorten to 3 chars; strip invalid characters - extname = os.path.splitext(dir_name)[1][1:4].strip() - extname = extname.encode(parent_dir_entry._encoding, - errors="replace") - extname = map_chars(extname).decode(parent_dir_entry._encoding) - except IndexError: - extname = "" + # Shorten to 8 chars; strip invalid characters + basename = os.path.splitext(dir_name)[0][0:8].strip() + basename = basename.encode(parent_dir_entry._encoding, + errors="replace") + basename = map_chars(basename).decode(parent_dir_entry._encoding) + + # Shorten to 3 chars; strip invalid characters + extname = os.path.splitext(dir_name)[1][1:4].strip() + extname = extname.encode(parent_dir_entry._encoding, + errors="replace") + extname = map_chars(extname).decode(parent_dir_entry._encoding) if len(extname) == 0: extsep = ""