o
    Rh                     @   s   d Z ddlZddlZddlmZ ddlmZmZm	Z	m
Z
mZ dadae ZdZdd Zdd	 Zd
d Zdd Zdd ZG dd dZdd Zdd Zdd ZdS )a6  
This file contains private functionality for interacting with the AWS
Common Runtime library (awscrt) in boto3.

All code contained within this file is for internal usage within this
project and is not intended for external consumption. All interfaces
contained within are subject to abrupt breaking changes.
    N)Session)BotocoreCRTCredentialsWrapperBotocoreCRTRequestSerializerCRTTransferManageracquire_crt_s3_process_lockcreate_s3_crt_clientboto3c                 C   s   |d|d}t di |S )zCreate a CRT S3 Client for file transfer.

    Instantiating many of these may lead to degraded performance or
    system resource exhaustion.
    T)regionuse_sslcrt_credentials_providerN )r   )sessionconfigregion_namecred_providercreate_crt_client_kwargsr   r   K/home/air/sanwanet/backup_V2/venv/lib/python3.10/site-packages/boto3/crt.py_create_crt_client*   s
   r   c                 C   s   t | |d dS )N)r   endpoint_url)r   )r   r   r   r   r   _create_crt_request_serializer8   s   
r   c                 K   s(   t |}| }tt| ||||||S )zFCreate boto3 wrapper class to manage crt lock reference and S3 client.)r   to_crt_credentials_providerCRTS3Clientr   )r   r   r   credentialslockkwargscred_wrapperr   r   r   r   _create_crt_s3_client>   s   r   c                 C   sL   t t}|d u r
dS t }| jj}|  }t||}t|||||}||fS )N)NN)r   PROCESS_LOCK_NAMEr   metar   _get_credentialsr   r   )clientr   r   r   r   r   
serializer	s3_clientr   r   r   #_initialize_crt_transfer_primativesL   s   

r#   c                 C   sX   t   td u rt| |\}}|a|aW d    tS W d    tS 1 s%w   Y  tS N)CLIENT_CREATION_LOCKCRT_S3_CLIENTr#   BOTOCORE_CRT_SERIALIZER)r    r   r!   r"   r   r   r   get_crt_s3_client_   s   

r(   c                   @   s   e Zd ZdZdd ZdS )r   a  
    This wrapper keeps track of our underlying CRT client, the lock used to
    acquire it and the region we've used to instantiate the client.

    Due to limitations in the existing CRT interfaces, we can only make calls
    in a single region and does not support redirects. We track the region to
    ensure we don't use the CRT client when a successful request cannot be made.
    c                 C   s   || _ || _|| _|| _d S r$   )
crt_clientprocess_lockr	   r   )selfr)   r*   r	   r   r   r   r   __init__x   s   
zCRTS3Client.__init__N)__name__
__module____qualname____doc__r,   r   r   r   r   r   n   s    	r   c                 C   sF   |du rdS |   }|du rdS t| |j}| jj|jk}|o"|S )z
    Boto3 client must use same signing region and credentials
    as the CRT_S3_CLIENT singleton. Otherwise fallback to classic.
    NF)r   compare_identityget_frozen_credentialsr   r   r   r	   )r    crt_s3_clientboto3_credsis_same_identityis_same_regionr   r   r   is_crt_compatible_request   s   
r7   c                 C   sL   z| }W n t jjy   Y dS w | j|jko#| j|jko#| j|jk}|S )NF)	botocore
exceptionsNoCredentialsError
access_keyaccess_key_id
secret_keysecret_access_keytokensession_token)r4   crt_s3_creds	crt_credsis_matching_identityr   r   r   r1      s   


r1   c                 C   s$   t | |}t| |rt|jtS dS )z8Create a CRTTransferManager for optimized data transfer.N)r(   r7   r   r)   r'   )r    r   r3   r   r   r   create_crt_transfer_manager   s   

rD   )r0   	threadingbotocore.exceptionsr8   botocore.sessionr   s3transfer.crtr   r   r   r   r   r&   r'   Lockr%   r   r   r   r   r#   r(   r   r7   r1   rD   r   r   r   r   <module>   s$   		