o
    f>h                     @   s~   d dl Z d dlmZmZ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 d dlmZ e dZG d	d
 d
eZdS )    N)DictOptionalTuple)	BasicAuthClientSession)ExponentialRetryRetryClient)AsyncHttpClient)Request)Responseztwilio.async_http_clientc                       s   e Zd ZdZdddeddfdedee dej	dee
 dee f
 fd	d
Z						dde
de
deee
ef  deee
ef  deee
e
f  deee
e
f  dee dedefddZdd Zdd Zdd Z  ZS )AsyncTwilioHttpClientzV
    General purpose asynchronous HTTP Client for interacting with the Twilio API
    TNpool_connectionstimeoutlogger	proxy_urlmax_retriesc                    s\   t  |d| || _|| _|rt| jdnd| _|dur,t|d}t| j|d| _dS dS )a  
        Constructor for the AsyncTwilioHttpClient

        :param pool_connections: Creates a client session for making requests from.
        :param trace_configs: Configuration used to trace request lifecycle events. See aiohttp library TraceConfig
                              documentation for more info.
        :param timeout: Timeout for the requests (seconds)
        :param logger
        :param proxy_url: Proxy URL
        :param max_retries: Maximum number of retries each request should attempt
        T)trace_configsN)attempts)client_sessionretry_options)super__init__r   r   r   sessionr   r   )selfr   r   r   r   r   r   r   	__class__ P/var/www/html/venv/lib/python3.10/site-packages/twilio/http/async_http_client.pyr      s   
zAsyncTwilioHttpClient.__init__Fmethodurlparamsdataheadersauthallow_redirectsreturnc	              	      s   |dur|dkrt |d}	|durt|d |d d}	| |||||	||d}
| |
 d| _d}d}| jr=| j}nt }d}tdi |
| _|j	di |
I dH }| 
|j| t|j| I dH |j| _|rs| I dH  | jS )	a  
        Make an asynchronous HTTP Request with parameters provided.

        :param method: The HTTP method to use
        :param url: The URL to request
        :param params: Query parameters to append to the URL
        :param data: Parameters to go in the body of the HTTP request
        :param headers: HTTP Headers to send with the request
        :param auth: Basic Auth arguments (username, password entries)
        :param timeout: Socket/Read timeout for the request. Overrides the timeout if set on the client.
        :param allow_redirects: Whether or not to allow redirects
        See the requests documentation for explanation of all these parameters

        :return: An http response
        Nr      )loginpassword)r   r   r    r!   r"   r#   r   r$   FTr   )
ValueErrorr   upperlog_request_test_only_last_responser   r   TwilioRequest_test_only_last_requestrequestlog_responsestatusr   textr"   close)r   r   r   r    r!   r"   r#   r   r$   
basic_authkwargstempr   responser   r   r   r/   5   s@   
zAsyncTwilioHttpClient.requestc                        | j r| j  I dH  dS dS )z0
        Closes the HTTP client session
        Nr   r3   r   r   r   r   r3   u      zAsyncTwilioHttpClient.closec                    s   | S )z-
        Async context manager setup
        r   r:   r   r   r   
__aenter__|   s   z AsyncTwilioHttpClient.__aenter__c                    r8   )z,
        Async context manager exit
        Nr9   )r   excinfor   r   r   	__aexit__   r;   zAsyncTwilioHttpClient.__aexit__)NNNNNF)__name__
__module____qualname____doc___loggerboolr   floatloggingLoggerstrintr   r   objectr   r   r/   r3   r<   r>   __classcell__r   r   r   r   r      s^    &	

@r   )rF   typingr   r   r   aiohttpr   r   aiohttp_retryr   r   twilio.httpr	   twilio.http.requestr
   r-   twilio.http.responser   	getLoggerrC   r   r   r   r   r   <module>   s    
