o
    4g                     @   s   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
 d
eZdS )    N)DictListMutableMappingOptionalTuple)urlparse
urlunparse)__version__)TwilioException)
HttpClient)TwilioHttpClient)Responsec                   @   s  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  fd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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dZdeeeef  deeef fddZdedee
eef  de
eef fddZdedefdd Zdefd!d"ZdS )%
ClientBasez&A client for accessing the Twilio API.Nusernamepasswordaccount_sidregionhttp_clientenvironmentedgeuser_agent_extensionsc	           	      C   s   |pt j}|p|d| _	 |p|d| _	 |p|d| _	 |p&|d| _	 |p,g | _	 | jr5| js9td|p=| j| _		 | j| jf| _
	 |pLt | _dS )am  
        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
        TWILIO_ACCOUNT_SIDTWILIO_AUTH_TOKENTWILIO_EDGETWILIO_REGIONz1Credentials are required to create a TwilioClientN)osenvirongetr   r   r   r   r   r
   r   authr   r   )	selfr   r   r   r   r   r   r   r    r    c/var/www/html/Testing_prj/Navya-Bakers/venv/lib/python3.10/site-packages/twilio/base/client_base.py__init__   s&   

zClientBase.__init__Fmethoduriparamsdataheadersr   timeoutallow_redirectsreturnc	           	   
   C   s<   |  |}| ||}| |}| jj||||||||d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
        r%   r&   r'   r   r(   r)   )get_authget_headersget_hostnamer   request	r   r#   r$   r%   r&   r'   r   r(   r)   r    r    r!   r/   >   s   

zClientBase.requestc	           	   
      sT   | j js	td| |}| ||}| |}| j j||||||||dI dH 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 requestsr+   N)r   is_asyncRuntimeErrorr,   r-   r.   r/   r0   r    r    r!   request_asyncg   s$   

zClientBase.request_asyncc                 C   s
   |p| j S )z
        Get the request authentication object
        :param auth: Authentication (username, password)
        :returns: The authentication object
        )r   )r   r   r    r    r!   r,      s   
zClientBase.get_authc                 C   s   |pi }t }t }t }t }d|||||d< | jD ]}|d  d|7  < qdt |d< d|d< |dkrDd	|vrDd
|d	< d|vrLd|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POSTzContent-Typez!application/x-www-form-urlencodedAcceptzapplication/json)r	   platformsystemmachinepython_versionformatr   )r   r#   r'   pkg_versionos_nameos_archr9   	extensionr    r    r!   r-      s(   	
zClientBase.get_headersc                 C   s   | 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pI|pI|oId	}|jdd
d ||||fD 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                 S   s   g | ]}|r|qS r    r    ).0partr    r    r!   
<listcomp>   s    z+ClientBase.get_hostname.<locals>.<listcomp>)netloc)
r   r   r   rI   splitjoinlen_replacestrr   )r   r$   
parsed_urlpiecesprefixsuffixr   r   r    r    r!   r.      s&   	

zClientBase.get_hostnamec                 C   s   d | jS )zf
        Provide a friendly representation

        :returns: Machine friendly representation
        z<Twilio {}>)r:   r   )r   r    r    r!   __repr__   s   zClientBase.__repr__)NNNNNNNN)NNNNNF)__name__
__module____qualname____doc__r   rN   r   r   r   r"   r   objectr   floatboolr   r/   r3   r,   r-   r.   rS   r    r    r    r!   r      s    
	
2	

-	

&/

$"r   )r   r6   typingr   r   r   r   r   urllib.parser   r   twilior	   twilio.base.exceptionsr
   twilio.httpr   twilio.http.http_clientr   twilio.http.responser   rX   r   r    r    r    r!   <module>   s    