Skip to content

Commit c37177a

Browse files
committed
smells
1 parent 94d7c3a commit c37177a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lambdas/mesh_processor/src/converter.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
EXPECTED_BUCKET_OWNER_ACCOUNT = os.getenv("ACCOUNT_ID")
99
DESTINATION_BUCKET_NAME = os.getenv("DESTINATION_BUCKET_NAME")
10+
UNEXPECTED_EOF_ERROR = "Unexpected EOF"
1011

1112
logging.basicConfig(level=logging.INFO)
1213
logger = logging.getLogger()
@@ -15,13 +16,16 @@
1516

1617

1718
def parse_headers(headers_str: str) -> dict[str, str]:
18-
headers = dict(header_str.split(":", 1) for header_str in headers_str.split("\r\n") if ":" in header_str)
19+
headers = dict(
20+
header_str.split(":", 1) for header_str in headers_str.split("\r\n")
21+
if ":" in header_str
22+
) # NOSONAR(S7494) force this to dict
1923
return {k.strip(): v.strip() for k, v in headers.items()}
2024

2125

2226
def parse_header_value(header_value: str) -> tuple[str, dict[str, str]]:
2327
main_value, *params = header_value.split(";")
24-
parsed_params = dict(param.strip().split("=", 1) for param in params)
28+
parsed_params = dict(param.strip().split("=", 1) for param in params) # NOSONAR(S7494) force this to dict
2529
parsed_params = {k: v.strip('"') for k, v in parsed_params.items()}
2630
return main_value, parsed_params
2731

@@ -30,7 +34,7 @@ def read_until_part_start(input_file: BinaryIO, boundary: bytes) -> None:
3034
while line := input_file.readline():
3135
if line == b"--" + boundary + b"\r\n":
3236
return
33-
raise ValueError("Unexpected EOF")
37+
raise ValueError(UNEXPECTED_EOF_ERROR)
3438

3539

3640
def read_headers_bytes(input_file: BinaryIO) -> bytes:
@@ -39,7 +43,7 @@ def read_headers_bytes(input_file: BinaryIO) -> bytes:
3943
if line == b"\r\n":
4044
return headers_bytes
4145
headers_bytes += line
42-
raise ValueError("Unexpected EOF")
46+
raise ValueError(UNEXPECTED_EOF_ERROR)
4347

4448

4549
def read_part_headers(input_file: BinaryIO) -> dict[str, str]:
@@ -67,7 +71,7 @@ def stream_part_body(input_file: BinaryIO, boundary: bytes, output_file: BinaryI
6771
output_file.write(previous_line)
6872

6973
previous_line = line
70-
raise ValueError("Unexpected EOF")
74+
raise ValueError(UNEXPECTED_EOF_ERROR)
7175

7276

7377
def move_file(source_bucket: str, source_key: str, destination_bucket: str, destination_key: str) -> None:

0 commit comments

Comments
 (0)