@@ -369,22 +369,22 @@ def _build_boundary_data(self, files: dict): # pylint: disable=too-many-locals
369369 file_name = field_values [0 ]
370370 file_handle = field_values [1 ]
371371
372- boundary_data = f"--{ boundary_string } \r \n "
373- boundary_data += f'Content-Disposition: form-data; name="{ field_name } "'
372+ boundary_objects .append (
373+ f'--{ boundary_string } \r \n Content-Disposition: form-data; name="{ field_name } "'
374+ )
374375 if file_name is not None :
375- boundary_data += f'; filename="{ file_name } "'
376- boundary_data += "\r \n "
376+ boundary_objects . append ( f'; filename="{ file_name } "' )
377+ boundary_objects . append ( "\r \n " )
377378 if len (field_values ) >= 3 :
378379 file_content_type = field_values [2 ]
379- boundary_data += f"Content-Type: { file_content_type } \r \n "
380+ boundary_objects . append ( f"Content-Type: { file_content_type } \r \n " )
380381 if len (field_values ) >= 4 :
381382 file_headers = field_values [3 ]
382383 for file_header_key , file_header_value in file_headers .items ():
383- boundary_data += f"{ file_header_key } : { file_header_value } \r \n "
384- boundary_data += "\r \n "
385-
386- content_length += len (boundary_data )
387- boundary_objects .append (boundary_data )
384+ boundary_objects .append (
385+ f"{ file_header_key } : { file_header_value } \r \n "
386+ )
387+ boundary_objects .append ("\r \n " )
388388
389389 if hasattr (file_handle , "read" ):
390390 is_binary = False
@@ -400,19 +400,15 @@ def _build_boundary_data(self, files: dict): # pylint: disable=too-many-locals
400400 file_handle .seek (0 , SEEK_END )
401401 content_length += file_handle .tell ()
402402 file_handle .seek (0 )
403- boundary_objects .append (file_handle )
404- boundary_data = ""
405- else :
406- boundary_data = file_handle
407403
408- boundary_data += "\r \n "
409- content_length += len (boundary_data )
410- boundary_objects .append (boundary_data )
404+ boundary_objects .append (file_handle )
405+ boundary_objects .append ("\r \n " )
411406
412- boundary_data = f"--{ boundary_string } --\r \n "
407+ boundary_objects . append ( f"--{ boundary_string } --\r \n " )
413408
414- content_length += len (boundary_data )
415- boundary_objects .append (boundary_data )
409+ for boundary_object in boundary_objects :
410+ if isinstance (boundary_object , str ):
411+ content_length += len (boundary_object )
416412
417413 return boundary_string , content_length , boundary_objects
418414
0 commit comments