@@ -369,22 +369,22 @@ def _build_boundary_data(self, files: dict): # pylint: disable=too-many-locals
369
369
file_name = field_values [0 ]
370
370
file_handle = field_values [1 ]
371
371
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
+ )
374
375
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 " )
377
378
if len (field_values ) >= 3 :
378
379
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 " )
380
381
if len (field_values ) >= 4 :
381
382
file_headers = field_values [3 ]
382
383
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 " )
388
388
389
389
if hasattr (file_handle , "read" ):
390
390
is_binary = False
@@ -400,19 +400,15 @@ def _build_boundary_data(self, files: dict): # pylint: disable=too-many-locals
400
400
file_handle .seek (0 , SEEK_END )
401
401
content_length += file_handle .tell ()
402
402
file_handle .seek (0 )
403
- boundary_objects .append (file_handle )
404
- boundary_data = ""
405
- else :
406
- boundary_data = file_handle
407
403
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 " )
411
406
412
- boundary_data = f"--{ boundary_string } --\r \n "
407
+ boundary_objects . append ( f"--{ boundary_string } --\r \n " )
413
408
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 )
416
412
417
413
return boundary_string , content_length , boundary_objects
418
414
0 commit comments