
    p h                         d dl 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  edg d	          Z G d
 de
          ZdS )    )
namedtuple)RequestSession)TwilioRestException)urlparse)
HttpClient)Response)ClientValidationJwtValidationPayloadmethodpathquery_stringall_headerssigned_headersbodyc                   F    e Zd ZddgZ	 ddZ	 	 	 	 	 	 ddZd Zd	 Zd
 ZdS )ValidationClientauthorizationhostTc                 l    || _         || _        || _        || _        |rt	                      nd| _        dS )a+  
        Build a ValidationClient which signs requests with private_key and allows Twilio to
        validate request has not been tampered with.

        :param str account_sid: A Twilio Account Sid starting with 'AC'
        :param str api_key_sid: A Twilio API Key Sid starting with 'SK'
        :param str credential_sid: A Credential Sid starting with 'CR',
                                   corresponds to public key Twilio will use to verify the JWT.
        :param str private_key: The private key used to sign the Client Validation JWT.
        N)account_sidcredential_sidapi_key_sidprivate_keyr   session)selfr   r   r   r   pool_connectionss         Y/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/twilio/http/validation_client.py__init__zValidationClient.__init__   s<    $ ',&&$4>wyyy$    NFc	                 0   | j         pt                      }	t          |                                |||||          }
|	                    |
          }d|j        vr&d|j        vr|                     |          |j        d<   |                     |          }t          | j	        | j
        | j        | j        |          }|                                |j        d<   |	                    |||          }t          t!          |j                  |j                  S )a  
        Make a signed HTTP Request

        :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
        )paramsdataheadersauthHostr   zTwilio-Client-Validation)allow_redirectstimeout)r   r   r   upperprepare_requestr%   	_get_host_build_validation_payloadr
   r   r   r   r   to_jwtsendr	   intstatus_codetext)r   r   urlr#   r$   r%   r&   r)   r(   r   requestprepared_requestvalidation_payloadjwtresponses                  r   r4   zValidationClient.request-   s)   6 ,+'))LLNNCT7QU
 
 
 #227;; *222.666/3~~>N/O/O$V,!;;<LMM!
 
 @Czz|| !;<<<+   
 
 H0118=AAAr!   c                     t          |j                  }|j        }|j        pd}t	          |j        |||j        t          j        |j	        pd          S )z
        Extract relevant information from request to build a ClientValidationJWT
        :param PreparedRequest request: request we will extract information from.
        :return: ValidationPayload
         r   )
r   r3   r   queryr   r   r%   r   !_ValidationClient__SIGNED_HEADERSr   )r   r4   parsedr   r   s        r   r-   z*ValidationClient._build_validation_payloadf   s]     '+&&{|)r >%+<#
 
 
 	
r!   c                 R    t          |j                  }t          |j                  S )z Pull the Host out of the request)r   r3   strnetloc)r   r4   r=   s      r   r,   zValidationClient._get_hosty   s!    '+&&6=!!!r!   c                     |                     dd          }|j        dk     s|j        dk    rt          |j        dd          dS )z
        Validate that a request to the new SSL certificate is successful
        :return: null on success, raise TwilioRestException if the request fails
        GETzhttps://tls-test.twilio.com:443   i,  z"Failed to validate SSL certificateN)r4   r1   r   )r   clientr8   s      r   validate_ssl_certificatez)ValidationClient.validate_ssl_certificate~   sZ    
 >>%)JKK#%%)=)D)D%$14   *E)Dr!   )T)NNNNNF)	__name__
__module____qualname__r<   r    r4   r-   r,   rE    r!   r   r   r      s        '0 ? ? ? ?8 7B 7B 7B 7Br
 
 
&" " "
    r!   r   N)collectionsr   requestsr   r   twilio.base.exceptionsr   urllib.parser   twilio.httpr   twilio.http.responser	   twilio.jwt.validationr
   r   r   rI   r!   r   <module>rQ      s    " " " " " " % % % % % % % % 6 6 6 6 6 6 ! ! ! ! ! ! " " " " " " ) ) ) ) ) ) 5 5 5 5 5 5 JOOO  x x x x xz x x x x xr!   