o d!5@stddlZddlZddlmZmZmZmZddlmZm Z m Z m Z GdddeZ GdddeZ Gdd d eZdS) N)CompleteMultipartUploadTaskCreateMultipartUploadTaskSubmissionTaskTask)ChunksizeAdjustercalculate_range_parameter get_callbacksget_filtered_dictc @sxeZdZdZdddddddd d d Zgd Zgd Zd d gZddZddZ ddZ ddZ ddZ ddZ ddZdS)CopySubmissionTaskz+Task for submitting tasks to execute a copyZIfMatchZIfModifiedSinceZ IfNoneMatchZIfUnmodifiedSinceSSECustomerKeySSECustomerAlgorithmSSECustomerKeyMD5 RequestPayerExpectedBucketOwner) CopySourceIfMatchCopySourceIfModifiedSinceCopySourceIfNoneMatchCopySourceIfUnmodifiedSinceCopySourceSSECustomerKeyCopySourceSSECustomerAlgorithmCopySourceSSECustomerKeyMD5rr) rrrrrrrr r r rr) rrrrrrrZMetadataDirectiveZTaggingDirectivec Cs|jjdur9|jj}||j}|j}|D]\} } | |jvr'| ||j| <q|jj di|} |j | d|jj|j krK| |||||dS| |||||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_requestrparamvalueresponserrl/private/var/folders/v1/_jykv66s6qd26_69j1njbrl80000gr/T/pip-target-p1gutpg6/lib/python/s3transfer/copies.py_submitJs6     zCopySubmissionTask._submitc CsL|jj}t|d}|j|t|j||j|j|j|j ||jj ddddS)Nprogress)r#rbucketkeyr callbacksrT)transfer_coordinator main_kwargsis_final) rrr_transfer_coordinatorsubmitCopyObjectTaskrr.r/rr)r"r#r$r%r&r'rprogress_callbacksrrr+r s"  z'CopySubmissionTask._submit_copy_requestcCsj|jj}i}|jD] \}} ||jvr| ||<q |j|t|j||j|j |dd} |j } t } | | |jj } tt|jj t| } g}t|d}td| dD]?}||j}t| |d| |jj |d<|| |d| |jj }||j|t|j||j|j|j ||||dd| idqU||j}|j|t|j||j|j |d| |d d d dS) N)r#r.r/r)r1r2r-ZCopySourceRange)r#rr.r/ part_numberrr0r upload_id)r1r2pending_main_kwargs)r:partsT)r1r2r;r3)rrrrCREATE_MULTIPART_ARGS_BLACKLISTr4r5rr.r/Zmultipart_chunksizerZadjust_chunksizerintmathceilfloatrrange_extra_upload_part_argsr_get_transfer_sizeappend CopyPartTaskr_extra_complete_multipart_argsr)r"r#r$r%r&r'rZcreate_multipart_extra_argsr(valZcreate_multipart_future part_sizeZadjuster num_partsZ part_futuresr7r9Zextra_part_argsrZcomplete_multipart_extra_argsrrr+r!s   z,CopySubmissionTask._submit_multipart_requestcCs(t|tr t|Std|t|f)NzZExpecting dictionary formatted: {"Bucket": bucket_name, "Key": key} but got %s or type %s.) isinstancedictcopy TypeErrortype)r"rrrr+r s   zi  r c@eZdZdZddZdS)r6zTask to do a nonmultipart copyc Cs0|jd|||d||D]}||dqdS)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 ) CopySourceBucketKeyZbytes_transferredNr)Z copy_object) r"r#rr.r/rr0rcallbackrrr+_main*s zCopyObjectTask._mainNrUrVrWrXr_rrrr+r6' r6c@rY)rFz)Task to upload a part in a multipart copyc CsF|jd|||||d|} |D]} | | dq| 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. )rZr[r\ZUploadId PartNumberr]ZCopyPartResultETag)rcrbNr)Zupload_part_copy) r"r#rr.r/r:r9rr0rr*r^etagrrr+r_Cs"   zCopyPartTask._mainNr`rrrr+rF@rarF)rMr?Zs3transfer.tasksrrrrZs3transfer.utilsrrrr r r6rFrrrr+s