
    pi                         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 j$                  d      Z G d	 d
e      Zy)    N)DictOptionalTuple)	BasicAuthClientSession)ExponentialRetryRetryClient)AsyncHttpClient)Request)Responseztwilio.async_http_clientc                        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	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Zd Zd Zd Z xZS )AsyncTwilioHttpClientzV
    General purpose asynchronous HTTP Client for interacting with the Twilio API
    TNpool_connectionstimeoutlogger	proxy_urlmax_retriesc                     t         |   |d|       || _        || _        |rt	        | j                        nd| _        |)t        |      }t        | j
                  |      | _        yy)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__s	           _/opt/services/ai/voice_agent/venv/lib/python3.12/site-packages/twilio/http/async_http_client.pyr   zAsyncTwilioHttpClient.__init__   sp    ( 	w/"*   (:(:; 	
 ",kBM&#||=DL #    methodurlparamsdataheadersauthallow_redirectsreturnc	           	      l  K   ||dk  rt        |      d}	|t        |d   |d         }	|j                         |||||	||d}
| j                  |
       d| _        d}d}| j
                  r| j
                  }nt               }d}t        di |
| _         |j                  di |
 d{   }| j                  |j                  |       t        |j                  |j                          d{   |j                        | _        |r|j                          d{    | j                  S 7 7 @7 w)	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   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   responses                 r   r3   zAsyncTwilioHttpClient.request5   s5    4 7a<W%%
"a47CJ lln.	
 	 (,%<<llG#oGD'4'>v'>$(2622(//84(0OO8==?2H4D4D)
% --/!!,,, 3 3 "s7   B)D4+D.,AD4/D0
0-D4D2D40D42D4c                 n   K   | j                   r#| j                   j                          d{    yy7 w)z0
        Closes the HTTP client session
        Nr   r7   r   s    r   r7   zAsyncTwilioHttpClient.closeu   -      <<,,$$&&& &   *535c                    K   | S w)z-
        Async context manager setup
        r,   r>   s    r   
__aenter__z AsyncTwilioHttpClient.__aenter__|   s      s   c                 n   K   | j                   r#| j                   j                          d{    yy7 w)z,
        Async context manager exit
        Nr=   )r   excinfos     r   	__aexit__zAsyncTwilioHttpClient.__aexit__   r?   r@   )NNNNNF)__name__
__module____qualname____doc___loggerboolr   floatloggingLoggerstrintr   r   objectr   r   r3   r7   rB   rE   __classcell__)r   s   @r   r   r      s    "&#'!(#'%)   %	 
   C=  c] L /3,0,0*.#' %>->- >- c6k*+	>-
 tCK()>- $sCx.)>- uS#X'>- %>- >- 
>-@''r   r   )rM   typingr   r   r   aiohttpr   r   aiohttp_retryr   r	   twilio.httpr
   twilio.http.requestr   r1   twilio.http.responser   	getLoggerrJ   r   r,   r   r   <module>rZ      s>     ( ( , 7 ' 8 )
'

6
7y'O y'r   