B 劇c!5@stddlZddlZddlmZmZmZmZddlmZm Z m Z m Z GdddeZ GdddeZ Gdd d eZdS) N)CompleteMultipartUploadTaskCreateMultipartUploadTaskSubmissionTaskTask)ChunksizeAdjustercalculate_range_parameter get_callbacksget_filtered_dictc @seZdZdZdddddddd d d Zd d ddddddddd d g Zd d dddddddg Zd d gZddZddZ ddZ ddZ ddZ dd Z d!d"Zd#S)$CopySubmissionTaskz+Task for submitting tasks to execute a copyZIfMatchZIfModifiedSinceZ IfNoneMatchZIfUnmodifiedSinceZSSECustomerKeyZSSECustomerAlgorithmZSSECustomerKeyMD5 RequestPayerExpectedBucketOwner) CopySourceIfMatchCopySourceIfModifiedSinceCopySourceIfNoneMatchCopySourceIfUnmodifiedSinceCopySourceSSECustomerKeyCopySourceSSECustomerAlgorithmCopySourceSSECustomerKeyMD5r r r rrrrrrZMetadataDirectiveZTaggingDirectivec Cs|jjdkrr|jj}||j}|j}x,|D] \} } | |jkr0| ||j| <q0W|jj f|} |j | d|jj|j kr| |||||n| |||||dS)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 NZ ContentLength)metasize call_args)_get_head_object_request_from_copy_source copy_source extra_argsitemsEXTRA_ARGS_TO_HEAD_ARGS_MAPPINGZ source_clientZ head_objectZprovide_transfer_sizeZmultipart_threshold_submit_copy_request_submit_multipart_request) selfclientconfigosutilrequest_executortransfer_futurerZhead_object_requestrparamvalueresponser'l/private/var/folders/8c/hx9_v10d5x38qmnzt13b7b8j1k3n5b/T/pip-target-x6xd5gna/lib/python/s3transfer/copies.py_submitJs"   zCopySubmissionTask._submitc CsL|jj}t|d}|j|t|j||j|j|j|j ||jj ddddS)Nprogress)rrbucketkeyr callbacksrT)transfer_coordinator main_kwargsis_final) rrr_transfer_coordinatorsubmitCopyObjectTaskrr+r,rr)rrr r!r"r#rprogress_callbacksr'r'r(rs  z'CopySubmissionTask._submit_copy_requestcCsr|jj}i}x(|jD]\}} ||jkr| ||<qW|j|t|j||j|j |dd} |j } t } | | |jj } tt|jj t| } g}t|d}xtd| dD]~}||j}t| |d| |jj |d<|| |d| |jj }||j|t|j||j|j|j ||||dd| idqW||j}|j|t|j||j|j |d| |d d d dS) N)rr+r,r)r.r/r*ZCopySourceRange)rrr+r, part_numberrr-r upload_id)r.r/pending_main_kwargs)r7partsT)r.r/r8r0)rrrrCREATE_MULTIPART_ARGS_BLACKLISTr1r2rr+r,Zmultipart_chunksizerZadjust_chunksizerintmathceilfloatrrange_extra_upload_part_argsr_get_transfer_sizeappend CopyPartTaskr_extra_complete_multipart_argsr)rrr r!r"r#rZcreate_multipart_extra_argsr$valZcreate_multipart_future part_sizeZadjuster num_partsZ part_futuresr4r6Zextra_part_argsrZcomplete_multipart_extra_argsr'r'r(rsz     z,CopySubmissionTask._submit_multipart_requestcCs,t|trt|Std|t|fdS)NzZExpecting dictionary formatted: {"Bucket": bucket_name, "Key": key} but got %s or type %s.) isinstancedictcopy TypeErrortype)rrr'r'r(r s   zi r c@seZdZdZddZdS)r3zTask to do a nonmultipart copyc Cs4|jf|||d|x|D]}||dqWdS)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 ) CopySourceBucketKey)bytes_transferredN)Z copy_object) rrrr+r,rr-rcallbackr'r'r(_main*s zCopyObjectTask._mainN)rOrPrQrRrXr'r'r'r(r3'sr3c@seZdZdZddZdS)rCz)Task to upload a part in a multipart copyc CsJ|jf|||||d|} x|D]} | | dq"W| dd} | |dS)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. )rSrTrUZUploadId PartNumber)rVZCopyPartResultETag)rZrY)Zupload_part_copy) rrrr+r,r7r6rr-rr&rWetagr'r'r(rXCs"  zCopyPartTask._mainN)rOrPrQrRrXr'r'r'r(rC@srC)rJr<Zs3transfer.tasksrrrrZs3transfer.utilsrrrr r r3rCr'r'r'r( s