o
    i                     @   s  d dl Z d dlZd dlZd dlmZ d dlZd dlZd dlZ	d dl
Z	d dlmZmZmZmZ d dlmZmZmZmZmZ d dlmZmZ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!m"Z" d dl#m$Z$m%Z% d dl&m'Z' d dl(m)Z)m*Z* d dl+m,Z, d dl-m.Z.m/Z/m0Z0m1Z1m2Z2 e 3e4Z5da6dd Z7dddde% ddfddZ8d2ddZ9G dd dZ:G dd de*Z;G dd de)Z<G dd dZ=G d d! d!e=Z>G d"d# d#eZ?G d$d% d%Z@G d&d' d'ZAG d(d) d)ZBG d*d+ d+ZCG d,d- d-ZDG d.d/ d/ZEG d0d1 d1ZFdS )3    N)BytesIO)AwsCredentialsAwsCredentialsProviderAwsSigningAlgorithmAwsSigningConfig)ClientBootstrapClientTlsContextDefaultHostResolverEventLoopGroupTlsContextOptions)S3ClientS3RequestTlsModeS3RequestType)UNSIGNED)urlsplit)Config)NoCredentialsError)	ArnParserInvalidArnException)FULL_OBJECT_CHECKSUM_ARGSMB)TransferNotDoneError)BaseTransferFutureBaseTransferMeta)TransferManager)CallArgsOSUtilscreate_nested_clientget_callbacksis_s3express_bucketc                 C   s>   t d u rtj| }z|  W n
 ty   Y d S w |a t S N)CRT_S3_PROCESS_LOCKawscrts3ZCrossProcessLockacquireRuntimeError)nameZcrt_lock r'   E/home/app/Keep/.python/lib/python3.10/site-packages/s3transfer/crt.pyacquire_crt_s3_process_lock;   s   r)      Tc              
   C   s   t |}t|}t||}	d}
|rtjntj}|dur2t }|r'|j|d nd|_t	|}|
 }
t|d}t|	| ||||
|ddS )a  
    :type region: str
    :param region: The region used for signing

    :type crt_credentials_provider:
        Optional[awscrt.auth.AwsCredentialsProvider]
    :param crt_credentials_provider: CRT AWS credentials provider
        to use to sign requests. If not set, requests will not be signed.

    :type num_threads: Optional[int]
    :param num_threads: Number of worker threads generated. Default
        is the number of processors in the machine.

    :type target_throughput: Optional[int]
    :param target_throughput: Throughput target in bytes per second.
        By default, CRT will automatically attempt to choose a target
        throughput that matches the system's maximum network throughput.
        Currently, if CRT is unable to determine the maximum network
        throughput, a fallback target throughput of ``1_250_000_000`` bytes
        per second (which translates to 10 gigabits per second, or 1.16
        gibibytes per second) is used. To set a specific target
        throughput, set a value for this parameter.

    :type part_size: Optional[int]
    :param part_size: Size, in Bytes, of parts that files will be downloaded
        or uploaded in.

    :type use_ssl: boolean
    :param use_ssl: Whether or not to use SSL.  By default, SSL is used.
        Note that not all services support non-ssl connections.

    :type verify: Optional[boolean/string]
    :param verify: Whether or not to verify SSL certificates.
        By default SSL certificates are verified.  You can provide the
        following values:

        * False - do not validate SSL certificates.  SSL will still be
            used (unless use_ssl is False), but SSL certificates
            will not be verified.
        * path/to/cert/bundle.pem - A filename of the CA cert bundle to
            use. Specify this argument if you want to use a custom CA cert
            bundle instead of the default one on your system.
    N)Zca_filepathF) provided_throughput_target_bytesT)	bootstrapregionZcredential_provider	part_sizetls_modetls_connection_optionsZthroughput_target_gbpsZenable_s3express)r
   r	   r   r   ZENABLEDZDISABLEDr   Z&override_default_trust_store_from_pathZverify_peerr   Znew_connection_options_get_crt_throughput_target_gbpsr   )r-   Zcrt_credentials_providerZnum_threadsZtarget_throughputr.   Zuse_sslverifyZevent_loop_groupZhost_resolverr,   r0   r/   Ztls_ctx_optionsZclient_tls_optiontarget_gbpsr'   r'   r(   create_s3_crt_clientT   s8   4
r4   c                 C   sH   | d u rt j }td| |d u rd}n| d d }td| |S )Nz-Recommended CRT throughput target in gbps: %sg      $@r*   i ʚ;z'Using CRT throughput target in gbps: %s)r"   r#   Z&get_recommended_throughput_target_gbpsloggerdebug)r+   r3   r'   r'   r(   r1      s   
r1   c                   @   s   e Zd ZejZejZejZdZejZd$ddZ	dd Z
dd Z	d%d	d
Zd%ddZd%ddZd&ddZdd Zdd Zdd Zdd Zdd Zdd Zd&ddZd d! Zd"d# ZdS )'CRTTransferManagerTNc                 C   sH   |du rt  | _|| _t|| j| _|j| _g | _t	d| _
d| _dS )aF  A transfer manager interface for Amazon S3 on CRT s3 client.

        :type crt_s3_client: awscrt.s3.S3Client
        :param crt_s3_client: The CRT s3 client, handling all the
            HTTP requests and functions under then hood

        :type crt_request_serializer: s3transfer.crt.BaseCRTRequestSerializer
        :param crt_request_serializer: Serializer, generates unsigned crt HTTP
            request.

        :type osutil: s3transfer.utils.OSUtils
        :param osutil: OSUtils object to use for os-related behavior when
            using with transfer manager.
        N   r   )r   _osutil_crt_s3_clientS3ClientArgsCreator_s3_args_creatortranslate_crt_exception_crt_exception_translator_future_coordinators	threading	Semaphore
_semaphore_id_counter)selfZcrt_s3_clientcrt_request_serializerosutilr'   r'   r(   __init__   s   
zCRTTransferManager.__init__c                 C   s   | S r    r'   rD   r'   r'   r(   	__enter__   s   zCRTTransferManager.__enter__c                 G   s   d}|rd}|  | d S )NFT	_shutdown)rD   exc_type	exc_valueargscancelr'   r'   r(   __exit__   s   zCRTTransferManager.__exit__c                 C   sN   |d u ri }|d u ri }|  || j | | t|||||d}| d|S )Nbucketkeyfileobj
extra_argssubscribersZ
get_object)_validate_all_known_argsALLOWED_DOWNLOAD_ARGS_validate_if_bucket_supportedr   _submit_transfer)rD   rR   rS   rT   rU   rV   callargsr'   r'   r(   download   s   
zCRTTransferManager.downloadc                 C   sX   |d u ri }|d u ri }|  || j | | | | t|||||d}| d|S )NrQ   Z
put_object)rW   ALLOWED_UPLOAD_ARGSrY   &_validate_checksum_algorithm_supportedr   rZ   )rD   rT   rR   rS   rU   rV   r[   r'   r'   r(   upload   s   

zCRTTransferManager.uploadc                 C   sL   |d u ri }|d u ri }|  || j | | t||||d}| d|S )N)rR   rS   rU   rV   Zdelete_object)rW   ALLOWED_DELETE_ARGSrY   r   rZ   )rD   rR   rS   rU   rV   r[   r'   r'   r(   delete  s   
zCRTTransferManager.deleteFc                 C   s   |  | d S r    rJ   rD   rO   r'   r'   r(   shutdown     zCRTTransferManager.shutdownc                 C   s@   | j r| j D ]\}}||}|rtd| dqd S d S )Nz'TransferManager methods do not support z+ resource. Use direct client calls instead.) VALIDATE_SUPPORTED_BUCKET_VALUES_UNSUPPORTED_BUCKET_PATTERNSitemsmatch
ValueError)rD   rR   resourcepatternrh   r'   r'   r(   rY     s   

z0CRTTransferManager._validate_if_bucket_supportedc                 C   s0   |D ]}||vrt d| dd| qd S )NzInvalid extra_args key 'z', must be one of: z, )ri   join)rD   actualallowedkwargr'   r'   r(   rW   ,  s   z+CRTTransferManager._validate_all_known_argsc                 C   sH   | d}|d u rd S ttjjj}| |vr"td| d| d S )NChecksumAlgorithmzChecksumAlgorithm: z* not supported. Supported algorithms are: )getlistr"   r#   S3ChecksumAlgorithm__members__upperri   )rD   rU   checksum_algorithmZsupported_algorithmsr'   r'   r(   r^   4  s   
z9CRTTransferManager._validate_checksum_algorithm_supportedc                 C   s    | j D ]
}| s|  qd S r    )r?   donerO   rD   coordinatorr'   r'   r(   _cancel_transfers?  s
   
z$CRTTransferManager._cancel_transfersc                 C      | j D ]}|  qd S r    )r?   resultrx   r'   r'   r(   _finish_transfersD     

z$CRTTransferManager._finish_transfersc                 C   r{   r    )r?   %wait_until_on_done_callbacks_completerx   r'   r'   r(   _wait_transfers_doneH  r~   z'CRTTransferManager._wait_transfers_donec                 C   sz   |r|    z1z|   W n ty   |    Y n ty"   Y nw W |   d S W |   d S W |   d S |   w r    )rz   r}   KeyboardInterrupt	Exceptionr   rb   r'   r'   r(   rK   L  s   zCRTTransferManager._shutdownc                 K      | j   d S r    )rB   releaserD   kwargsr'   r'   r(   _release_semaphoreY  rd   z%CRTTransferManager._release_semaphorec              
   C   s  | j g}t| j| jd}t| j||d}td	i |}t|}|| z$| j	  | j
|d}|  | j
|||||}	| jjd	i |	}
W n& tyo } z||d | j
j|d|d}||d W Y d }~n
d }~ww ||
 | j| |  jd7  _|S )
N)transfer_idexception_translator)metary   ZqueuedTrw   )after_subscribers)error   r'   )r   CRTTransferCoordinatorrC   r>   CRTTransferMetaCRTTransferFutureAfterDoneHandlerappendrB   r$   r<   get_crt_callbackget_make_request_argsr:   Zmake_requestr   set_exceptionset_s3_requestr?   )rD   request_type	call_argson_done_after_callsry   
componentsfutureZ	afterdoneZ	on_queuedZcrt_callargsZcrt_s3_requesteon_doner'   r'   r(   rZ   \  sJ   



z#CRTTransferManager._submit_transferr    NNF)__name__
__module____qualname__r   rX   r]   r`   re   rf   rG   rI   rP   r\   r_   ra   rc   rY   rW   r^   rz   r}   r   rK   r   rZ   r'   r'   r'   r(   r7      s.    





r7   c                   @   s>   e Zd ZdZdddZedd Zedd Zed	d
 ZdS )r   z*Holds metadata about the CRTTransferFutureNc                 C   s   || _ || _i | _d S r    )_transfer_id
_call_args_user_context)rD   r   r   r'   r'   r(   rG     s   
zCRTTransferMeta.__init__c                 C      | j S r    )r   rH   r'   r'   r(   r        zCRTTransferMeta.call_argsc                 C   r   r    )r   rH   r'   r'   r(   r     r   zCRTTransferMeta.transfer_idc                 C   r   r    )r   rH   r'   r'   r(   user_context  r   zCRTTransferMeta.user_contextr   )	r   r   r   __doc__rG   propertyr   r   r   r'   r'   r'   r(   r     s    


r   c                   @   sD   e Zd ZdddZedd Zdd Zddd	Zd
d Zdd Z	dS )r   Nc                 C   s    || _ |du rt | _ || _dS )aZ  The future associated to a submitted transfer request via CRT S3 client

        :type meta: s3transfer.crt.CRTTransferMeta
        :param meta: The metadata associated to the transfer future.

        :type coordinator: s3transfer.crt.CRTTransferCoordinator
        :param coordinator: The coordinator associated to the transfer future.
        N)_metar   _coordinator)rD   r   ry   r'   r'   r(   rG     s   	
zCRTTransferFuture.__init__c                 C   r   r    )r   rH   r'   r'   r(   r     r   zCRTTransferFuture.metac                 C   s
   | j  S r    )r   rw   rH   r'   r'   r(   rw        
zCRTTransferFuture.donec                 C      | j | d S r    )r   r|   rD   timeoutr'   r'   r(   r|        zCRTTransferFuture.resultc                 C   r   r    )r   rO   rH   r'   r'   r(   rO     rd   zCRTTransferFuture.cancelc                 C   s$   |   std| jj|dd dS )z!Sets the exception on the future.z?set_exception can only be called once the transfer is complete.T)overrideN)rw   r   r   r   rD   	exceptionr'   r'   r(   r     s
   zCRTTransferFuture.set_exceptionr   r    )
r   r   r   rG   r   r   rw   r|   rO   r   r'   r'   r'   r(   r     s    


r   c                   @      e Zd Zdd Zdd ZdS )BaseCRTRequestSerializerc                 C      t d)al  Serialize CRT HTTP requests.

        :type transfer_type: string
        :param transfer_type: the type of transfer made,
            e.g 'put_object', 'get_object', 'delete_object'

        :type future: s3transfer.crt.CRTTransferFuture

        :rtype: awscrt.http.HttpRequest
        :returns: An unsigned HTTP request to be used for the CRT S3 client
        zserialize_http_request()NotImplementedError)rD   transfer_typer   r'   r'   r(   serialize_http_request  s   z/BaseCRTRequestSerializer.serialize_http_requestc                 C   r   )Nztranslate_crt_exception()r   r   r'   r'   r(   r=     s   z0BaseCRTRequestSerializer.translate_crt_exceptionN)r   r   r   r   r=   r'   r'   r'   r(   r     s    r   c                   @   sn   e Zd ZdddZdd Zdd Zdd	 Zd
d Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd ZdS )BotocoreCRTRequestSerializerNc                 C   s   || _ |du r	i }| || t|fi || _| jjjd| j | jjjd| j | jjjd| j	 | jjjd| j
 dS )a  Serialize CRT HTTP request using botocore logic
        It also takes into account configuration from both the session
        and any keyword arguments that could be passed to
        `Session.create_client()` when serializing the request.

        :type session: botocore.session.Session

        :type client_kwargs: Optional[Dict[str, str]])
        :param client_kwargs: The kwargs for the botocore
            s3 client initialization.
        Nzrequest-created.s3.*zafter-call.s3.*zbefore-send.s3.*zbefore-call.s3.*)_session_resolve_client_configr   _clientr   eventsregister_capture_http_request+_change_response_to_serialized_http_request_make_fake_http_response_remove_checksum_context)rD   sessionclient_kwargsr'   r'   r(   rG     s"   



z%BotocoreCRTRequestSerializer.__init__c                 C   sP   d }|  r
|  }d|v r|d }ttd}|r||}||d< d|d< d S )Nconfig)Zsignature_versionr#   Zservice_name)Zget_default_client_configr   r   merge)rD   r   r   Zuser_provided_configZclient_configr'   r'   r(   r     s   

z3BotocoreCRTRequestSerializer._resolve_client_configc           	      C   s   t |j}|j}|jr| d|j }g }|j D ]\}}t|tr+|||f q||t|df qt	j
|}t	j
j|j|||jd}|S )N?zutf-8)methodpathheadersZbody_stream)r   urlr   queryr   rg   
isinstancestrr   r"   httpZHttpHeadersZHttpRequestr   body)	rD   Zaws_request	url_partsZcrt_pathZheaders_listr&   valueZcrt_headerscrt_requestr'   r'   r(   _crt_request_from_aws_request   s"   

z:BotocoreCRTRequestSerializer._crt_request_from_aws_requestc                 C   s   |  |}|jdd u rt|j}|jd|j |jdd ur(|jd |jdd u r<|jd u r<|j	dd |jdd urJ|jd |S )NhostzContent-MD5zContent-Length0zTransfer-Encoding)
r   r   rq   r   r   setnetlocremover   add)rD   botocore_http_requestr   r   r'   r'   r(   _convert_to_crt_http_request  s   


z9BotocoreCRTRequestSerializer._convert_to_crt_http_requestc                 K   s   ||j d< d S )Nhttp_request)contextrD   requestr   r'   r'   r(   r   4  rd   z2BotocoreCRTRequestSerializer._capture_http_requestc                 K   s   |d }|  |d< d S )Nr   HTTPRequest)prepare)rD   r   parsedr   r   r'   r'   r(   r   7  s   zHBotocoreCRTRequestSerializer._change_response_to_serialized_http_requestc                 K   s   t jd di tdS )N       )botocore
awsrequestZAWSResponseFakeRawResponser   r'   r'   r(   r   =  s   z5BotocoreCRTRequestSerializer._make_fake_http_responsec                 C   s&   t | j|d|j|jd|jd S )N)ZBucketKeyr   r'   )getattrr   rR   rS   rU   )rD   Zclient_methodr   r'   r'   r(   _get_botocore_http_requestE  s   z7BotocoreCRTRequestSerializer._get_botocore_http_requestc                 C   s   |  ||jj}| |}|S r    )r   r   r   r   )rD   r   r   r   r   r'   r'   r(   r   J  s
   
z3BotocoreCRTRequestSerializer.serialize_http_requestc                 C   s   t |tjjr| |S d S r    )r   r"   r#   ZS3ResponseError _translate_crt_s3_response_errorr   r'   r'   r(   r=   Q  s   
z4BotocoreCRTRequestSerializer.translate_crt_exceptionc                 C   s   |j }|dk r	d S dd |jD }|j}|d ur$| jjj}||j}nd }tj	
|||jd}| jjj||d}|di d}	| jj|	}
|
||dS )	Ni-  c                 S   s   i | ]\}}||qS r'   r'   ).0kvr'   r'   r(   
<dictcomp>^  s    zQBotocoreCRTRequestSerializer._translate_crt_s3_response_error.<locals>.<dictcomp>)r   status_coder   )shapeErrorZCode)operation_name)r   r   r   r   r   service_modelZoperation_modelZoutput_shaper   r   ZHeadersDictr   Z_response_parserparserq   
exceptionsZ	from_code)rD   Zs3_response_errorr   r   r   r   r   Zresponse_dictZparsed_responseZ
error_codeZerror_classr'   r'   r(   r   W  s&   

z=BotocoreCRTRequestSerializer._translate_crt_s3_response_errorc                 K   s"   | di }d|v r|d= d S d S )Nr   Zchecksum)rq   )rD   paramsr   request_contextr'   r'   r(   r   s  s   
z5BotocoreCRTRequestSerializer._remove_checksum_contextr    )r   r   r   rG   r   r   r   r   r   r   r   r   r=   r   r   r'   r'   r'   r(   r     s    
r   c                   @   s   e Zd ZdddZdS )r      Nc                 c   s    	 |  |}|sd S |V  qr    )read)rD   amtdecode_contentchunkr'   r'   r(   streamz  s   
zFakeRawResponse.stream)r   N)r   r   r   r  r'   r'   r'   r(   r   y  s    r   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
BotocoreCRTCredentialsWrapperc                 C   
   || _ d S r    )_resolved_credentials)rD   Zresolved_botocore_credentialsr'   r'   r(   rG     r   z&BotocoreCRTCredentialsWrapper.__init__c                 C   s   |    }t|j|j|jS r    )_get_credentialsZget_frozen_credentialsr   Z
access_keyZ
secret_keytoken)rD   credentialsr'   r'   r(   __call__  s   z&BotocoreCRTCredentialsWrapper.__call__c                 C   s
   t | S r    )r   Znew_delegaterH   r'   r'   r(   to_crt_credentials_provider  r   z9BotocoreCRTCredentialsWrapper.to_crt_credentials_providerc                 C   s   | j d u rt | j S r    )r  r   rH   r'   r'   r(   r    s   
z.BotocoreCRTCredentialsWrapper._get_credentialsN)r   r   r   rG   r	  r
  r  r'   r'   r'   r(   r    s
    r  c                   @   sn   e Zd ZdZ	dddZedd Zdd Zdd	d
ZdddZ	dd Z
dddZdd Zdd Zdd ZdS )r   z-A helper class for managing CRTTransferFutureNc                 C   s6   || _ || _|| _t | _d | _d | _t | _	d S r    )
r   _exception_translator_s3_requestr@   Lock_lock
_exception_crt_futureEvent_done_event)rD   r   
s3_requestr   r'   r'   r(   rG     s   
zCRTTransferCoordinator.__init__c                 C   r   r    )r  rH   r'   r'   r(   r    r   z!CRTTransferCoordinator.s3_requestc                 C   r   r    )r  r   rH   r'   r'   r(   set_done_callbacks_complete  rd   z2CRTTransferCoordinator.set_done_callbacks_completec                 C   r   r    )r  waitr   r'   r'   r(   r     r   z<CRTTransferCoordinator.wait_until_on_done_callbacks_completeFc                 C   sN   | j  |  r
|r|| _W d    d S W d    d S 1 s w   Y  d S r    )r  rw   r  )rD   r   r   r'   r'   r(   r     s   "z$CRTTransferCoordinator.set_exceptionc                 C   s   | j r
| j   d S d S r    )r  rO   rH   r'   r'   r(   rO     s   zCRTTransferCoordinator.cancelc              
   C   s   | j r| j z<z| j| W n( ty!   |   | j|   ty7 } z| | W Y d }~nd }~ww W | jrAd | _d S d S | jrId | _w r    )r  r  r|   r   rO   r   handle_exceptionr  )rD   r   r   r'   r'   r(   r|     s"   

zCRTTransferCoordinator.resultc              
   C   s^   d }| j r&z|  |}W n ty% } ztjd|d W Y d }~nd }~ww |d ur-|||)NzUnable to translate exception.)exc_info)r  r   r5   r6   )rD   excZtranslated_excr   r'   r'   r(   r    s   z'CRTTransferCoordinator.handle_exceptionc                 C   s   | j d u rdS | j  S )NF)r  rw   rH   r'   r'   r(   rw     s   

zCRTTransferCoordinator.donec                 C   s   || _ | j j| _d S r    )r  Zfinished_futurer  )rD   r  r'   r'   r(   r     s   z%CRTTransferCoordinator.set_s3_request)NNNr    r   )r   r   r   r   rG   r   r  r  r   r   rO   r|   r  rw   r   r'   r'   r'   r(   r     s    




r   c                   @   sB   e Zd Zdd Zdd Z		dddZdd	 Zd
d Zdd ZdS )r;   c                 C   s   || _ || _d S r    )_request_serializer	_os_utils)rD   rE   Zos_utilsr'   r'   r(   rG     s   
zS3ClientArgsCreator.__init__c                 C   s(   t | d| | j}|||||g |dS )NZ_get_make_request_args_r   r   ry   r   on_done_before_callsr   )r   _default_get_make_request_args)rD   r   r   ry   r   r   Zrequest_args_handlerr'   r'   r(   r     s   z)S3ClientArgsCreator.get_make_request_argsNc                    s    fdd}|S )Nc                     sf   g }d ur
|7 }|t 7 } d ur| 7 }|D ]}dkr)|| d d q|| i | qd S )Nprogressr   )Zbytes_transferred)r   )rN   r   Zcallbacks_listcallbackr   before_subscriberscallback_typer   r'   r(   invoke_all_callbacks  s   zBS3ClientArgsCreator.get_crt_callback.<locals>.invoke_all_callbacksr'   )rD   r   r"  r!  r   r#  r'   r   r(   r     s   z$S3ClientArgsCreator.get_crt_callbackc                    s   d }t  jtr j}| j|}| jd< n j jd< d }	t fddtD sB jdd	 }
t
jjt
jj|
 t
jjjd}	d jd	< | j| ||||d
}||d< |	|d< |S )NZContentLengthZBodyc                 3   s    | ]}| j v V  qd S r    )rU   )r   Zchecksum_argr   r'   r(   	<genexpr>  s
    
zHS3ClientArgsCreator._get_make_request_args_put_object.<locals>.<genexpr>rp   ZCRC32)	algorithmlocationzoverride-to-be-removedZ
ContentMD5r  send_filepathchecksum_config)r   rT   r   r  Zget_file_sizerU   anyr   popru   r"   r#   S3ChecksumConfigrs   ZS3ChecksumLocationZTRAILERr  )rD   r   r   ry   r   r  r   r(  data_lenr)  rv   make_request_argsr'   r$  r(   !_get_make_request_args_put_object  s>   	

z5S3ClientArgsCreator._get_make_request_args_put_objectc                 C   s   d }d }t jjdd}	t|jtr&|j}
| j|
}|t	||
|| j nt
|j}| j||||||d}||d< ||d< |	|d< |S )NT)Zvalidate_responser  recv_filepathon_bodyr)  )r"   r#   r,  r   rT   r   r  Zget_temp_filenamer   RenameTempFileHandlerOnBodyFileObjWriterr  )rD   r   r   ry   r   r  r   r0  r1  r)  Zfinal_filepathr.  r'   r'   r(   !_get_make_request_args_get_object<  s0   	

z5S3ClientArgsCreator._get_make_request_args_get_objectc           
      C   s   | j ||tt| tj| |d||| |dd}|d tjkr3ddd |dD |d	< t	 }|
|j }	rV|	d
 dkrVttjdddd|d< |	d |_|S t|jrettjddd|d< |S )Nrw   r  )r   typer   Zon_progressr5   c                 s   s    | ]}|  V  qd S r    )title)r   xr'   r'   r(   r%  y  s    
zES3ClientArgsCreator._default_get_make_request_args.<locals>.<genexpr>_r   r-   *F)r&  r-   use_double_uri_encodeshould_normalize_uri_pathZsigning_configresource_name)r&  r;  r<  )r  r   r   r   ru   DEFAULTr   rl   split_S3ArnParamHandler
handle_arnrR   r   r   ZV4_ASYMMETRICr   ZV4_S3EXPRESS)
rD   r   r   ry   r   r  r   r.  Zarn_handlerZaccesspoint_arn_detailsr'   r'   r(   r  `  sD   




	

z2S3ClientArgsCreator._default_get_make_request_argsr   )	r   r   r   rG   r   r   r/  r4  r  r'   r'   r'   r(   r;     s    
/$r;   c                   @   r   )r2  c                 C   s   || _ || _|| _|| _d S r    )r   _final_filename_temp_filenamer9   )rD   ry   Zfinal_filenameZtemp_filenamerF   r'   r'   r(   rG     s   
zRenameTempFileHandler.__init__c              
   K   sx   |d }|r| j | j d S z| j | j| j W d S  ty; } z| j | j | j| W Y d }~d S d }~ww )Nr   )r9   Zremove_filerC  Zrename_filerB  r   r   r   )rD   r   r   r   r'   r'   r(   r	    s   
zRenameTempFileHandler.__call__Nr   r   r   rG   r	  r'   r'   r'   r(   r2    s    r2  c                   @   r   )r   c                 C   r  r    )r   rx   r'   r'   r(   rG     r   zAfterDoneHandler.__init__c                 K   r   r    )r   r  r   r'   r'   r(   r	    rd   zAfterDoneHandler.__call__NrD  r'   r'   r'   r(   r         r   c                   @   r   )r3  c                 C   r  r    )_fileobj)rD   rT   r'   r'   r(   rG     r   zOnBodyFileObjWriter.__init__c                 K   r   r    )rF  write)rD   r  r   r'   r'   r(   r	    r   zOnBodyFileObjWriter.__call__NrD  r'   r'   r'   r(   r3    rE  r3  c                   @   s:   e Zd ZdZedZdd Zdd Zdd Z	d	d
 Z
dS )r@  a  Partial port of S3ArnParamHandler from botocore.

    This is used to make a determination on MRAP accesspoints for signing
    purposes. This should be safe to remove once we properly integrate auth
    resolution from Botocore into the CRT transfer integration.
    zA^(?P<resource_type>accesspoint|outpost)[/:](?P<resource_name>.+)$c                 C   s   t  | _d S r    )r   _arn_parserrH   r'   r'   r(   rG     s   z_S3ArnParamHandler.__init__c                 C   s*   |  |}|d u rd S |d dkr|S d S )Nresource_typeZaccesspoint)_get_arn_details_from_bucketrD   rR   arn_detailsr'   r'   r(   rA    s   
z_S3ArnParamHandler.handle_arnc                 C   s2   z| j |}| | |W S  ty   Y d S w r    )rH  Z	parse_arn_add_resource_type_and_namer   rK  r'   r'   r(   rJ    s   
z/_S3ArnParamHandler._get_arn_details_from_bucketc                 C   s8   | j |d }|r|d|d< |d|d< d S d S )Nrj   rI  r=  )_RESOURCE_REGEXrh   group)rD   rL  rh   r'   r'   r(   rM    s
   z._S3ArnParamHandler._add_resource_type_and_nameN)r   r   r   r   recompilerN  rG   rA  rJ  rM  r'   r'   r'   r(   r@    s    	r@  r    )GloggingrP  r@   ior   Zawscrt.httpr"   Z	awscrt.s3Zbotocore.awsrequestr   Zbotocore.sessionZawscrt.authr   r   r   r   Z	awscrt.ior   r   r	   r
   r   r   r   r   r   Zbotocore.compatr   Zbotocore.configr   Zbotocore.exceptionsr   Zbotocore.utilsr   r   Zs3transfer.constantsr   r   Zs3transfer.exceptionsr   Zs3transfer.futuresr   r   Zs3transfer.managerr   Zs3transfer.utilsr   r   r   r   r   	getLoggerr   r5   r!   r)   r4   r1   r7   r   r   r   r   r   r  r   r;   r2  r   r3  r@  r'   r'   r'   r(   <module>   s`   


U L& &	I :