
    g                     \    S SK r S SKrS SKJrJr  S SKJrJr  S rS r	S r
 " S S\5      rg)	    N)sha1sha256)urlparseparse_qsc                 r    [        U 5      [        U5      :w  a  gSn[        X5       H  u  p4X#U:H  -  nM     U$ )zCompare two strings while protecting against timing attacks

:param str string1: the first string
:param str string2: the second string

:returns: True if the strings are equal, False if not
:rtype: :obj:`bool`
FT)lenzip)string1string2resultc1c2s        `/Users/Alptekin/Desktop/izin_takip/venv/lib/python3.13/site-packages/twilio/request_validator.pycomparer      s@     7|s7|#Fg'( ( M    c                     U R                   (       d  U R                  5       $ U R                  R                  S5      S   nU R	                  US9nUR                  5       $ )zRemove the port number from a URI

:param uri: parsed URI that Twilio requested on your server

:returns: full URI without a port number
:rtype: str
:r   netloc)portgeturlr   split_replace)uri
new_netlocnew_uris      r   remove_portr      sM     88zz|!!#&q)Jll*l-G>>r   c                     U R                   (       a  U R                  5       $ U R                  S:X  a  SOSnU R                  S-   [	        U5      -   nU R                  US9nUR                  5       $ )zAdd the port number to a URI

:param uri: parsed URI that Twilio requested on your server

:returns: full URI with a port number
:rtype: str
httpsi  P   r   r   )r   r   schemer   strr   )r   r   r   r   s       r   add_portr#   +   s]     xxzz|**'3RDc!CI-Jll*l-G>>r   c                   2    \ rS rSrS rS rS rS rS rSr	g)	RequestValidator=   c                 0    UR                  S5      U l        g Nutf-8)encodetoken)selfr+   s     r   __init__RequestValidator.__init__>   s    \\'*
r   c                    UnU(       aN  [        [        U5      5       H6  nU R                  X$5      n[        [        U5      5       H
  nX4U-   -  nM     M8     [        R                  " U R
                  UR                  S5      [        5      n[        R                  " UR                  5       5      nUR                  S5      nUR                  5       $ )zCompute the signature for a given request

:param uri: full URI that Twilio requested on your server
:param params: post vars that Twilio sent with the request

:returns: The computed signature
r)   )sortedset
get_valueshmacnewr+   r*   r   base64	b64encodedigestdecodestrip)	r,   r   paramss
param_namevaluesvaluemaccomputeds	            r   compute_signature"RequestValidator.compute_signatureA   s     $S[1
<#CK0Ee++A 1 2 hhtzz188G#4d;##CJJL1??7+~~r   c                      UR                  U5      $ ! [         a,     UR                  U5      s $ ! [         a
    X   /s s $ f = ff = f)N)getallAttributeErrorgetlist)r,   
param_dictr<   s      r   r2   RequestValidator.get_valuesX   sX    		0$$Z00 	00!))*55! 0".//0		0s)    
A	1A	A A	AA	c                 r    [        UR                  S5      5      R                  5       nUR                  5       $ r(   )r   r*   	hexdigestr9   )r,   bodyr@   s      r   compute_hashRequestValidator.compute_hashd   s+    $++g./99;~~r   c                    Uc  0 n[        U5      n[        U5      n[        U5      nSn[        UR                  5      nSU;   a8  [        U[        5      (       a#  [        U R                  U5      US   S   5      n0 n[        U R                  Xb5      U5      n	[        U R                  XR5      U5      n
U=(       a    U	=(       d    U
$ )a5  Validate a request from Twilio

:param uri: full URI that Twilio requested on your server
:param params: dictionary of POST variables or string of POST body for JSON requests
:param signature: expected signature in HTTP X-Twilio-Signature header

:returns: True if the request passes validation, False if not
T
bodySHA256r   )
r   r#   r   r   query
isinstancer"   r   rL   rA   )r,   r   r:   	signature
parsed_uriuri_with_porturi_without_portvalid_body_hashrP   valid_signaturevalid_signature_with_ports              r   validateRequestValidator.validatei   s     >Fc]
 ,&z2))*5 Z%<%<%d&7&7&?|ATUVAWXOF """#3<i
 %,""=99%
! QO$P7PQr   )r+   N)
__name__
__module____qualname____firstlineno__r-   rA   r2   rL   rY   __static_attributes__ r   r   r%   r%   =   s    + .
0 
 Rr   r%   )r5   r3   hashlibr   r   urllib.parser   r   r   r   r#   objectr%   r`   r   r   <module>rd      s0        +$"$LRv LRr   