
    pib(                         d dl Z d dlZd dlZd dlmZmZmZ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 d dlmZ d dlmZ  G d	 d
e      Zy)    N)DictListMutableMappingOptionalTuple)urlparse
urlunparse)__version__)
HttpClient)TwilioHttpClient)Response)CredentialProviderc                   (   e Zd ZdZdddddddd	d
d	Z	 	 	 	 	 	 	 	 	 d'dee   dee   dee   dee   dee   deeeef      dee   dee	e      dee
   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(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eeeef      deeef   fd#Zdedeeeef      deeef   fd$Zdedefd%Zdefd&Zy))
ClientBasez&A client for accessing the Twilio API.sydneyz	sao-paulo	frankfurtdublintokyoosaka	singaporeashburnumatilla)	au1br1de1ie1jp1jp2sg1us1us2Nusernamepasswordaccount_sidregionhttp_clientenvironmentedgeuser_agent_extensionscredential_providerc
                 4   |xs t         j                  }|xs |j                  d      | _        	 |xs |j                  d      | _        	 ||||t        j                  dt        d       |xs& |j                  d      xs || j                  |   nd| _	        	 |xs |j                  d	      | _
        	 |xs g | _        	 |	xs d| _        	 |xs | j                  | _        	 | j                  | j                  f| _        	 |xs
 t               | _        y)
a  
        Initializes the Twilio Client

        :param username: Username to authenticate with
        :param password: Password to authenticate with
        :param account_sid: Account SID, defaults to Username
        :param region: Twilio Region to make requests to, defaults to 'us1' if an edge is provided
        :param http_client: HttpClient, defaults to TwilioHttpClient
        :param environment: Environment to look for auth details, defaults to os.environ
        :param edge: Twilio Edge to make requests to, defaults to None.
        :param user_agent_extensions: Additions to the user agent string
        :param credential_provider: credential provider for authentication method that needs to be used
        TWILIO_ACCOUNT_SIDTWILIO_AUTH_TOKENNzoFor regional processing, DNS is of format product.<edge>.<region>.twilio.com; otherwise use product.twilio.com.   )
stacklevelTWILIO_EDGE TWILIO_REGION)osenvirongetr"   r#   warningswarnDeprecationWarningregion_mappingsr(   r%   r)   r*   r$   authr   r&   )
selfr"   r#   r$   r%   r&   r'   r(   r)   r*   s
             Y/opt/services/ai/voice_agent/venv/lib/python3.12/site-packages/twilio/base/client_base.py__init__zClientBase.__init__   s%   4 "/RZZ IKOO4H$I HKOO4G$H4<MM B"  L}-L060B$$V, 		
 	@ @%:%@b"!#6#>$ *&7$--]]DMM2	''2'H6F6H"    methoduriparamsdataheadersr:   timeoutallow_redirectsreturnc	           
         | j                  ||      }| j                  r.| j                  j                         }	|	j                         |d<   n,| j                  | j
                  | j                  |      }nd}|dk(  r|d= | j                  |      }| j                  |      }
| j                  j                  ||||
||||      S )a(  
        Makes a request to the Twilio API using the configured http client
        Authentication information is automatically added if none is provided

        :param method: HTTP Method
        :param uri: Fully qualified url
        :param params: Query string parameters
        :param data: POST body data
        :param headers: HTTP Headers
        :param auth: Authentication
        :param timeout: Timeout in seconds
        :param allow_redirects: Should the client follow redirects

        :returns: Response from the Twilio API
        AuthorizationNDELETEAcceptrA   rB   rC   r:   rD   rE   )get_headersr*   to_auth_strategyget_auth_stringr"   r#   get_authget_hostnamecopy_non_none_valuesr&   requestr;   r?   r@   rA   rB   rC   r:   rD   rE   auth_strategyfiltered_datas              r<   rR   zClientBase.requestY   s    4 ""673## 44EEGM'4'D'D'FGO$]]&4==+D==&DDX!$11$7''+ ( 	
 		
r>   c	           
        K   | j                   j                  st        d      | j                  ||      }|dk(  r|d= | j                  r.| j                  j                         }	|	j                         |d<   n,| j                  | j                  | j                  |      }nd}| j                  |      }| j                  |      }
| j                   j                  ||||
||||       d{   S 7 w)a  
        Asynchronously makes a request to the Twilio API  using the configured http client
        The configured http client must be an asynchronous http client
        Authentication information is automatically added if none is provided

        :param method: HTTP Method
        :param uri: Fully qualified url
        :param params: Query string parameters
        :param data: POST body data
        :param headers: HTTP Headers
        :param auth: Authentication
        :param timeout: Timeout in seconds
        :param allow_redirects: Should the client follow redirects

        :returns: Response from the Twilio API
        z>http_client must be asynchronous to support async API requestsrI   rJ   rH   NrK   )r&   is_asyncRuntimeErrorrL   r*   rM   rN   r"   r#   rO   rP   rQ   rR   rS   s              r<   request_asynczClientBase.request_async   s    6 ((P  ""673X!## 44EEGM'4'D'D'FGO$]]&4==+D==&DD$11$7%%--+ . 	
 	
 		
 	
s   C*C3,C1-C3c                 
   t        |t              r5|j                         D ci c]  \  }}||| j                  |       c}}S t        |t              r"|D cg c]  }|| j                  |       c}S |S c c}}w c c}w )N)
isinstancedictitemsrQ   list)r;   rB   kvitems        r<   rQ   zClientBase.copy_non_none_values   s    dD! !JJLAq= 4,,Q// 
 d#<@48DDT))$/  s   A:B "B c                 "    |xs | j                   S )z
        Get the request authentication object
        :param auth: Authentication (username, password)
        :returns: The authentication object
        )r:   )r;   r:   s     r<   rO   zClientBase.get_auth   s      tyy r>   c                    |xs i }t         }t        j                         }t        j                         }t        j                         }dj                  ||||      |d<   | j                  D ]  }|dxx   dj                  |      z  cc<     dj                  t               |d<   d|d<   |dk(  s|d	k(  r	d
|vrd|d
<   d|vrd|d<   |S )z
        Get the request headers including user-agent, extensions, encoding, content-type, MIME type
        :param method: HTTP method
        :param headers: HTTP headers
        :returns: HTTP headers
        z"twilio-python/{} ({} {}) Python/{}z
User-Agentz {}z	python-{}zX-Twilio-Clientzutf-8zAccept-CharsetPOSTPUTzContent-Typez!application/x-www-form-urlencodedrJ   zapplication/json)r
   platformsystemmachinepython_versionformatr)   )r;   r?   rC   pkg_versionos_nameos_archri   	extensions           r<   rL   zClientBase.get_headers   s     -R "//#""$!002 D K K	!
 33 	=IL!U\\)%<<!	=%0%7%7%D!" %, !f%nG6S&IGN#7" 2GHr>   c                    | j                   s| j                  s|S t        |      }|j                  j	                  d      }|d   }dj                  |dd       }d}d}t        |      dk(  r|d   }nt        |      dk(  r
|d   }|d   }| j                   xs |}| j                  xs
 |xs |xr d	}|j                  dj                  ||||fD cg c]  }|s|	 c}      
      }t        t        |            S c c}w )z
        Determines the proper hostname given edge and region preferences
        via client configuration or uri.

        :param uri: Fully qualified url

        :returns: The final uri used to make the request
        .r   N         r.   r    )netloc)
r(   r%   r   ru   splitjoinlen_replacestrr	   )	r;   r@   
parsed_urlpiecesprefixsuffixr%   r(   parts	            r<   rP   zClientBase.get_hostname   s    yyJc]
""((-&+&v;!AYF[A!9DAYFyy D::4>E((88vtVV.LUdPTTUV ) 

 :j)** Vs   C<C<c                 8    dj                  | j                        S )zf
        Provide a friendly representation

        :returns: Machine friendly representation
        z<Twilio {}>)rj   r$   )r;   s    r<   __repr__zClientBase.__repr__"  s     ##D$4$455r>   )	NNNNNNNNN)NNNNNF)__name__
__module____qualname____doc__r9   r   rz   r   r   r   r   r=   r   objectr   floatboolr   rR   rY   rQ   rO   rL   rP   r    r>   r<   r   r      s   0 
O #'"&%) $,0:>"59<@:#3-:# 3-:# c]	:#
 :# j):# nS#X67:# sm:#  (S	2:# &&89:#@ /3,0,0*.#' %3
3
 3
 c6k*+	3

 tCK()3
 $sCx.)3
 uS#X'3
 %3
 3
 
3
r /3,0,0*.#' %7
7
 7
 c6k*+	7

 tCK()7
 $sCx.)7
 uS#X'7
 %7
 7
 
7
r!XeCHo6 !5c? !""$,T#s(^$<"	c3h"H +  +  +D6# 6r>   r   )r3   rf   r6   typingr   r   r   r   r   urllib.parser   r	   twilior
   twilio.httpr   twilio.http.http_clientr   twilio.http.responser   %twilio.credential.credential_providerr   r   r   r   r>   r<   <module>r      s4    	   > > -  " 4 ) DZ6 Z6r>   