
    bf                         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__)TwilioException)
HttpClient)TwilioHttpClient)Responsec                      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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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_extensionsc	                    |pt           j        }|p|                    d          | _        	 |p|                    d          | _        	 |p|                    d          | _        	 |p|                    d          | _        	 |pg | _        	 | j        r| j        st          d          |p| j        | _	        	 | j        | j        f| _
        	 |pt                      | _        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   s	            Q/var/www/html/Alfredo/env/lib/python3.11/site-packages/twilio/base/client_base.py__init__zClientBase.__init__   s    . "/RZ IKOO4H$I$I HKOO4G$H$H:KOOM::	@ @ @%:%@b"!} 	WDM 	W!"UVVV&7$-]DM2	''2'H6F6H6H""    Fmethoduriparamsdataheadersr!   timeoutallow_redirectsreturnc	           
          |                      |          }|                     ||          }|                     |          }| 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
        r(   r)   r*   r!   r+   r,   )get_authget_headersget_hostnamer   request	r"   r&   r'   r(   r)   r*   r!   r+   r,   s	            r#   r3   zClientBase.request>   su    4 }}T""""6733$$''+ ( 	
 	
 		
r%   c	           
        K   | j         j        st          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 requestsr/   N)r   is_asyncRuntimeErrorr0   r1   r2   r3   r4   s	            r#   request_asynczClientBase.request_asyncg   s      6 ( 	P   }}T""""6733$$%--+ . 	
 	
 	
 	
 	
 	
 	
 	
 		
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#   r0   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    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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_archr@   	extensions           r#   r1   zClientBase.get_headers   s    -R "/##"$$!022 D K K	!
 !
 3 	= 	=IL!!!U\\)%<%<<!!!!%0%7%7%D%D!" %, !Vg = =&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  rO   ).0parts     r#   
<listcomp>z+ClientBase.get_hostname.<locals>.<listcomp>   s    UUUdPTUTUUUr%   )netloc)
r   r   r   rS   splitjoinlen_replacestrr	   )r"   r'   
parsed_urlpiecesprefixsuffixr   r   s           r#   r2   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 {}>)rA   r   )r"   s    r#   __repr__zClientBase.__repr__   s     ##D$4555r%   )NNNNNNNN)NNNNNF)__name__
__module____qualname____doc__r   rX   r   r   r   r$   r   objectr   floatboolr   r3   r8   r0   r1   r2   r^   rO   r%   r#   r   r      s       00 #'"&%) $,0:>"59,# ,#3-,# 3-,# c]	,#
 ,# j),# nS#X67,# sm,#  (S	2,# ,# ,# ,#d /3,0,0*.#' %'
 '
'
 '
 c6k*+	'

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

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