
    p hx%                         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dS )    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dS ) 
ClientBasez&A client for accessing the Twilio API.Nusernamepasswordaccount_sidregionhttp_clientenvironmentedgeuser_agent_extensionscredential_providerc
                    |pt           j        }|p|                    d          | _        	 |p|                    d          | _        	 |p|                    d          | _        	 |p|                    d          | _        	 |pg | _        	 |	pd| _        	 |p| j        | _	        	 | j        | j        f| _
        	 |pt                      | _        dS )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
             S/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/twilio/base/client_base.py__init__zClientBase.__init__   s    4 "/RZ IKOO4H$I$I HKOO4G$H$H:KOOM::	@ @ @%:%@b"!#6#>$ *&7$-]DM2	''2'H6F6H6H""    Fmethoduriparamsdataheadersr"   timeoutallow_redirectsreturnc	           
         |                      ||          }| j        r1| j                                        }	|	                                |d<   n&| j        | j        |                     |          }nd}|dk    r|d= |                     |          }|                     |          }
| 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3# 	 4EEGGM'4'D'D'F'FGO$$]&4=+D==&&DDDX!$$11$77''+ ( 	
 	
 		
r&   c	           
        K   | j         j        st          d          |                     ||          }|dk    r|d= | j        r1| j                                        }	|	                                |d<   n&| j        | j        | 	                    |          }nd}| 
                    |          }|                     |          }
| j                             ||||
||||           d{V S )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   s0     6 ( 	P   ""6733X!# 	 4EEGGM'4'D'D'F'FGO$$]&4=+D==&&DDD$$11$77%--+ . 	
 	
 	
 	
 	
 	
 	
 	
 		
r&   c                      t          |t                    r  fd|                                D             S t          |t                    r fd|D             S |S )Nc                 F    i | ]\  }}||                     |          S Nr9   ).0kvr#   s      r$   
<dictcomp>z3ClientBase.copy_non_none_values.<locals>.<dictcomp>   s:       Aq= 4,,Q// ==r&   c                 >    g | ]}|                     |          S rD   rE   )rF   itemr#   s     r$   
<listcomp>z3ClientBase.copy_non_none_values.<locals>.<listcomp>   s3       48DDT))$//DTDTDTr&   )
isinstancedictitemslist)r#   r*   s   ` r$   r9   zClientBase.copy_non_none_values   s    dD!! 		    JJLL   
 d## 	   <@    r&   c                     |p| 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      ty r&   c                    |pi }t           }t          j                    }t          j                    }t          j                    }d                    ||||          |d<   | j        D ]%}|dxx         d                    |          z  cc<   &d                    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_archrX   	extensions           r$   r4   zClientBase.get_headers   s	    -R "/##"$$!022 D K K	!
 !
 3 	= 	=IL!!!U\\)%<%<<!!!!%0%7%7%D%D!" %, !f%nG6S6S&IGN#7"" 2GHr&   c           	         | j         s	| j        s|S t          |          }|j                            d          }|d         }d                    |dd                   }d}d}t          |          dk    r	|d         }n#t          |          dk    r|d         }|d         }| j         p|}| j        p|p|od	}|                    d                    d
 ||||fD                                 }t          t          |                    S )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            us1c                     g | ]}||S  rg   )rF   parts     r$   rL   z+ClientBase.get_hostname.<locals>.<listcomp>  s    UUUdPTUTUUUr&   )netloc)
r   r   r   ri   splitjoinlen_replacestrr	   )r#   r(   
parsed_urlpiecesprefixsuffixr   r   s           r$   r8   zClientBase.get_hostname   s"    y 	 	Jc]]
"((--&+&&v;;!AYFF[[A!9DAYFy D::4>E((88UUvtVV.LUUUVV ) 
 

 :j))***r&   c                 6    d                     | j                  S )zf
        Provide a friendly representation

        :returns: Machine friendly representation
        z<Twilio {}>)rY   r   )r#   s    r$   __repr__zClientBase.__repr__	  s     ##D$4555r&   )	NNNNNNNNN)NNNNNF)__name__
__module____qualname____doc__r   rn   r   r   r   r   r%   r   objectr   floatboolr   r:   rA   r9   r7   r4   r8   rt   rg   r&   r$   r   r      s%       00 #'"&%) $,0:>"59<@.# .#3-.# 3-.# c]	.#
 .# j).# nS#X67.# sm.#  (S	2.# &&89.# .# .# .#h /3,0,0*.#' %3
 3
3
 3
 c6k*+	3

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

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