a
    !f                     @   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eee ej	ee
 ee d fddZde
e
eee
ef  eee
ef  eee
e
f  eee
e
f  ee eed	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                    sX   t  |d| || _|| _|r,t| jdnd| _|durTt|d}t| j|d| _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)Zattempts)Zclient_sessionretry_options)super__init__r   r   r   sessionr   r   )selfr   r   r   r   r   r   r   	__class__ ^/var/www/html/python-backend/venv/lib/python3.9/site-packages/twilio/http/async_http_client.pyr      s    
zAsyncTwilioHttpClient.__init__F)	methodurlparamsdataheadersauthr   allow_redirectsreturnc	              	      s   |dur|dkrt |d}	|dur8t|d |d d}	| |||||	||d}
| |
 d| _d}d}| jrx| j}n
t }d}tf i |
| _|j	f i |
I dH }| 
|j| t|j| I dH |j| _|r| 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"   FT)
ValueErrorr   upperZlog_requestZ_test_only_last_responser   r   TwilioRequestZ_test_only_last_requestrequestZ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                    s   | j r| j  I dH  dS )z0
        Closes the HTTP client session
        Nr   r-   r   r   r   r   r-   u   s    zAsyncTwilioHttpClient.closec                    s   | S )z-
        Async context manager setup
        r   r3   r   r   r   
__aenter__|   s    z AsyncTwilioHttpClient.__aenter__c                    s   | j r| j  I dH  dS )z,
        Async context manager exit
        Nr2   )r   excinfor   r   r   	__aexit__   s    zAsyncTwilioHttpClient.__aexit__)NNNNNF)__name__
__module____qualname____doc___loggerboolr   floatloggingLoggerstrintr   r   objectr   r   r*   r-   r4   r6   __classcell__r   r   r   r   r      sD   &      @r   )r>   typingr   r   r   Zaiohttpr   r   Zaiohttp_retryr   r   Ztwilio.httpr	   Ztwilio.http.requestr
   r)   Ztwilio.http.responser   	getLoggerr;   r   r   r   r   r   <module>   s   
