
    "hjRY                         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	m
Z
mZmZ d dlmZmZmZmZ  G d de      Z G d	 d
e	      Z G d de      Z G d de      Zy)    N)	parse_qsl)ClientError)S3CopyFailedError)CompleteMultipartUploadTaskCreateMultipartUploadTaskSubmissionTaskTask)ChunksizeAdjustercalculate_range_parameterget_callbacksget_filtered_dictc            
           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g dZd	d
gZ	g dZ
d	d
gZd	d
gZg dZd Zd Z	 	 d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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AnnotationDirectiveTagging)CacheControlContentDispositionContentEncodingContentLanguageContentTypeExpiresMetadata)r   r   r   r   r   )r   r   ChecksumAlgorithmc           	      F   i }|j                   j                  }d}t        |j                  t              r|j                  j                  d      }|j                   j                  |j                   j                  | j                  |j                        }	|j                  }
|
j                         D ]&  \  }}|| j                  v s||	| j                  |   <   (  |j                  j                  di |	}|j                   j                  |d          |j                   j                  |j                  d             | j!                  |      }|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	VersionIdContentLengthETag)source_version_id )meta	call_args
isinstancecopy_sourcedictgetsizeetag)_get_head_object_request_from_copy_source
extra_argsitemsEXTRA_ARGS_TO_HEAD_ARGS_MAPPINGsource_clienthead_objectprovide_transfer_sizeprovide_object_etag_extract_preserved_metadatamultipart_threshold_submit_copy_request_submit_multipart_request)selfclientconfigosutilrequest_executortransfer_futurepreserved_metadatar3   r0   head_object_requestr;   paramvalueresponses                 O/root/.hermes/SkillClaw/.venv/lib/python3.12/site-packages/s3transfer/copies.py_submitzCopySubmissionTask._submito   s   *  #((22	 i++T2 ) 5 5 9 9+ F  %%-##((0 >>))  
 #--J !+ 0 0 2 uD@@@  (<<UC ;y..:: %H   66)
   44X\\&5IJ!%!A!A(!K $$v'A'AA%%(8/ ** ""3 +     c                 4   |j                   j                  }t        |d      }| j                  j	                  |t        | j                  ||j                  |j                  |j                  |j                  ||j                   j                  dd             y )Nprogress)rG   r5   bucketkeyr;   	callbacksr8   T)transfer_coordinatormain_kwargsis_final)r2   r3   r   _transfer_coordinatorsubmitCopyObjectTaskr5   rV   rW   r;   r8   )rF   rG   rH   rI   rJ   rK   r3   progress_callbackss           rQ   rD   z'CopySubmissionTask._submit_copy_request   s     $((22	 +?JG 	""))%)%?%?$#,#8#8'..$=="+"6"6!3+0055 	
rS   Nc                    |j                   j                  }| j                  |j                  |xs i       }	i }
|	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                   j.                  |j                   j.                  |d<   | j1                  ||dz
  ||j                   j                        }|j                  j3                  d      }|j5                  | j                  j                  |t7        | j                  ||j8                  |j                  |j                  |||||d	d	|i
                   ) | j;                  |j                        }| j                  j                  |t=        | j                  ||j                  |j                  |||d||dd             y )N)rG   rV   rW   r;   )rY   rZ   rU      CopySourceRanger   r+   )	rG   r5   rV   rW   part_numberr;   rX   r8   checksum_algorithm	upload_id)rY   rZ   pending_main_kwargs)rG   rV   rW   r;   r3   r0   )re   partsT)rY   rZ   rf   r[   )r2   r3   _apply_preserved_metadatar;   r<   CREATE_MULTIPART_ARGS_BLACKLISTr\   r]   r   rV   rW   multipart_chunksizer
   adjust_chunksizer8   intmathceilfloatr   range_extra_upload_part_argsr   r9   _get_transfer_sizer7   appendCopyPartTaskr5   _extra_complete_multipart_argsCopyCompleteMultipartUploadTask)rF   rG   rH   rI   rJ   rK   rL   r0   r3   merged_extra_argscreate_multipart_extra_argsrN   valcreate_multipart_future	part_sizeadjuster	num_partspart_futuresr_   rc   extra_part_argsr8   rd   complete_multipart_extra_argss                           rQ   rE   z,CopySubmissionTask._submit_multipart_request   s    $((22	 ::  "4":
 ')#+113 	9JE3D@@@58+E2	9 #'"<"<"C"C%%)%?%?$'..$=="=	#
 ..	$&--++00
	 IIo**//%	2BBC
	
 *?JG IM2 0	K"::$$O 2Ka$$))	2O-. ##((4#((--   34
 **a$$))	D "+!5!5!9!9:M!N**11$ -1-G-G&,+4+@+@&/&6&6#,==+6*9);$(2D
% ()@-70	d )-(K(K  )
%
 	""))+%)%?%?$'..$=="?!*): "9)% 	
rS   c                 F    i }| j                   D ]  }||v s||   ||<    |S N)PRESERVED_METADATA_FIELDS)rF   head_object_response	preservedfields       rQ   rB   z.CopySubmissionTask._extract_preserved_metadataT  s<    	33 	?E,,#7#>	% 	? rS   c                     |j                  d      dk(  r|S |j                         D ci c]  \  }}|| j                  vr|| }}}|j                  |       |S c c}}w )Nr    REPLACE)r7   r<   r   update)rF   r;   rL   kvresults         rQ   rh   z,CopySubmissionTask._apply_preserved_metadata[  ss     >>-.); #((*
1666 qD
 

 	()
s   A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 .)r4   r6   copy	TypeErrortype)rF   r5   s     rQ   r:   z<CopySubmissionTask._get_head_object_request_from_copy_sourcei  sF    k4(99[))&-yk1B0C1F rS   c                 .    t        || j                        S r   )r   UPLOAD_PART_COPY_ARGSrF   r;   s     rQ   rq   z*CopySubmissionTask._extra_upload_part_argss  s     !T-G-GHHrS   c                 .    t        || j                        S r   )r   COMPLETE_MULTIPART_ARGSr   s     rQ   ru   z1CopySubmissionTask._extra_complete_multipart_argsx  s     T-I-IJJrS   c                 &    ||dz
  k(  r|||z  z
  S |S )Nra   r1   )rF   r{   
part_indexr}   total_transfer_sizes        rQ   rr   z%CopySubmissionTask._get_transfer_size{  s(     Q& '*y*@AArS   )NN)__name__
__module____qualname____doc__r=   r   ri   r   r   GET_OBJECT_TAGGING_ARGSPUT_OBJECT_TAGGING_ARGSLIST_OBJECT_ANNOTATIONS_ARGSGET_OBJECT_ANNOTATION_ARGSPUT_OBJECT_ANNOTATION_ARGSrR   rD   rE   rB   rh   r:   rq   ru   rr   r1   rS   rQ   r   r   "   s    5 '%6!.':$4*@':&4
'#'#!  ./DE
 %34I#J "02G!H"L\
B  {
zI
KrS   r   c                   "    e Zd ZdZd Zd Zd Zy)rv   zCompleteMultipartUpload variant that also applies tags and annotations.

    After the destination object is finalized, copies/applies tags and
    annotations inline. Errors during apply propagate as task failures.
    c	                      |j                   d|||d|id|}	|	j                  d      }
|	j                  d      }| j                  ||||       | j                  |||||
       y )NParts)BucketKeyUploadIdMultipartUploadr/   r-   r1   )complete_multipart_uploadr7   _apply_tags_apply_annotations)rF   rG   rV   rW   re   rg   r;   r3   r0   rP   	dest_etagdest_version_ids               rQ   _mainz%CopyCompleteMultipartUploadTask._main  s     4633 
$e,	

 
 LL(	",,{3,=OI0/9	
rS   c                 @   |j                   }|j                  d      }|dvry |dk(  rm|j                  d   |j                  d   dt        |t        j
                        }|r||d<    |j                  j                  di |j                  dg       }n2t        |j                  d	d
      d      D 	
cg c]
  \  }	}
|	|
d }}	}
|sy |j                  |j                  d|idt        |t        j                        }|r||d<    |j                  di | y c c}
}	w )Nr!   )COPYr   r   r   r   r   r   r-   TagSetr#    T)keep_blank_values)r   Value)r   r   r#   r1   )r;   r7   r5   r   r   r   r>   get_object_taggingr   rV   rW   r   put_object_tagging)rF   rG   r3   r0   r   r;   	directive
src_kwargstag_setr   r   
put_kwargss               rQ   r   z+CopyCompleteMultipartUploadTask._apply_tags  sU    ))
NN#56	//#//9 ,,U3 $ 2 J JJ !*;
;'@i--@@ c(B  &NN9b1&*Aq A&G  &&== '*
  .FF	

 &5J{#!!!/J/'s   5Dc                 z   |j                   }|j                  d      dk7  ry |j                  d   |j                  d   d}|r||d<   i |t        |t        j
                        }i |t        |t        j                        }	t        |t        j                        }
 |j                  j                  di |}g }i }|j                  dg       D ]  }|d   } |j                  j                  di |	d|i}|j                  |j                  ||d	   j                         d
|
}|r||d<   |r||d<   	  |j                  di | |j                  |        |rEt#        d|j                   d|j                   d| dt%        |j'                                d| 
      y # t         $ r}|||<   Y d }~d }~ww xY w)Nr"   r   r   r   r   r-   AnnotationsAnnotationNameAnnotationPayload)r   r   r   r   ObjectIfMatchz#Failed to copy annotations to s3:///z. Succeeded: z
. Failed: z
. Errors: r1   )r;   r7   r5   r   r   r   r   r   r>   list_object_annotationsget_object_annotationrV   rW   readput_object_annotationrs   	Exceptionr   listkeys)rF   rG   r3   r0   r   r   r;   src_baselist_kwargsget_kwargs_baseput_passthroughlist_response	succeededfailed
annotationnamepayload_responser   es                      rQ   r   z2CopyCompleteMultipartUploadTask._apply_annotations  s3    ))
>>/0F:++H5((/
 $5H[!

.KK


.II
 ,*EE
 H	//GG 

 	'++M2> 	!J./DLy66LL  ! # 
 $** }}"&%5'&$& "J *9
;'.7
?+!,,,:z:  &+	!0 #!(()9==/ :'[ )./ 0!(	$    ! t!s   5#F""	F:+F55F:N)r   r   r   r   r   r   r   r1   rS   rQ   rv   rv     s    
2(0TErS   rv   c                       e Zd ZdZd Zy)r^   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

        )
CopySourcer   r   bytes_transferredNr1   )copy_object)	rF   rG   r5   rV   rW   r;   rX   r8   callbacks	            rQ   r   zCopyObjectTask._main  sA     	 	
"6s	
>H	
 " 	-Ht,	-rS   Nr   r   r   r   r   r1   rS   rQ   r^   r^     s
    (-rS   r^   c                       e Zd ZdZ	 ddZy)rt   z)Task to upload a part in a multipart copyNc           	      |   	  |j                   d|||||d|}|D ]  } ||	        |d   d   }||d}|
r%d|
j                          }||d   v r|d   |   ||<   |S # t        $ rR}|j                  j                  di       j                  d      }|d   }|d   }|dk(  rt	        d| d| d	       d
}~ww xY w)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.
        )r   r   r   r   
PartNumberErrorCoder   r   PreconditionFailedzContents of stored object "z" in bucket "z" did not match expected ETag.Nr   CopyPartResultr/   )r/   r   Checksumr1   )upload_part_copyr   rP   r7   r   upper)rF   rG   r5   rV   rW   re   rc   r;   rX   r8   rd   rP   r   
error_codesrc_key
src_bucketr   r9   part_metadatachecksum_members                       rQ   r   zCopyPartTask._main3  s.   L	.v.. &"& H( " 	-Ht,	-()&1!%[A ();)A)A)C(DEO(+;"<<19:J1K#2o. -  	488@J!%(G$X.J11'1' ;"", .%%  	s   A   	B;)AB66B;r   r   r1   rS   rQ   rt   rt   0  s    3  ErS   rt   )r   rm   urllib.parser   botocore.exceptionsr   s3transfer.exceptionsr   s3transfer.tasksr   r   r   r	   s3transfer.utilsr
   r   r   r   r   rv   r^   rt   r1   rS   rQ   <module>r      sc      " + 3  ` `FO&A Od-T -2H4 HrS   