
    3                         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e      Z G d de      Z G d de      Zy)    N)Task)SubmissionTask)CreateMultipartUploadTask)CompleteMultipartUploadTask)get_callbacks)calculate_range_parameter)get_filtered_dict)ChunksizeAdjusterc            	       f    e Zd ZdZdddddddd	d
Zg dZg dZd	gZd Zd Z	d Z
d Zd Zd Zd Zy)CopySubmissionTaskz+Task for submitting tasks to execute a copyIfMatchIfModifiedSinceIfNoneMatchIfUnmodifiedSinceSSECustomerKeySSECustomerAlgorithmSSECustomerKeyMD5RequestPayer)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   MetadataDirectiveTaggingDirectivec                 ,   |j                   j                  |j                   j                  }| j                  |j                        }|j
                  }|j                         D ]&  \  }	}
|	| j                  v s|
|| j                  |	   <   (  |j                  j                  di |}|j                   j                  |d          |j                   j                  |j                  k  r| j                  |||||       y| j                  |||||       y)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responses               $lib/third_party/s3transfer/copies.py_submitzCopySubmissionTask._submitF   s'   * $$, (,,66I>>))+   #--J !+ 0 0 2uD@@@GL (<<UCE !3
 ;y..:: '%'H  66)+
 $$v'A'AA%%(8/K **(8/K    c                 4   |j                   j                  }t        |d      }| j                  j	                  |t        | j                  ||j                  |j                  |j                  |j                  ||j                   j                  dd             y )Nprogress)r0   r%   bucketkeyr&   	callbacksr"   T)transfer_coordinatormain_kwargsis_final)r!   r#   r   _transfer_coordinatorsubmitCopyObjectTaskr%   r>   r?   r&   r"   )r/   r0   r1   r2   r3   r4   r#   progress_callbackss           r9   r-   z'CopySubmissionTask._submit_copy_request|   s    #((22	 +?JG 	""))%)%?%?$#,#8#8'..$=="+"6"6!3+0055 	
r;   c                    |j                   j                  }i }|j                  j                         D ]  \  }}	|| j                  vs|	||<    | j
                  j                  |t        | j
                  ||j                  |j                  |d            }
|j                  }t               }|j                  ||j                   j                        }t        t        j                   |j                   j                  t#        |      z              }g }t%        |d      }t'        d|dz         D ]  }| j)                  |j                        }t+        ||dz
  ||j                   j                        |d<   | j-                  ||dz
  ||j                   j                        }|j/                  | j
                  j                  |t1        | j
                  ||j2                  |j                  |j                  ||||dd|
i                    | j5                  |j                        }| j
                  j                  |t7        | j
                  ||j                  |j                  |d|
|d	d
             y )N)r0   r>   r?   r&   )rA   rB   r=      CopySourceRange)r0   r%   r>   r?   part_numberr&   r@   r"   	upload_id)rA   rB   pending_main_kwargs)rL   partsT)rA   rB   rM   rC   )r!   r#   r&   r'   CREATE_MULTIPART_ARGS_BLACKLISTrD   rE   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/   r0   r1   r2   r3   r4   r#   create_multipart_extra_argsr6   valcreate_multipart_future	part_sizeadjuster	num_partspart_futuresrG   rK   extra_part_argsr"   complete_multipart_extra_argss                       r9   r.   z,CopySubmissionTask._submit_multipart_request   s|   #((22	 ')##..446JE3D@@@58+E2 7 #'"<"<"C"C%%)%?%?$'..$=="=	#
 ..	$&--++002	IIo**//%	2BBCE	 *?JG IM2K"::$$&O
 2K;q=)_5I5I5N5N2PO-. **;q=)_5I5I5N5ND **11$ -1-G-G&,+4+@+@&/&6&6#,==+6*9);$(	% ()@- 3F )-(K(K  )"% 	""))'%)%?%?$'..$=="?	 "9)% 	
r;   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)r/   r%   s     r9   r$   z<CopySubmissionTask._get_head_object_request_from_copy_source   s9    k4(99[)) [ 13 r;   c                 .    t        || j                        S N)r	   UPLOAD_PART_COPY_ARGSr/   r&   s     r9   rW   z*CopySubmissionTask._extra_upload_part_args   s     !T-G-GHHr;   c                 .    t        || j                        S rm   )r	   COMPLETE_MULTIPART_ARGSro   s     r9   r[   z1CopySubmissionTask._extra_complete_multipart_args  s     T-I-IJJr;   c                 &    ||dz
  k(  r|||z  z
  S |S )NrI   r    )r/   r_   
part_indexra   total_transfer_sizes        r9   rX   z%CopySubmissionTask._get_transfer_size  s&    Q& '*y*@AAr;   N)__name__
__module____qualname____doc__r(   rn   rO   rq   r:   r-   r.   r$   rW   r[   rX   r    r;   r9   r   r      sm    5 '%6!.':$4*@':&	'#
'# 	4Kl
2[
z	I
Kr;   r   c                       e Zd ZdZd Zy)rF   zTask to do a nonmultipart copyc                 P     |j                   d|||d| |D ]  } ||        y)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/   r0   r%   r>   r?   r&   r@   r"   callbacks	            r9   _mainzCopyObjectTask._main  s=     	 	J"6s	J>H	J!Ht, "r;   Nru   rv   rw   rx   r   r    r;   r9   rF   rF     s
    (-r;   rF   c                       e Zd ZdZd Zy)rZ   z)Task to upload a part in a multipart copyc
           	      l     |j                   d|||||d|}
|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 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.
        )r{   r|   r}   UploadId
PartNumberr~   CopyPartResultETag)r   r   r    )upload_part_copy)r/   r0   r%   r>   r?   rL   rK   r&   r@   r"   r8   r   etags                r9   r   zCopyPartTask._main&  sa    0 +6** F"6s;F:DF "Ht, "()&1K88r;   Nr   r    r;   r9   rZ   rZ   $  s
    39r;   rZ   )ri   rS   s3transfer.tasksr   r   r   r   s3transfer.utilsr   r   r	   r
   r   rF   rZ   r    r;   r9   <module>r      sL      ! + 6 8 * 6 . .q qh-T -, 94  9r;   