o
    Ďi<                     @   s   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 de	ZG dd	 d	e
ZG d
d de
ZdS )    N)ClientError)S3CopyFailedError)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 s|j jdu rH|j j}| |j}|j}| D ]\}	}
|	| jv r-|
|| j|	 < q|j	j
di |}|j |d  |j |d |j j|jk rZ| ||||| 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responser!   r!   M/home/jeff/fluffinator/venv/lib/python3.10/site-packages/s3transfer/copies.py_submitS   s:   



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)r4   r'   bucketkeyr(   	callbacksr#   T)transfer_coordinatormain_kwargsis_final)r"   r%   r
   _transfer_coordinatorsubmitCopyObjectTaskr'   r@   rA   r(   r#   )r3   r4   r5   r6   r7   r8   r%   progress_callbacksr!   r!   r=   r1      s"   
	z'CopySubmissionTask._submit_copy_requestc                 C   s  |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 ]R}| |j}t||d ||j j|d< |j jd urv|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)r4   r@   rA   r(   )rC   rD   r?      CopySourceRanger   ChecksumAlgorithm)	r4   r'   r@   rA   part_numberr(   rB   r#   checksum_algorithm	upload_id)rC   rD   pending_main_kwargs)rO   partsT)rC   rD   rP   rE   )r"   r%   r(   r)   CREATE_MULTIPART_ARGS_BLACKLISTrF   rG   r   r@   rA   multipart_chunksizer   adjust_chunksizer#   intmathceilfloatr
   range_extra_upload_part_argsr	   r$   _get_transfer_sizer/   appendCopyPartTaskr'   _extra_complete_multipart_argsr   )r3   r4   r5   r6   r7   r8   r%   create_multipart_extra_argsr:   valcreate_multipart_future	part_sizeadjuster	num_partspart_futuresrI   rM   extra_part_argsr#   rN   complete_multipart_extra_argsr!   r!   r=   r2      s   

z,CopySubmissionTask._submit_multipart_requestc                 C   s.   t |tr
t|S td| dt| d)NzLExpecting dictionary formatted: {"Bucket": bucket_name, "Key": key} but got z	 or type .)
isinstancedictcopy	TypeErrortype)r3   r'   r!   r!   r=   r&      s   

z<CopySubmissionTask._get_head_object_request_from_copy_sourcec                 C      t || jS N)r   UPLOAD_PART_COPY_ARGSr3   r(   r!   r!   r=   rZ   *  s   z*CopySubmissionTask._extra_upload_part_argsc                 C   rn   ro   )r   COMPLETE_MULTIPART_ARGSrq   r!   r!   r=   r^   /  s   z1CopySubmissionTask._extra_complete_multipart_argsc                 C   s   ||d kr|||  S |S )NrJ   r!   )r3   rb   
part_indexrd   total_transfer_sizer!   r!   r=   r[   2  s   z%CopySubmissionTask._get_transfer_sizeN)__name__
__module____qualname____doc__r*   rp   rR   rr   r>   r1   r2   r&   rZ   r^   r[   r!   r!   r!   r=   r   !   s,    Cp
r   c                   @   s   e Zd ZdZdd ZdS )rH   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)	r3   r4   r'   r@   rA   r(   rB   r#   callbackr!   r!   r=   _main?  s   zCopyObjectTask._mainNru   rv   rw   rx   r   r!   r!   r!   r=   rH   <  s    rH   c                   @   s   e Zd ZdZ	dddZdS )r]   z)Task to upload a part in a multipart copyNc              
   C   s   z|j d|||||d|}W n. ty> } z"|jdi d}|d }|d }|dkr9td| d| d	 d
}~ww |D ]}||	d qA|d d }||d}|
rkd|
  }||d v rk|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.
        )ry   rz   r{   UploadId
PartNumberErrorCoder{   rz   PreconditionFailedzContents of stored object "z" in bucket "z" did not match expected ETag.Nr|   CopyPartResultr    )r    r   Checksumr!   )upload_part_copyr   r<   r/   r   upper)r3   r4   r'   r@   rA   rO   rM   r(   rB   r#   rN   r<   e
error_codesrc_key
src_bucketr   r$   part_metadatachecksum_memberr!   r!   r=   r   X  sD   &

zCopyPartTask._mainro   r   r!   r!   r!   r=   r]   U  s    r]   )rk   rV   botocore.exceptionsr   s3transfer.exceptionsr   s3transfer.tasksr   r   r   r   s3transfer.utilsr   r	   r
   r   r   rH   r]   r!   r!   r!   r=   <module>   s     