o
    Àyð`Z4  ã                   @   s¤   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dlm
Z
 d d	lmZ G d
d„ deƒZG dd„ deƒZG dd„ deƒZdS )é    N)ÚTask)ÚSubmissionTask)ÚCreateMultipartUploadTask)ÚCompleteMultipartUploadTask)Úget_callbacks)Úcalculate_range_parameter)Úget_filtered_dict)ÚChunksizeAdjusterc                
   @   sx   e Zd ZdZdddddddd	d
dœ	Zg d¢Zg d¢Zd	d
g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ÚTaggingDirectivec                 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   ú3/usr/lib/python3/dist-packages/s3transfer/copies.pyÚ_submitI   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   sj  |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 ]?}|  |j¡}t||d ||j jƒ|d< |  ||d ||j j¡}| | 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)r.   r#   r:   r;   Úpart_numberr$   r<   r    Ú	upload_id)r=   r>   Úpending_main_kwargs)rG   ÚpartsT)r=   r>   rH   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Ú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   rF   Úextra_part_argsr    Ú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   rR      s   z*CopySubmissionTask._extra_upload_part_argsc                 C   re   rf   )r   ÚCOMPLETE_MULTIPART_ARGSrh   r   r   r7   rV     s   z1CopySubmissionTask._extra_complete_multipart_argsc                 C   s   ||d kr|||  S |S )NrD   r   )r-   rZ   Ú
part_indexr\   Útotal_transfer_sizer   r   r7   rS     s   z%CopySubmissionTask._get_transfer_sizeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r&   rg   rJ   ri   r8   r+   r,   r"   rR   rV   rS   r   r   r   r7   r
      s0    ÷þ6]r
   c                   @   ó   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   Ú_main  s   ÿÿÿzCopyObjectTask._mainN©rl   rm   rn   ro   rx   r   r   r   r7   rB     ó    rB   c                   @   rp   )rU   z)Task to upload a part in a multipart copyc
                 C   sF   |j d|||||dœ|¤Ž}
|D ]}||	d� q|
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 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

        :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.
        )rq   rr   rs   ÚUploadIdÚ
PartNumberrt   ÚCopyPartResultÚETag)r~   r|   Nr   )Úupload_part_copy)r-   r.   r#   r:   r;   rG   rF   r$   r<   r    r6   rw   Úetagr   r   r7   rx   )  s   þþ
zCopyPartTask._mainNry   r   r   r   r7   rU   '  rz   rU   )rb   rN   Ús3transfer.tasksr   r   r   r   Ús3transfer.utilsr   r   r   r	   r
   rB   rU   r   r   r   r7   Ú<module>   s    x