o
    Rh8                     @   st   d dl Z d dl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 deZG dd deZG dd	 d	eZdS )
    N)CompleteMultipartUploadTaskCreateMultipartUploadTaskSubmissionTaskTask)ChunksizeAdjustercalculate_range_parameterget_callbacksget_filtered_dictc                
   @   sx   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d Zdd Z	dd Z
dd Zdd Zdd Zd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                 C   s   |j jdu r9|j j}| |j}|j}| D ]\}	}
|	| jv r'|
|| j|	 < q|jj	di |}|j 
|d  |j j|jk rK| ||||| 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 )metasize	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multipart_threshold_submit_copy_request_submit_multipart_request)selfclientconfigosutilrequest_executortransfer_futurer!   head_object_requestr$   paramvalueresponser   r   S/home/air/sanwanet/backup_V2/venv/lib/python3.10/site-packages/s3transfer/copies.py_submitP   s6   



zCopySubmissionTask._submitc                 C   sL   |j j}t|d}| j|t| j||j|j|j|j	||j j
ddd d S )Nprogress)r.   r#   bucketkeyr$   	callbacksr    T)transfer_coordinatormain_kwargsis_final)r   r!   r   _transfer_coordinatorsubmitCopyObjectTaskr#   r:   r;   r$   r    )r-   r.   r/   r0   r1   r2   r!   progress_callbacksr   r   r7   r+      s"   
	z'CopySubmissionTask._submit_copy_requestc                 C   sx  |j j}i }|j D ]\}}	|| jvr|	||< q| j|t| j||j|j	|dd}
|j
}t }|||j j}tt|j jt| }g }t|d}td|d D ]F}| |j}t||d ||j j|d< | ||d ||j j}|jd}|| j|t| j||j|j|j	|||||d	d|
id	 qU| |j}| j|t| j||j|j	|d|
|d
dd d S )N)r.   r:   r;   r$   )r=   r>   r9      CopySourceRangeChecksumAlgorithm)	r.   r#   r:   r;   part_numberr$   r<   r    checksum_algorithm	upload_id)r=   r>   pending_main_kwargs)rI   partsT)r=   r>   rJ   r?   )r   r!   r$   r%   CREATE_MULTIPART_ARGS_BLACKLISTr@   rA   r   r:   r;   multipart_chunksizer   adjust_chunksizer    intmathceilfloatr   range_extra_upload_part_argsr   _get_transfer_sizegetappendCopyPartTaskr#   _extra_complete_multipart_argsr   )r-   r.   r/   r0   r1   r2   r!   create_multipart_extra_argsr4   valcreate_multipart_future	part_sizeadjuster	num_partspart_futuresrC   rG   extra_part_argsr    rH   complete_multipart_extra_argsr   r   r7   r,      s   

z,CopySubmissionTask._submit_multipart_requestc                 C   s(   t |tr
t|S td|t|f )NzZExpecting dictionary formatted: {"Bucket": bucket_name, "Key": key} but got %s or type %s.)
isinstancedictcopy	TypeErrortype)r-   r#   r   r   r7   r"     s   


z<CopySubmissionTask._get_head_object_request_from_copy_sourcec                 C      t || jS N)r	   UPLOAD_PART_COPY_ARGSr-   r$   r   r   r7   rT     s   z*CopySubmissionTask._extra_upload_part_argsc                 C   rh   ri   )r	   COMPLETE_MULTIPART_ARGSrk   r   r   r7   rY   #  s   z1CopySubmissionTask._extra_complete_multipart_argsc                 C   s   ||d kr|||  S |S )NrD   r   )r-   r]   
part_indexr_   total_transfer_sizer   r   r7   rU   &  s   z%CopySubmissionTask._get_transfer_sizeN)__name__
__module____qualname____doc__r&   rj   rL   rl   r8   r+   r,   r"   rT   rY   rU   r   r   r   r7   r
      s,    >l
r
   c                   @   s   e Zd ZdZdd ZdS )rB   zTask to do a nonmultipart copyc           	      C   s0   |j d|||d| |D ]}||d q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)	r-   r.   r#   r:   r;   r$   r<   r    callbackr   r   r7   _main3  s   zCopyObjectTask._mainNro   rp   rq   rr   rz   r   r   r   r7   rB   0  s    rB   c                   @   s   e Zd ZdZ	dddZdS )rX   z)Task to upload a part in a multipart copyNc                 C   sx   |j d|||||d|}|D ]}||	d q|d d }||d}|
r:d|
  }||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.
        )rs   rt   ru   UploadId
PartNumberrv   CopyPartResultETag)r   r}   ChecksumNr   )upload_part_copyupper)r-   r.   r#   r:   r;   rI   rG   r$   r<   r    rH   r6   ry   etagpart_metadatachecksum_memberr   r   r7   rz   L  s(   &
zCopyPartTask._mainri   r{   r   r   r   r7   rX   I  s    rX   )re   rP   s3transfer.tasksr   r   r   r   s3transfer.utilsr   r   r   r	   r
   rB   rX   r   r   r   r7   <module>   s     