U
    EZh                     @   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_clientZboto3c                 C   s   |d|d}t f |S )zCreate a CRT S3 Client for file transfer.

    Instantiating many of these may lead to degraded performance or
    system resource exhaustion.
    T)regionZuse_sslZcrt_credentials_provider)r   )sessionconfigregion_namecred_providerZcreate_crt_client_kwargs r   P/home/aprabhat/apps/x.techxrdev.in/venv/lib/python3.8/site-packages/boto3/crt.py_create_crt_client*   s
    r   c                 C   s   t | |d dS )N)r   Z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   Zto_crt_credentials_providerCRTS3Clientr   )r	   r
   r   credentialslockkwargsZcred_wrapperr   r   r   r   _create_crt_s3_client>   s    r   c                 C   sL   t t}|d k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   s2   t $ td kr$t| |\}}|a|aW 5 Q R X 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krdS |   }|dkr dS t| |j}| jj|jk}|oD|S )z
    Boto3 client must use same signing region and credentials
    as the CRT_S3_CLIENT singleton. Otherwise fallback to classic.
    NF)r   compare_identityZget_frozen_credentialsr   r   r   r   )r   crt_s3_clientboto3_credsZis_same_identityZis_same_regionr   r   r   is_crt_compatible_request   s     r-   c                 C   sN   z
| }W n t jjk
r$   Y dS X | j|jkoH| j|jkoH| j|jk}|S )NF)	botocore
exceptionsZNoCredentialsErrorZ
access_keyZaccess_key_idZ
secret_keyZsecret_access_keytokenZsession_token)r,   Zcrt_s3_credsZ	crt_credsZis_matching_identityr   r   r   r*      s    


r*   c                 C   s$   t | |}t| |r t|jtS dS )z8Create a CRTTransferManager for optimized data transfer.N)r!   r-   r   r"   r    )r   r
   r+   r   r   r   create_crt_transfer_manager   s    

 r1   )r)   	threadingZbotocore.exceptionsr.   Zbotocore.sessionr   Zs3transfer.crtr   r   r   r   r   r   r    Lockr   r   r   r   r   r   r!   r   r-   r*   r1   r   r   r   r   <module>   s"   		