
    fjbY                         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dS )    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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AnnotationDirectiveTagging)CacheControlContentDispositionContentEncodingContentLanguageContentTypeExpiresMetadata)r   r   r   r   r   )r   r   ChecksumAlgorithmc           	         i }d}|j         j        }|j         j        |j         j        |                     |j                  }	|j        }
|
                                D ]\  }}|| j        v r||	| j        |         <    |j	        j
        di |	}|j                             |d                    |j                             |                    d                     |                     |          }|                    d          }|j         j        |j        k     r|                     |||||           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	VersionId)source_version_id )meta	call_argssizeetag)_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_extract_preserved_metadatamultipart_threshold_submit_copy_request_submit_multipart_request)selfclientconfigosutilrequest_executortransfer_futurepreserved_metadatar0   r3   head_object_requestr8   paramvalueresponses                 U/var/www/app.qaans.com/backend/venv/lib/python3.11/site-packages/s3transfer/copies.py_submitzCopySubmissionTask._submito   s   *   #(2	 %-#(0 >>)   
 #-J !+ 0 0 2 2  uD@@@  (<UC ;y.:  % H  66)  
  44X\\&5I5IJJJ!%!A!A(!K!K !)[ 9 9 $v'AAA%%(8/     ** ""3 +         c                     |j         j        }t          |d          }| j                            |t          | j        ||j        |j        |j        |j	        ||j         j
        dd                     d S )Nprogress)rE   r7   bucketkeyr8   	callbacksr4   T)transfer_coordinatormain_kwargsis_final)r2   r3   r   _transfer_coordinatorsubmitCopyObjectTaskr7   rT   rU   r8   r4   )rD   rE   rF   rG   rH   rI   r3   progress_callbackss           rO   rB   z'CopySubmissionTask._submit_copy_request   s     $(2	 +?JGG 	"))%)%?$#,#8'.$="+"6!3+05    	
 	
 	
 	
 	
rQ   Nc                    |j         j        }|                     |j        |pi           }	i }
|	                                D ]\  }}|| j        vr||
|<   | j                            |t          | j        ||j	        |j
        |
d                    }|j        }t                      }|                    ||j         j                  }t          t!          j        |j         j        t%          |          z                      }g }t'          |d          }t)          d|dz             D ]}|                     |j                  }t-          ||dz
  ||j         j                  |d<   |j         j        |j         j        |d<   |                     ||dz
  ||j         j                  }|j                            d          }|                    | j                            |t7          | j        ||j        |j	        |j
        |||||d	d	|i
                               |                     |j                  }| j                            |t=          | j        ||j	        |j
        |||d||dd                     d S )N)rE   rT   rU   r8   )rW   rX   rS      CopySourceRanger   r+   )	rE   r7   rT   rU   part_numberr8   rV   r4   checksum_algorithm	upload_id)rW   rX   pending_main_kwargs)rE   rT   rU   r8   r3   r0   )rc   partsT)rW   rX   rd   rY   )r2   r3   _apply_preserved_metadatar8   r9   CREATE_MULTIPART_ARGS_BLACKLISTrZ   r[   r   rT   rU   multipart_chunksizer
   adjust_chunksizer4   intmathceilfloatr   range_extra_upload_part_argsr   r5   _get_transfer_sizer?   appendCopyPartTaskr7   _extra_complete_multipart_argsCopyCompleteMultipartUploadTask)rD   rE   rF   rG   rH   rI   rJ   r0   r3   merged_extra_argscreate_multipart_extra_argsrL   valcreate_multipart_future	part_sizeadjuster	num_partspart_futuresr]   ra   extra_part_argsr4   rb   complete_multipart_extra_argss                           rO   rC   z,CopySubmissionTask._submit_multipart_request   s/    $(2	 :: "4":
 
 ')#+1133 	9 	9JE3D@@@58+E2"&"<"C"C%%)%?$'.$="=	   #
 #
 .	$&&--+0
 
	 Io*/%	2B2BBCC
 
	
 *?JGG IM22 0	 0	K"::$ O 2Ka$)	2 2O-. #(4#(-   34
 **a$)	 D "+!5!9!9:M!N!N*11$ -1-G&,+4+@&/&6#,=+6*9);$(2D
% 
% ()@-      . )-(K(K )
 )
%
 	"))+%)%?$'.$="?!*):  "9)% %   	
 	
 	
 	
 	
rQ   c                 <    i }| j         D ]}||v r||         ||<   |S NPRESERVED_METADATA_FIELDS)rD   head_object_response	preservedfields       rO   r@   z.CopySubmissionTask._extract_preserved_metadataU  s;    	3 	? 	?E,,,#7#>	% rQ   c                      |                     d          dk    r|S  fd|                                D             }|                    |           |S )Nr    REPLACEc                 .    i | ]\  }}|j         v||S r1   r   ).0kvrD   s      rO   
<dictcomp>z@CopySubmissionTask._apply_preserved_metadata.<locals>.<dictcomp>b  s7     
 
 
Q666 q666rQ   )r?   r9   update)rD   r8   rJ   results   `   rO   rf   z,CopySubmissionTask._apply_preserved_metadata\  sq     >>-..);;
 
 
 
'--//
 
 
 	()))rQ   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)rD   r7   s     rO   r6   z<CopySubmissionTask._get_head_object_request_from_copy_sourcei  sh    k4(( 	9[)))F&F F15k1B1BF F F  rQ   c                 ,    t          || j                  S r   )r   UPLOAD_PART_COPY_ARGSrD   r8   s     rO   ro   z*CopySubmissionTask._extra_upload_part_argss  s     !T-GHHHrQ   c                 ,    t          || j                  S r   )r   COMPLETE_MULTIPART_ARGSr   s     rO   rs   z1CopySubmissionTask._extra_complete_multipart_argsx  s     T-IJJJrQ   c                 (    ||dz
  k    r|||z  z
  S |S )Nr_   r1   )rD   ry   
part_indexr{   total_transfer_sizes        rO   rp   z%CopySubmissionTask._get_transfer_size{  s+     Q&& '*y*@AArQ   )NN)__name__
__module____qualname____doc__r:   r   rg   r   r   GET_OBJECT_TAGGING_ARGSPUT_OBJECT_TAGGING_ARGSLIST_OBJECT_ANNOTATIONS_ARGSGET_OBJECT_ANNOTATION_ARGSPUT_OBJECT_ANNOTATION_ARGSrP   rB   rC   r@   rf   r6   ro   rs   rp   r1   rQ   rO   r   r   "   s|       55 '%6!.':$4*@':&4
' 
'#  ' ' '#! ! !    ./DE  
 %34I#J "02G!H" " "M M M^
 
 
B  {
 {
 {
 {
z      I I I
K K K    rQ   r   c                   $    e Zd ZdZd Zd Zd ZdS )rt   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|}	|	                    d          }
|	                    d          }|                     ||||           |                     |||||
           d S )NParts)BucketKeyUploadIdMultipartUploadr.   r/   r1   )complete_multipart_uploadr?   _apply_tags_apply_annotations)rD   rE   rT   rU   rc   re   r8   r3   r0   rN   	dest_etagdest_version_ids               rO   _mainz%CopyCompleteMultipartUploadTask._main  s     463 
$e,	
 

 
 
 LL((	",,{33,=OOOI0/9	
 	
 	
 	
 	
rQ   c                    |j         }|                    d          }|dvrd S |dk    rc|j        d         |j        d         dt          |t          j                  }|r||d<    |j        j        di |                    dg           }n/d	 t          |                    d
d          d          D             }|sd S |j	        |j
        d|idt          |t          j                  }	|r||	d<    |j        di |	 d S )Nr!   )COPYr   r   r   r   r   r   r/   TagSetc                     g | ]
\  }}||d S ))r   Valuer1   )r   r   r   s      rO   
<listcomp>z?CopyCompleteMultipartUploadTask._apply_tags.<locals>.<listcomp>  s4       Aq A&&  rQ   r#    T)keep_blank_values)r   r   r#   r1   )r8   r?   r7   r   r   r   r;   get_object_taggingr   rT   rU   r   put_object_tagging)
rD   rE   r3   r0   r   r8   	directive
src_kwargstag_set
put_kwargss
             rO   r   z+CopyCompleteMultipartUploadTask._apply_tags  s   )
NN#566	///F#/9 ,U3  $ 2 J J ! <*;
;'@i-@   c(B G %NN9b11&*    G  	F&= '*
 
  .F 	

  	6&5J{#!!//J/////rQ   c                 V   |j         }|                    d          dk    rd S |j        d         |j        d         d}|r||d<   i |t          |t          j                  }i |t          |t          j                  }	t          |t          j                  }
 |j        j	        di |}g }i }|                    dg           D ]}|d         } |j        j
        di |	d|i}|j        |j        ||d	                                         d
|
}|r||d<   |r||d<   	  |j        di | |                    |           }# t           $ r}|||<   Y d }~d }~ww xY w|rGt#          d|j         d|j         d| dt%          |                                           d| 
          d S )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   )r8   r?   r7   r   r   r   r   r   r;   list_object_annotationsget_object_annotationrT   rU   readput_object_annotationrq   	Exceptionr   listkeys)rD   rE   r3   r0   r   r   r8   src_baselist_kwargsget_kwargs_baseput_passthroughlist_response	succeededfailed
annotationnamepayload_responser   es                      rO   r   z2CopyCompleteMultipartUploadTask._apply_annotations  s    )
>>/00F::F+H5(/
 
  	6$5H[!

.K 


.I 
 ,*E
 
 H	/G 
 

 
 	'++M2>> 	! 	!J./DLy6L    !   #     
 $* }"&%56I%J%O%O%Q%Q	 
 "J  :*9
;' 8.7
?+!,,::z:::  &&&& ! ! ! t! 	#$!($ $+4=$ $'$ $  ..$ $ "	$ $  	 	s   !"E
EEEN)r   r   r   r   r   r   r   r1   rQ   rO   rt   rt     sQ         
 
 
2&0 &0 &0PC C C C CrQ   rt   c                       e Zd ZdZd ZdS )r\   zTask to do a nonmultipart copyc                 J     |j         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 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)	rD   rE   r7   rT   rU   r8   rV   r4   callbacks	            rO   r   zCopyObjectTask._main  se     	 	
"6s	
 	
>H	
 	
 	
 " 	- 	-HHt,,,,,	- 	-rQ   Nr   r   r   r   r   r1   rQ   rO   r\   r\     s)        ((- - - - -rQ   r\   c                       e Zd ZdZ	 ddZdS )rr   z)Task to upload a part in a multipart copyNc           	         	  |j         d|||||d|}nm# t          $ r`}|j                            di                               d          }|d         }|d         }|dk    rt	          d| d| d	           d
}~ww xY w|D ]} ||	           |d         d         }||d}|
r2d|
                                 }||d         v r|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.
        )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   rN   r?   r   upper)rD   rE   r7   rT   rU   rc   ra   r8   rV   r4   rb   rN   r   
error_codesrc_key
src_bucketr   r5   part_metadatachecksum_members                       rO   r   zCopyPartTask._main/  sv   L	.v. &"&   HH  	 	 	4488@@J!%(G$X.J111'%' % %",% % %   	 " 	- 	-HHt,,,,,()&1!%[AA 	E);)A)A)C)CEEO(+;"<<<19:J1K#2o. s    
B AA;;B r   r   r1   rQ   rO   rr   rr   ,  s9        33  E E E E E ErQ   rr   )r   rk   urllib.parser   botocore.exceptionsr   s3transfer.exceptionsr   s3transfer.tasksr   r   r   r	   s3transfer.utilsr
   r   r   r   r   rt   r\   rr   r1   rQ   rO   <module>r      s     " " " " " " + + + + + + 3 3 3 3 3 3                      ` ` ` ` ` ` ` `FK K K K K&A K K K\- - - - -T - - -2H H H H H4 H H H H HrQ   