
    hz                     V    d Z ddlZddlmZmZ ddlmZ  G d dej                        Z	y)z*The module containing HTTPProxyDigestAuth.    N)cookiesutils   )_digest_auth_compatc                        e Zd ZdZ ej
                  dej                        Z fdZe	d        Z
e
j                  d        Z
 fdZd Zd	 Z xZS )
HTTPProxyDigestAuthaO  HTTP digest authentication between proxy

    :param stale_rejects: The number of rejects indicate that:
        the client may wish to simply retry the request
        with a new encrypted response, without reprompting the user for a
        new username and password. i.e., retry build_digest_header
    :type stale_rejects: int
    zdigest )flagsc                 Z    t        t        | 
  |i | d| _        | j	                          y )Nr   )superr   __init__stale_rejectsinit_per_thread_state)selfargskwargs	__class__s      f/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/requests_toolbelt/auth/http_proxy_digest.pyr   zHTTPProxyDigestAuth.__init__   s,    !414B6B""$    c                 P    t        | dd       }|| j                  S |j                  S N_thread_localgetattr_stale_rejectsr   )r   thread_locals     r   r   z!HTTPProxyDigestAuth.stale_rejects   s.    t_d;&&&)))r   c                 @    t        | dd       }||| _        y ||_        y r   r   )r   valuer   s      r   r   z!HTTPProxyDigestAuth.stale_rejects"   s&    t_d;"'D).L&r   c                 J    	 t         t        |           y # t        $ r Y y w xY w)N)r   r   r   AttributeError)r   r   s    r   r   z)HTTPProxyDigestAuth.init_per_thread_state*   s(    	%tBD 		s    	""c                 >   |j                   dk(  r| j                  dk  r|j                  j                  d      }|t	        d      | j
                  j                  |      s|S t        j                  | j
                  j                  d|d            | _
        d|j                  j                  v rod	| j                  v ra| j                  d	   j                         d
k(  r| xj                  dz  c_        n+| j                  d	   j                         dk(  rt	        d      |j                   |j                          |j                  j                         }t!        j"                  |j$                  |j                  |j&                         |j)                  |j$                         | j+                  |j,                  |j.                        |j                  d<    |j0                  j2                  |fi |}|j4                  j7                  |       ||_        |S |S )zHandle HTTP 407 only once, otherwise give up

        :param r: current response
        :returns: responses, along with the new response
        i     zproxy-authenticatezRproxy server violated RFC 7235:407 response MUST contain header proxy-authenticate r   )countProxy-AuthorizationstaletruefalsezUser or password is invalid)status_coder   headersgetIOError_patmatchr   parse_dict_headersubchalrequestlowercontentclosecopyr   extract_cookies_to_jar_cookiesrawprepare_cookiesbuild_digest_headermethodurl
connectionsendhistoryappend)r   rr   s_authprep_rs         r   
handle_407zHTTPProxyDigestAuth.handle_4071   s    ==CD$6$6$:YY]]#78F~JK K YY__V,//		b&24DI
 &):)::tyy(99W%++-7&&!+&YYw'--/7:!"?@@ IIGGI99>>#D**4==!))QUUK  /262J2JTXX3'DLL./"""4262BJJa BJIHr   c                     | j                          | j                  r3| j                  |j                  |j                        |j
                  d<   |j                  d| j                         |S )Nr$   response)r   
last_noncer:   r;   r<   r)   register_hookrE   )r   rA   s     r   __call__zHTTPProxyDigestAuth.__call___   sU    ""$??/3/G/G!%%0AII+, 	

DOO4r   )__name__
__module____qualname____doc__recompile
IGNORECASEr,   r   propertyr   setterr   rE   rJ   __classcell__)r   s   @r   r   r   
   sc     2::j6D% * * / /,\r   r   )
rN   rO   requestsr   r   r"   r   authHTTPDigestAuthr    r   r   <module>rY      s%    0 	 # )]$-- ]r   