o
    eH                     @   sv   d dl Z d dlmZ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 e dZG d	d
 d
e
ZdS )    N)RequestSessionhooks)HTTPAdapter)	urlencode)
HttpClient)r   )Responseztwilio.http_clientc                   @   sD   e Zd ZdZdddeddfddZ		dddZd	d
 Zdd ZdS )TwilioHttpClientzI
    General purpose HTTP Client for interacting with the Twilio API
    TNc                 C   sz   |rt  nd| _| jr|dur| jdt|d d| _d| _|| _|p't | _	|dur5|dkr5t
||| _|| _dS )a  
        Constructor for the TwilioHttpClient

        :param bool pool_connections
        :param request_hooks
        :param int timeout: Timeout for the requests.
                            Timeout should never be zero (0) or less.
        :param logger
        :param dict proxy: Http proxy for the requests session
        :param int max_retries: Maximum number of retries each request should attempt
        Nzhttps://)max_retriesr   )r   sessionmountr   last_requestlast_responseloggerr   default_hooksrequest_hooks
ValueErrortimeoutproxy)selfpool_connectionsr   r   r   r   r
    r   J/var/www/html/venv/lib/python3.10/site-packages/twilio/http/http_client.py__init__   s   
zTwilioHttpClient.__init__Fc	                 C   s   |dur|dkrt || |||||| jd}	| |	 d| _| jp&t }
| jr.| j|
_t	di |	}t
di |	| _|
|}|
j|||durL|n| jd}| | tt|j|j|j| _| jS )a  
        Make an HTTP Request with parameters provided.

        :param str method: The HTTP method to use
        :param str url: The URL to request
        :param dict params: Query parameters to append to the URL
        :param dict data: Parameters to go in the body of the HTTP request
        :param dict headers: HTTP Headers to send with the request
        :param tuple auth: Basic Auth arguments
        :param float timeout: Socket/Read timeout for the request
        :param boolean allow_redirects: Whether or not to allow redirects
        See the requests documentation for explanation of all these parameters

        :return: An http response
        :rtype: A :class:`Response <twilio.rest.http.response.Response>` object
        Nr   )methodurlparamsdataheadersauthr   )allow_redirectsr   r   )r   upperr   _log_requestr   r   r   r   proxiesr   TwilioRequestr   prepare_requestsendr   _log_responser   intstatus_codetextr   )r   r   r   r   r   r   r   r   r    kwargsr   requestprepped_requestresponser   r   r   r,   ,   s4   



zTwilioHttpClient.requestc              	   C   s   | j d |d r)| j d|d |d t|d  | j d|d  n| j d|d |d  |d r\| j d	 |d  D ]\}}d
| vr[| j d|| qG| j d d S )Nz-- BEGIN Twilio API Request --r   z{} Request: {}?{}r   r   zQuery Params: {}z{} Request: {}r   zHeaders:authorizationz{} : {}z-- END Twilio API Request --)r   infoformatr   itemslower)r   r+   keyvaluer   r   r   r"   a   s   &zTwilioHttpClient._log_requestc                 C   s,   | j d|j | j d|j d S )NzResponse Status Code: {}zResponse Headers: {})r   r0   r1   r)   r   )r   r.   r   r   r   r'   s   s   zTwilioHttpClient._log_response)NNNNNF)	__name__
__module____qualname____doc___loggerr   r,   r"   r'   r   r   r   r   r	      s    


5r	   )loggingrequestsr   r   r   requests.adaptersr   urllib.parser   twilio.httpr   twilio.http.requestr$   twilio.http.responser   	getLoggerr:   r	   r   r   r   r   <module>   s    
