77
88EXPECTED_BUCKET_OWNER_ACCOUNT = os .getenv ("ACCOUNT_ID" )
99DESTINATION_BUCKET_NAME = os .getenv ("DESTINATION_BUCKET_NAME" )
10+ UNEXPECTED_EOF_ERROR = "Unexpected EOF"
1011
1112logging .basicConfig (level = logging .INFO )
1213logger = logging .getLogger ()
1516
1617
1718def 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
2226def 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
3640def 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
4549def 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
7377def move_file (source_bucket : str , source_key : str , destination_bucket : str , destination_key : str ) -> None :
0 commit comments