
    |hP                     p    d Z ddlmZ ddlmZ ddlmZmZ  G d dej                        Z	 G d d	e	      Z
y
)z-The module containing the code for GuessAuth.    )auth)cookies   )_digest_auth_compathttp_proxy_digestc                   .    e Zd ZdZd Zd Zd Zd Zd Zy)	GuessAuthz7Guesses the auth type by the WWW-Authentication header.c                 <    || _         || _        d | _        d | _        y N)usernamepasswordr   pos)selfr   r   s      [/var/www/html/test/engine/venv/lib/python3.12/site-packages/requests_toolbelt/auth/guess.py__init__zGuessAuth.__init__   s      	    c                    | j                   /|j                  j                  j                  | j                          |j                   |j
                  j                          |j                  j                         }t        |d      st        j                         |_        t        j                  |j                  |j                  |j
                         |j                  |j                         t        j                  | j                   | j"                        | _        | j                  |      } |j$                  j&                  |fi |}|j(                  j+                  |       ||_        |S N_cookies)r   requestbodyseekcontentrawrelease_conncopyhasattrr   RequestsCookieJarr   extract_cookies_to_jarprepare_cookiesr   HTTPBasicAuthr   r   
connectionsendhistoryappendr   rkwargsprep_rs        r   _handle_basic_auth_401z GuessAuth._handle_basic_auth_401   s    88IINN) 	
			yy~~tZ(#557DM&&t}}aiiGT]]+&&t}}dmmD	yyQ\\t.v.


!
	r   c                 h   t        j                  | j                  | j                        | _        	 | j                  j                          t        | j                  d      r'| j                  j                  d| j                  _         | j                  j                  |fi |S # t        $ r Y ew xY w)Nnum_401_callsr   )
auth_compatHTTPDigestAuthr   r   r   init_per_thread_stateAttributeErrorr   r-   
handle_401r   r'   r(   s      r   _handle_digest_auth_401z!GuessAuth._handle_digest_auth_401'   s    ..t}}dmmL		II++- DII/		''/&'DII# $tyy##A000  	 	s   B% %	B10B1c                     |j                   j                  dd      j                         }d|v r| j                  ||      S d|v r| j	                  ||      S y)z/Resends a request with auth headers, if needed.zwww-authenticate basicdigestN)headersgetlowerr+   r4   )r   r'   r(   www_authenticates       r   r2   zGuessAuth.handle_401:   s`     99==);R@FFH&&..q&99''//6:: (r   c                     | j                   | j                  |      S 	 |j                  j                         | _        |j                  d| j                         |S # t        $ r Y )w xY wNresponse)r   r   tellr   r1   register_hookr2   )r   r   s     r   __call__zGuessAuth.__call__E   sc    99 99W%%	||((*DH 	j$//:	  		s   A 	A('A(N)	__name__
__module____qualname____doc__r   r+   r4   r2   rB    r   r   r	   r	   	   s    A,1&	;
r   r	   c                   D     e Zd ZdZ	 	 d fd	Zd Zd Zd Z fdZ xZ	S )GuessProxyAuthzZ
    Guesses the auth type by WWW-Authentication and Proxy-Authentication
    headers
    c                 X    t         t        |   ||       || _        || _        d | _        y r   )superrI   r   proxy_usernameproxy_password
proxy_auth)r   r   r   rL   rM   	__class__s        r   r   zGuessProxyAuth.__init__W   s+    nd,Xx@,,r   c                    | j                   /|j                  j                  j                  | j                          |j                   |j
                  j                          |j                  j                         }t        |d      st        j                         |_        t        j                  |j                  |j                  |j
                         |j                  |j                         t        j                  | j                   | j"                        | _        | j%                  |      } |j&                  j(                  |fi |}|j*                  j-                  |       ||_        |S r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r    r   HTTPProxyAuthrL   rM   rN   r"   r#   r$   r%   r&   s        r   _handle_basic_auth_407z%GuessProxyAuth._handle_basic_auth_407^   s   88IINN)				yy~~tZ(#557DM&&t}}aiiGT]]+,,T-@-@-1-@-@Bt$Q\\t.v.


!
	r   c                     t        j                  | j                  | j                        | _        	 | j
                  j                           | j                  j                  |fi |S # t        $ r Y (w xY w)N)r   r   )	r   HTTPProxyDigestAuthrL   rM   rN   r   r0   r1   
handle_407r3   s      r   _handle_digest_auth_407z&GuessProxyAuth._handle_digest_auth_407s   sm    +??((((*	II++- *t))!6v66  		s   A) )	A54A5c                     |j                   j                  dd      j                         }d|v r| j                  ||      S d|v r| j	                  ||      S y )NzProxy-Authenticater6   r7   r8   )r9   r:   r;   rR   rV   )r   r'   r(   proxy_authenticates       r   rU   zGuessProxyAuth.handle_407   s^    YY]]+?DJJL((..q&99))//6:: *r   c                     | j                   | j                  |      }	 |j                  j                         | _        |j                  d| j                         t        t        | '  |      S # t        $ r Y :w xY wr>   )
rN   r   r@   r   r1   rA   rU   rK   rI   rB   )r   r   rO   s     r   rB   zGuessProxyAuth.__call__   sp    ??&oog.G	||((*DH 	j$//:^T3G<<	  		s   A. .	A:9A:)NNNN)
rC   rD   rE   rF   r   rR   rV   rU   rB   __classcell__)rO   s   @r   rI   rI   R   s.     0459*
7;
= 
=r   rI   N)rF   requestsr   r   r6   r   r.   r   AuthBaser	   rI   rG   r   r   <module>r]      s2    3   CF FR@=Y @=r   