o
    #`^h                     @   s  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  d dl!m"Z" d dl#m$Z$m%Z% d dl&m'Z' d dl(m)Z)m*Z*m+Z+m,Z, e -e.Z/da0dd Z1dddde  ddfddZ2d/ddZ3G dd dZ4G dd de%Z5G dd de$Z6G dd dZ7G dd  d e7Z8G d!d" d"eZ9G d#d$ d$Z:G d%d& d&Z;G d'd( d(Z<G d)d* d*Z=G d+d, d,Z>G d-d. d.Z?dS )0    N)BytesIO)AwsCredentialsAwsCredentialsProviderAwsSigningAlgorithmAwsSigningConfig)ClientBootstrapClientTlsContextDefaultHostResolverEventLoopGroupTlsContextOptions)S3ClientS3RequestTlsModeS3RequestType)UNSIGNED)urlsplit)Config)NoCredentialsError)MB)TransferNotDoneError)BaseTransferFutureBaseTransferMeta)TransferManager)CallArgsOSUtils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s3CrossProcessLockacquireRuntimeError)namecrt_lock r%   L/home/air/shanriGPT/back/venv/lib/python3.10/site-packages/s3transfer/crt.pyacquire_crt_s3_process_lock8   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)ca_filepathF) provided_throughput_target_bytesT)	bootstrapregioncredential_provider	part_sizetls_modetls_connection_optionsthroughput_target_gbpsenable_s3express)r
   r	   r   r   ENABLEDDISABLEDr   &override_default_trust_store_from_pathverify_peerr   new_connection_options_get_crt_throughput_target_gbpsr   )r,   crt_credentials_providernum_threadstarget_throughputr.   use_sslverifyevent_loop_grouphost_resolverr+   r0   r/   tls_ctx_optionsclient_tls_optiontarget_gbpsr%   r%   r&   create_s3_crt_clientQ   s8   4
rC   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   &get_recommended_throughput_target_gbpsloggerdebug)r*   rB   r%   r%   r&   r8      s   
r8   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)selfcrt_s3_clientcrt_request_serializerosutilr%   r%   r&   __init__   s   
zCRTTransferManager.__init__c                 C   s   | S r   r%   rT   r%   r%   r&   	__enter__   s   zCRTTransferManager.__enter__c                 G   s   d}|rd}|  | d S )NFT	_shutdown)rT   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subscribers
get_object)_validate_all_known_argsALLOWED_DOWNLOAD_ARGS_validate_if_bucket_supportedr   _submit_transfer)rT   rc   rd   re   rf   rg   callargsr%   r%   r&   download   s   
zCRTTransferManager.downloadc                 C   sX   |d u ri }|d u ri }|  || j | | | | t|||||d}| d|S )Nrb   
put_object)ri   ALLOWED_UPLOAD_ARGSrk   &_validate_checksum_algorithm_supportedr   rl   )rT   re   rc   rd   rf   rg   rm   r%   r%   r&   upload   s   

zCRTTransferManager.uploadc                 C   sL   |d u ri }|d u ri }|  || j | | t||||d}| d|S )N)rc   rd   rf   rg   delete_object)ri   ALLOWED_DELETE_ARGSrk   r   rl   )rT   rc   rd   rf   rg   rm   r%   r%   r&   delete
  s   
zCRTTransferManager.deleteFc                 C   s   |  | d S r   r[   rT   r`   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)rT   rc   resourcepatternr|   r%   r%   r&   rk     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, )r}   join)rT   actualallowedkwargr%   r%   r&   ri   )  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__upperr}   )rT   rf   checksum_algorithmsupported_algorithmsr%   r%   r&   rq   1  s   
z9CRTTransferManager._validate_checksum_algorithm_supportedc                 C   s    | j D ]
}| s|  qd S r   )rO   doner`   rT   coordinatorr%   r%   r&   _cancel_transfers<  s
   
z$CRTTransferManager._cancel_transfersc                 C      | j D ]}|  qd S r   )rO   resultr   r%   r%   r&   _finish_transfersA     

z$CRTTransferManager._finish_transfersc                 C   r   r   )rO   %wait_until_on_done_callbacks_completer   r%   r%   r&   _wait_transfers_doneE  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   )r   r   KeyboardInterrupt	Exceptionr   rv   r%   r%   r&   r\   I  s   zCRTTransferManager._shutdownc                 K      | j   d S r   )rR   releaserT   kwargsr%   r%   r&   _release_semaphoreV  rx   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)metar   queuedTr   )after_subscribers)error   r%   )r   CRTTransferCoordinatorrS   rN   CRTTransferMetaCRTTransferFutureAfterDoneHandlerappendrR   r!   rL   get_crt_callbackget_make_request_argsrJ   make_requestr   set_exceptionset_s3_requestrO   )rT   request_type	call_argson_done_after_callsr   
componentsfuture	afterdone	on_queuedcrt_callargscrt_s3_requesteon_doner%   r%   r&   rl   Y  sJ   



z#CRTTransferManager._submit_transferr   NNF)__name__
__module____qualname__r   rj   rp   rt   ry   rz   rX   rZ   ra   rn   rr   ru   rw   rk   ri   rq   r   r   r   r\   r   rl   r%   r%   r%   r&   rG      s.    





rG   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)rT   r   r   r%   r%   r&   rX     s   
zCRTTransferMeta.__init__c                 C      | j S r   )r   rY   r%   r%   r&   r        zCRTTransferMeta.call_argsc                 C   r   r   )r   rY   r%   r%   r&   r     r   zCRTTransferMeta.transfer_idc                 C   r   r   )r   rY   r%   r%   r&   user_context  r   zCRTTransferMeta.user_contextr   )	r   r   r   __doc__rX   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)rT   r   r   r%   r%   r&   rX     s   	
zCRTTransferFuture.__init__c                 C   r   r   )r   rY   r%   r%   r&   r     r   zCRTTransferFuture.metac                 C   s
   | j  S r   )r   r   rY   r%   r%   r&   r        
zCRTTransferFuture.donec                 C      | j | d S r   )r   r   rT   timeoutr%   r%   r&   r        zCRTTransferFuture.resultc                 C   r   r   )r   r`   rY   r%   r%   r&   r`     rx   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)r   r   r   r   rT   	exceptionr%   r%   r&   r     s
   zCRTTransferFuture.set_exceptionr   r   )
r   r   r   rX   r   r   r   r   r`   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)rT   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&   rM     s   z0BaseCRTRequestSerializer.translate_crt_exceptionN)r   r   r   r   rM   r%   r%   r%   r&   r     s    r   c                   @   sf   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S )BotocoreCRTRequestSerializerNc                 C   sp   || _ |du r	i }| || |jdi || _| 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.*r%   )
_session_resolve_client_configcreate_client_clientr   eventsregister_capture_http_request+_change_response_to_serialized_http_request_make_fake_http_response)rT   sessionclient_kwargsr%   r%   r&   rX     s   


z%BotocoreCRTRequestSerializer.__init__c                 C   sP   d }|  r
|  }d|v r|d }ttd}|r||}||d< d|d< d S )Nconfig)signature_versionr   service_name)get_default_client_configr   r   merge)rT   r   r   user_provided_config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headersbody_stream)r   urlr   queryr   r{   
isinstancestrr   r   httpHttpHeadersHttpRequestr   body)	rT   aws_request	url_partscrt_pathheaders_listr#   value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   r   r   r   setnetlocremover   add)rT   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rT   requestr   r%   r%   r&   r   .  rx   z2BotocoreCRTRequestSerializer._capture_http_requestc                 K   s   |d }|  |d< d S )Nr  HTTPRequest)prepare)rT   r  parsedr   r
  r%   r%   r&   r   1  s   zHBotocoreCRTRequestSerializer._change_response_to_serialized_http_requestc                 K   s   t jd di tdS )N       )botocore
awsrequestAWSResponseFakeRawResponser	  r%   r%   r&   r   7  s   z5BotocoreCRTRequestSerializer._make_fake_http_responsec                 C   s&   t | j|d|j|jd|jd S )N)BucketKeyr  r%   )getattrr   rc   rd   rf   )rT   client_methodr   r%   r%   r&   _get_botocore_http_request?  s   z7BotocoreCRTRequestSerializer._get_botocore_http_requestc                 C   s   |  ||jj}| |}|S r   )r  r   r   r  )rT   r   r   r  r   r%   r%   r&   r   D  s
   
z3BotocoreCRTRequestSerializer.serialize_http_requestc                 C   s   t |tjjr| |S d S r   )r   r   r   S3ResponseError _translate_crt_s3_response_errorr   r%   r%   r&   rM   K  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>X  s    zQBotocoreCRTRequestSerializer._translate_crt_s3_response_error.<locals>.<dictcomp>)r   status_coder   )shapeErrorCode)operation_name)r  r   r#  r   r   service_modeloperation_modeloutput_shaper  r  HeadersDictr   _response_parserparser   
exceptions	from_code)rT   s3_response_errorr  r   r#  r$  r   response_dictparsed_response
error_codeerror_classr%   r%   r&   r  Q  s&   

z=BotocoreCRTRequestSerializer._translate_crt_s3_response_errorr   )r   r   r   rX   r   r   r  r   r   r   r  r   rM   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)rT   amtdecode_contentchunkr%   r%   r&   streamo  s   
zFakeRawResponse.stream)r1  N)r   r   r   r6  r%   r%   r%   r&   r  n  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)rT   resolved_botocore_credentialsr%   r%   r&   rX   x  r   z&BotocoreCRTCredentialsWrapper.__init__c                 C   s   |    }t|j|j|jS r   )_get_credentialsget_frozen_credentialsr   
access_key
secret_keytoken)rT   credentialsr%   r%   r&   __call__{  s   z&BotocoreCRTCredentialsWrapper.__call__c                 C   s
   t | S r   )r   new_delegaterY   r%   r%   r&   to_crt_credentials_provider  r   z9BotocoreCRTCredentialsWrapper.to_crt_credentials_providerc                 C   s   | j d u rt | j S r   )r9  r   rY   r%   r%   r&   r;    s   
z.BotocoreCRTCredentialsWrapper._get_credentialsN)r   r   r   rX   rA  rC  r;  r%   r%   r%   r&   r7  w  s
    r7  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_requestrP   Lock_lock
_exception_crt_futureEvent_done_event)rT   r   
s3_requestr   r%   r%   r&   rX     s   
zCRTTransferCoordinator.__init__c                 C   r   r   )rE  rY   r%   r%   r&   rL    r   z!CRTTransferCoordinator.s3_requestc                 C   r   r   )rK  r  rY   r%   r%   r&   set_done_callbacks_complete  rx   z2CRTTransferCoordinator.set_done_callbacks_completec                 C   r   r   )rK  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   )rG  r   rH  )rT   r   r   r%   r%   r&   r     s   "z$CRTTransferCoordinator.set_exceptionc                 C   s   | j r
| j   d S d S r   )rE  r`   rY   r%   r%   r&   r`     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   )rH  rI  r   r   r`   r   handle_exceptionrE  )rT   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)rD  r   rE   rF   )rT   exctranslated_excr   r%   r%   r&   rO    s   z'CRTTransferCoordinator.handle_exceptionc                 C   s   | j d u rdS | j  S )NF)rI  r   rY   r%   r%   r&   r     s   

zCRTTransferCoordinator.donec                 C   s   || _ | j j| _d S r   )rE  finished_futurerI  )rT   rL  r%   r%   r&   r     s   z%CRTTransferCoordinator.set_s3_request)NNNr   r   )r   r   r   r   rX   r   rL  rM  r   r   r`   r   rO  r   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 )rK   c                 C   s   || _ || _d S r   )_request_serializer	_os_utils)rT   rV   os_utilsr%   r%   r&   rX     s   
zS3ClientArgsCreator.__init__c                 C   s(   t | d| | j}|||||g |dS )N_get_make_request_args_r   r   r   r   on_done_before_callsr   )r  _default_get_make_request_args)rT   r   r   r   r   r   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   )bytes_transferred)r   )r_   r   callbacks_listcallbackr   before_subscriberscallback_typer   r%   r&   invoke_all_callbacks  s   zBS3ClientArgsCreator.get_crt_callback.<locals>.invoke_all_callbacksr%   )rT   r   rb  ra  r   rc  r%   r`  r&   r     s   z$S3ClientArgsCreator.get_crt_callbackc                 C   s   d }t |jtr|j}| j|}||jd< n|j|jd< |jdd }	tj	j
tj	j|	 tj	jjd}
d|jd< | j||||||d}||d	< |
|d
< |S )NContentLengthBodyr   CRC32)	algorithmlocationzoverride-to-be-removed
ContentMD5rX  send_filepathchecksum_config)r   re   r   rU  get_file_sizerf   popr   r   r   S3ChecksumConfigr   S3ChecksumLocationTRAILERrZ  )rT   r   r   r   r   rY  r   rj  data_lenr   rk  make_request_argsr%   r%   r&   !_get_make_request_args_put_object  s6   	

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)validate_responserX  recv_filepathon_bodyrk  )r   r   rn  r   re   r   rU  get_temp_filenamer   RenameTempFileHandlerOnBodyFileObjWriterrZ  )rT   r   r   r   r   rY  r   ru  rv  rk  final_filepathrr  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
r@ttjd
|d< |S )Nr   r\  )r
  typer   on_progressr|   c                 s   s    | ]}|  V  qd S r   )title)r  xr%   r%   r&   	<genexpr>i  s    
zES3ClientArgsCreator._default_get_make_request_args.<locals>.<genexpr>_r#  )rg  signing_config)rT  r   r  r   r   DEFAULTr   r   splitr   rc   r   r   V4_S3EXPRESS)rT   r   r   r   r   rY  r   rr  r%   r%   r&   rZ  P  s(   




z2S3ClientArgsCreator._default_get_make_request_argsr   )	r   r   r   rX   r   r   rs  r{  rZ  r%   r%   r%   r&   rK     s    
*$rK   c                   @   r   )rx  c                 C   s   || _ || _|| _|| _d S r   )r   _final_filename_temp_filenamerI   )rT   r   final_filenametemp_filenamerW   r%   r%   r&   rX   u  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   )rI   remove_filer  rename_filer  r   r   r   )rT   r   r   r   r%   r%   r&   rA  {  s   
zRenameTempFileHandler.__call__Nr   r   r   rX   rA  r%   r%   r%   r&   rx  t  s    rx  c                   @   r   )r   c                 C   r8  r   )r   r   r%   r%   r&   rX     r   zAfterDoneHandler.__init__c                 K   r   r   )r   rM  r   r%   r%   r&   rA    rx   zAfterDoneHandler.__call__Nr  r%   r%   r%   r&   r         r   c                   @   r   )ry  c                 C   r8  r   )_fileobj)rT   re   r%   r%   r&   rX     r   zOnBodyFileObjWriter.__init__c                 K   r   r   )r  write)rT   r5  r   r%   r%   r&   rA    r   zOnBodyFileObjWriter.__call__Nr  r%   r%   r%   r&   ry    r  ry  r   )@loggingrP   ior   awscrt.httpr   	awscrt.s3botocore.awsrequestr  botocore.sessionawscrt.authr   r   r   r   	awscrt.ior   r   r	   r
   r   r   r   r   r   botocore.compatr   botocore.configr   botocore.exceptionsr   s3transfer.constantsr   s3transfer.exceptionsr   s3transfer.futuresr   r   s3transfer.managerr   s3transfer.utilsr   r   r   r   	getLoggerr   rE   r   r'   rC   r8   rG   r   r   r   r   r  r7  r   rK   rx  r   ry  r%   r%   r%   r&   <module>   sZ   


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