
    =h                         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__)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y)
ClientBasez&A client for accessing the Twilio API.Nusernamepasswordaccount_sidregionhttp_clientenvironmentedgeuser_agent_extensionsc	                    |xs t         j                  }|xs |j                  d      | _        	 |xs |j                  d      | _        	 |xs |j                  d      | _        	 |xs |j                  d      | _        	 |xs g | _        	 | j                  r| j                  st        d      |xs | j                  | _	        	 | j                  | j                  f| _
        	 |xs
 t               | _        y)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	            g/var/www/html/phonemate/phone_mate_backend/venv/lib/python3.12/site-packages/twilio/base/client_base.py__init__zClientBase.__init__   s    . "/RZZ IKOO4H$I HKOO4G$H:KOOM:	@ @%:%@b"!}}DMM!"UVV&7$--]]DMM2	''2'H6F6H"    methoduriparamsdataheadersr!   timeoutallow_redirectsreturnc	           
          | j                  |      }| 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
        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>   sj    4 }}T"""673$''+ ( 	
 		
r%   c	           
        K   | j                   j                  st        d      | j                  |      }| 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 requestsr/   N)r   is_asyncRuntimeErrorr0   r1   r2   r3   r4   s	            r#   request_asynczClientBase.request_asyncg   s     6 ((P  }}T"""673$%%--+ . 	
 	
 		
 	
s   A<B>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#   r0   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(  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02 D K K	!
 33IL!U\\)%<<! 4%0%7%7%D!" %, !Vg =&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   rN   splitjoinlen_replacestrr	   )	r"   r'   
parsed_urlpiecesprefixsuffixr   r   parts	            r#   r2   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 {}>)rA   r   )r"   s    r#   __repr__zClientBase.__repr__   s     ##D$4$455r%   )NNNNNNNN)NNNNNF)__name__
__module____qualname____doc__r   rS   r   r   r   r$   r   objectr   floatboolr   r3   r8   r0   r1   r2   rZ    r%   r#   r   r      sv   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# 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   r_   r   rb   r%   r#   <module>rj      s1    	  > > -  2 " 4 )]6 ]6r%   