
    gx%                         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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.Nusernamepasswordaccount_sidregionhttp_clientenvironmentedgeuser_agent_extensionscredential_providerc
                    |xs t         j                  }|xs |j                  d      | _        	 |xs |j                  d      | _        	 |xs |j                  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_TOKENTWILIO_EDGETWILIO_REGIONN)osenvirongetr   r   r   r   r   r   r   authr   r   )
selfr   r   r   r   r   r   r   r   r   s
             T/var/www/html/Manimaran/venv/lib/python3.12/site-packages/twilio/base/client_base.py__init__zClientBase.__init__   s    4 "/RZZ IKOO4H$I HKOO4G$H:KOOM:	@ @%:%@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r)   r*   r+   r"   r,   r-   )get_headersr   to_auth_strategyget_auth_stringr   r   get_authget_hostnamecopy_non_none_valuesr   requestr#   r'   r(   r)   r*   r+   r"   r,   r-   auth_strategyfiltered_datas              r$   r:   zClientBase.request@   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 requestsr1   r2   r0   Nr3   )r   is_asyncRuntimeErrorr4   r   r5   r6   r   r   r7   r8   r9   r:   r;   s              r$   request_asynczClientBase.request_asyncu   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itemsr9   list)r#   r*   kvitems        r$   r9   zClientBase.copy_non_none_values   s    dD! !JJL(DAq= 4,,Q//( 
 d#<@<@DDDT))$/D  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$   r7   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-urlencodedr2   zapplication/json)r
   platformsystemmachinepython_versionformatr   )r#   r'   r+   pkg_versionos_nameos_archrQ   	extensions           r$   r4   zClientBase.get_headers   s     -R "//#""$!002 D K K	!
 33IL!U\\)%<<! 4%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            us1)netloc)
r   r   r   r_   splitjoinlen_replacestrr	   )	r#   r(   
parsed_urlpiecesprefixsuffixr   r   parts	            r$   r8   zClientBase.get_hostname   s
    yyJc]
""((-&+&v;!AYF[A!9DAYFyy D::4>E((88vtVV.LU.LdPTT.LUV ) 

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

        :returns: Machine friendly representation
        z<Twilio {}>)rR   r   )r#   s    r$   __repr__zClientBase.__repr__	  s     ##D$4$455r&   )	NNNNNNNNN)NNNNNF)__name__
__module____qualname____doc__r   rd   r   r   r   r   r%   r   objectr   floatboolr   r:   rA   r9   r7   r4   r8   rk    r&   r$   r   r      s   0 #'"&%) $,0:>"59<@.#3-.# 3-.# c]	.#
 .# j).# nS#X67.# sm.#  (S	2.# &&89.#h /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   )r   rN   typingr   r   r   r   r   urllib.parser   r	   twilior
   twilio.httpr   twilio.http.http_clientr   twilio.http.responser   %twilio.credential.credential_providerr   rp   r   rs   r&   r$   <module>r{      s1    	  > > -  " 4 ) DB6 B6r&   