
    tni<                         d dl Z d dlZd dlmZ d dlmZ d dlmZmZm	Z	m
Z
 d dlmZmZmZmZ  G d de	          Z G d d	e
          Z G d
 de
          ZdS )    N)ClientError)S3CopyFailedError)CompleteMultipartUploadTaskCreateMultipartUploadTaskSubmissionTaskTask)ChunksizeAdjustercalculate_range_parameterget_callbacksget_filtered_dictc            
       l    e Zd ZdZdddddddd	d
d	Zg dZg dZg dZd Zd Z	d Z
d Zd Zd Zd ZdS )CopySubmissionTaskz+Task for submitting tasks to execute a copyIfMatchIfModifiedSinceIfNoneMatchIfUnmodifiedSinceSSECustomerKeySSECustomerAlgorithmSSECustomerKeyMD5RequestPayerExpectedBucketOwner)	CopySourceIfMatchCopySourceIfModifiedSinceCopySourceIfNoneMatchCopySourceIfUnmodifiedSinceCopySourceSSECustomerKeyCopySourceSSECustomerAlgorithmCopySourceSSECustomerKeyMD5r   r   )r   r   r   r   r   r   r   r   r   r   r   r   )	r   r   r   r   r   r   r   MetadataDirectiveTaggingDirective)r   r   r   r   r   c                 F   |j         j        |j         j        |j         j        }|                     |j                  }|j        }|                                D ]\  }	}
|	| j        v r|
|| j        |	         <    |j	        j
        di |}|j                             |d                    |j                             |                    d                     |j         j        |j        k     r|                     |||||           dS |                     |||||           dS )a  
        :param client: The client associated with the transfer manager

        :type config: s3transfer.manager.TransferConfig
        :param config: The transfer config associated with the transfer
            manager

        :type osutil: s3transfer.utils.OSUtil
        :param osutil: The os utility associated to the transfer manager

        :type request_executor: s3transfer.futures.BoundedExecutor
        :param request_executor: The request executor associated with the
            transfer manager

        :type transfer_future: s3transfer.futures.TransferFuture
        :param transfer_future: The transfer future associated with the
            transfer request that tasks are being submitted for
        NContentLengthETag )metasizeetag	call_args)_get_head_object_request_from_copy_sourcecopy_source
extra_argsitemsEXTRA_ARGS_TO_HEAD_ARGS_MAPPINGsource_clienthead_objectprovide_transfer_sizeprovide_object_etaggetmultipart_threshold_submit_copy_request_submit_multipart_request)selfclientconfigosutilrequest_executortransfer_futurer(   head_object_requestr+   paramvalueresponses               N/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/s3transfer/copies.py_submitzCopySubmissionTask._submitS   s   ,  %-#(0 (,6I>>)   
 #-J !+ 0 0 2 2  uD@@@  (<UC ;y.:  % H  66)  
  44X\\&5I5IJJJ $v'AAA%%(8/     **(8/        c                     |j         j        }t          |d          }| j                            |t          | j        ||j        |j        |j        |j	        ||j         j
        dd                     d S )Nprogress)r7   r*   bucketkeyr+   	callbacksr&   T)transfer_coordinatormain_kwargsis_final)r%   r(   r   _transfer_coordinatorsubmitCopyObjectTaskr*   rE   rF   r+   r&   )r6   r7   r8   r9   r:   r;   r(   progress_callbackss           r@   r4   z'CopySubmissionTask._submit_copy_request   s     $(2	 +?JGG 	"))%)%?$#,#8'.$="+"6!3+05    	
 	
 	
 	
 	
rB   c                    |j         j        }i }|j                                        D ]\  }}	|| j        vr|	||<   | j                            |t          | j        ||j        |j	        |d                    }
|j
        }t                      }|                    ||j         j                  }t          t          j        |j         j        t#          |          z                      }g }t%          |d          }t'          d|dz             D ]}|                     |j                  }t+          ||dz
  ||j         j                  |d<   |j         j        |j         j        |d<   |                     ||dz
  ||j         j                  }|j                            d          }|                    | j                            |t5          | j        ||j        |j        |j	        |||||d	d	|
i
                               |                     |j                  }| j                            |t;          | j        ||j        |j	        |d|
|dd                     d S )N)r7   rE   rF   r+   )rH   rI   rD      CopySourceRanger   ChecksumAlgorithm)	r7   r*   rE   rF   part_numberr+   rG   r&   checksum_algorithm	upload_id)rH   rI   pending_main_kwargs)rU   partsT)rH   rI   rV   rJ   )r%   r(   r+   r,   CREATE_MULTIPART_ARGS_BLACKLISTrK   rL   r   rE   rF   multipart_chunksizer	   adjust_chunksizer&   intmathceilfloatr   range_extra_upload_part_argsr
   r'   _get_transfer_sizer2   appendCopyPartTaskr*   _extra_complete_multipart_argsr   )r6   r7   r8   r9   r:   r;   r(   create_multipart_extra_argsr=   valcreate_multipart_future	part_sizeadjuster	num_partspart_futuresrN   rS   extra_part_argsr&   rT   complete_multipart_extra_argss                        r@   r5   z,CopySubmissionTask._submit_multipart_request   s    $(2	 ')##.4466 	9 	9JE3D@@@58+E2"&"<"C"C%%)%?$'.$="=	   #
 #
 .	$&&--+0
 
	 Io*/%	2B2BBCC
 
	
 *?JGG IM22 0	 0	K"::$ O 2Ka$)	2 2O-. #(4#(-   34
 **a$)	 D "+!5!9!9:M!N!N*11$ -1-G&,+4+@&/&6#,=+6*9);$(2D
% 
% ()@-      . )-(K(K )
 )
% 	"))'%)%?$'.$="?	  "9)% %   	
 	
 	
 	
 	
rB   c                     t          |t                    rt          j        |          S t          d| dt	          |           d          )NzLExpecting dictionary formatted: {"Bucket": bucket_name, "Key": key} but got z	 or type .)
isinstancedictcopy	TypeErrortype)r6   r*   s     r@   r)   z<CopySubmissionTask._get_head_object_request_from_copy_source   sh    k4(( 	9[)))F&F F15k1B1BF F F  rB   c                 ,    t          || j                  S N)r   UPLOAD_PART_COPY_ARGSr6   r+   s     r@   r`   z*CopySubmissionTask._extra_upload_part_args*  s     !T-GHHHrB   c                 ,    t          || j                  S rv   )r   COMPLETE_MULTIPART_ARGSrx   s     r@   rd   z1CopySubmissionTask._extra_complete_multipart_args/  s     T-IJJJrB   c                 (    ||dz
  k    r|||z  z
  S |S )NrP   r$   )r6   rh   
part_indexrj   total_transfer_sizes        r@   ra   z%CopySubmissionTask._get_transfer_size2  s+     Q&& '*y*@AArB   N)__name__
__module____qualname____doc__r-   rw   rX   rz   rA   r4   r5   r)   r`   rd   ra   r$   rB   r@   r   r   !   s        55 '%6!.':$4*@':&4
' 
'#  
' 
' 
'#  A A AF
 
 
4n
 n
 n
`  I I I
K K K    rB   r   c                       e Zd ZdZd ZdS )rM   zTask to do a nonmultipart copyc                 J     |j         d|||d| |D ]} ||           dS )a  
        :param client: The client to use when calling PutObject
        :param copy_source: The CopySource parameter to use
        :param bucket: The name of the bucket to copy to
        :param key: The name of the key to copy to
        :param extra_args: A dictionary of any extra arguments that may be
            used in the upload.
        :param callbacks: List of callbacks to call after copy
        :param size: The size of the transfer. This value is passed into
            the callbacks

        )
CopySourceBucketKeybytes_transferredNr$   )copy_object)	r6   r7   r*   rE   rF   r+   rG   r&   callbacks	            r@   _mainzCopyObjectTask._main?  se     	 	
"6s	
 	
>H	
 	
 	
 " 	- 	-HHt,,,,,	- 	-rB   Nr~   r   r   r   r   r$   rB   r@   rM   rM   <  s)        ((- - - - -rB   rM   c                       e Zd ZdZ	 ddZdS )rc   z)Task to upload a part in a multipart copyNc           	         	  |j         d|||||d|}nm# t          $ r`}|j                            di                               d          }|d         }|d         }|dk    rt	          d| d| d	           d
}~ww xY w|D ]} ||	           |d         d         }||d}|
r2d|
                                 }||d         v r|d         |         ||<   |S )a<  
        :param client: The client to use when calling PutObject
        :param copy_source: The CopySource parameter to use
        :param bucket: The name of the bucket to upload to
        :param key: The name of the key to upload to
        :param upload_id: The id of the upload
        :param part_number: The number representing the part of the multipart
            upload
        :param extra_args: A dictionary of any extra arguments that may be
            used in the upload.
        :param callbacks: List of callbacks to call after copy part
        :param size: The size of the transfer. This value is passed into
            the callbacks
        :param checksum_algorithm: The algorithm that was used to create the multipart
            upload

        :rtype: dict
        :returns: A dictionary representing a part::

            {'Etag': etag_value, 'PartNumber': part_number}

            This value can be appended to a list to be used to complete
            the multipart upload. If a checksum is in the response,
            it will also be included.
        )r   r   r   UploadId
PartNumberErrorCoder   r   PreconditionFailedzContents of stored object "z" in bucket "z" did not match expected ETag.Nr   CopyPartResultr#   )r#   r   Checksumr$   )upload_part_copyr   r?   r2   r   upper)r6   r7   r*   rE   rF   rU   rS   r+   rG   r&   rT   r?   e
error_codesrc_key
src_bucketr   r'   part_metadatachecksum_members                       r@   r   zCopyPartTask._mainX  sv   L	.v. &"&   HH  	 	 	4488@@J!%(G$X.J111'%' % %",% % %   	 " 	- 	-HHt,,,,,()&1!%[AA 	E);)A)A)C)CEEO(+;"<<<19:J1K#2o. s    
B AA;;B rv   r   r$   rB   r@   rc   rc   U  s9        33  E E E E E ErB   rc   )rr   r\   botocore.exceptionsr   s3transfer.exceptionsr   s3transfer.tasksr   r   r   r   s3transfer.utilsr	   r
   r   r   r   rM   rc   r$   rB   r@   <module>r      sP     + + + + + + 3 3 3 3 3 3                      X X X X X X X Xv- - - - -T - - -2H H H H H4 H H H H HrB   