
    nbi!              
      Z   d Z ddlmZ ddlZddlZddlmZ ddlmZm	Z	m
Z
mZmZ ej        rddlmZmZ g dZddZddZddZ G d dej        eej        ej        ee	f                  f         ej        e                   Z G d dee                   Z G d dee                   ZdS ) a  
requests.hooks
~~~~~~~~~~~~~~

This module provides the capabilities for the Requests hooks system.

Available hooks:

``pre_request``:
    The prepared request just got built. You may alter it prior to be sent through HTTP.
``pre_send``:
    The prepared request got his ConnectionInfo injected.
    This event is triggered just after picking a live connection from the pool.
``on_upload``:
    Permit to monitor the upload progress of passed body.
    This event is triggered each time a block of data is transmitted to the remote peer.
    Use this hook carefully as it may impact the overall performance.
``response``:
    The response generated from a Request.
    )annotationsN)MutableMapping   )_HVAsyncHookCallableTypeAsyncHookTypeHookCallableTypeHookType)PreparedRequestResponsepre_requestpre_send	on_uploadearly_responseresponsereturnHookType[_HV]c                 $    d t           D             S )Nc                    i | ]}|g S  r   ).0events     ^/var/www/html/mdtn/previsions/meteo_cartes/venv/lib/python3.11/site-packages/niquests/hooks.py
<dictcomp>z!default_hooks.<locals>.<dictcomp>1   s    )))%E2)))    )HOOKSr   r   r   default_hooksr   0   s    ))5))))r   keystrhooksHookType[_HV] | None	hook_datar   kwargs
typing.Anyc                    ||S |                     |           }|rAt          |          r|g}|D ],}	  ||fi |}n# t          $ r  ||          }Y nw xY w||}-|S )z6Dispatches a hook dictionary on a given piece of data.)getcallable	TypeErrorr   r!   r#   r$   	callableshook
_hook_datas          r   dispatch_hookr.   4   s    }49IIcNNI 	'I 	$"I 	' 	'D-!T)66v66

 - - -!T)__


-%&	s   	=AAAsyncHookType[_HV] | Nonec                N  K   ||S |                     |           }|rt          |          r|g}|D ]r}t          j        |          r2	  ||fi | d{V }nG# t          $ r  ||           d{V }Y n*w xY w	  ||fi |}n# t          $ r  ||          }Y nw xY w||}s|S )zEDispatches a hook dictionary on a given piece of data asynchronously.N)r'   r(   asyncioiscoroutinefunctionr)   r*   s          r   async_dispatch_hookr3   I   s2     }QVQZQZ[^Q_Q_I 'I 	$"I 	' 	'D*400 	17'+tI'@'@'@'@!@!@!@!@!@!@JJ  7 7 7'+tI!6!6!6!6!6!6JJJ71!%i!:!:6!:!:JJ  1 1 1!%iJJJ1 %&	s$   	AA76A7;	BBBc                  N    e Zd ZddZddZdd
ZddZddZd Zd Z	d Z
d ZdS )_BaseLifeCycleHookr   Nonec                     g g g g g d| _         d S Nr   _storeselfs    r   __init__z_BaseLifeCycleHook.__init__h   s%     f
 f
r   r   str | bytesvalue8list[HookCallableType[_HV] | AsyncHookCallableType[_HV]]c                     t          d          NzLifeCycleHook is Read OnlyNotImplementedError)r<   r   r?   s      r   __setitem__z_BaseLifeCycleHook.__setitem__q       !">???r   r    c                    | j         |         S Nr9   r<   r   s     r   __getitem__z_BaseLifeCycleHook.__getitem__t   s    {3r   c                    | |         S rH   r   rI   s     r   r'   z_BaseLifeCycleHook.getw   s    Cyr   c                    t          |t                    st          i }t                      }| j                                        D ]%\  }}|||<   ||xx         |j        |         z  cc<   &||_        |S rH   )
isinstancer5   r)   r:   items)r<   other	tmp_storecombined_hookshfnss         r   __add__z_BaseLifeCycleHook.__add__z   s    %!344 	O	2D2F2Fk'')) 	, 	,FAsIaLaLLLELO+LLLL )r   c              #  $   K   | j         E d {V  d S rH   r9   r;   s    r   __iter__z_BaseLifeCycleHook.__iter__   s&      ;r   c              #  ,   K   | D ]}|| |         fV  d S rH   r   rI   s     r   rN   z_BaseLifeCycleHook.items   s6       	! 	!CtCy.    	! 	!r   c                     t          d          rB   rC   rI   s     r   __delitem__z_BaseLifeCycleHook.__delitem__   rF   r   c                *    t          | j                  S rH   )lenr:   r;   s    r   __len__z_BaseLifeCycleHook.__len__   s    4;r   Nr   r6   )r   r>   r?   r@   r   r6   )r   r    r   r@   )r   r5   )__name__
__module____qualname__r=   rE   rJ   r'   rT   rV   rN   rY   r\   r   r   r   r5   r5   e   s        
 
 
 
@ @ @ @               ! ! !@ @ @         r   r5   c                  L     e Zd ZdZd fdZdd
ZddZddZddZddZ	 xZ
S )LifeCycleHookzP
    A sync-only middleware to be used in your request/response lifecycles.
    r   r6   c                    t                                                       | j                            | j        g| j        g| j        g| j        g| j        gd           d S r8   	superr=   r:   updater   r   r   r   r   r<   	__class__s    r   r=   zLifeCycleHook.__init__   o     $ 01!]O"n-#'#6"7!]O 	
 	
 	
 	
 	
r   prepared_requestr   r$   r%   PreparedRequest | Nonec                    dS zTThe prepared request just got built. You may alter it prior to be sent through HTTP.Nr   r<   rj   r$   s      r   r   zLifeCycleHook.pre_request       tr   c                    dS zThe prepared request got his ConnectionInfo injected. This event is triggered just
        after picking a live connection from the pool. You may not alter the prepared request.Nr   rn   s      r   r   zLifeCycleHook.pre_send   	     tr   c                    dS a  Permit to monitor the upload progress of passed body. This event is triggered each time
        a block of data is transmitted to the remote peer. Use this hook carefully as
        it may impact the overall performance. You may not alter the prepared request.Nr   rn   s      r   r   zLifeCycleHook.on_upload   s	     tr   r   r   c                    dS zAn early response caught before receiving the final Response for a given Request.
        Like but not limited to 103 Early Hints.Nr   r<   r   r$   s      r   r   zLifeCycleHook.early_response   rr   r   Response | Nonec                    dS zJThe response generated from a Request. You may alter the response at will.Nr   rw   s      r   r   zLifeCycleHook.response   ro   r   r]   rj   r   r$   r%   r   rk   rj   r   r$   r%   r   r6   r   r   r$   r%   r   r6   r   r   r$   r%   r   rx   r^   r_   r`   __doc__r=   r   r   r   r   r   __classcell__rh   s   @r   rb   rb               

 

 

 

 

 

      
      
       r   rb   c                  L     e Zd ZdZd fdZdd
ZddZddZddZddZ	 xZ
S )AsyncLifeCycleHookzR
    An async-only middleware to be used in your request/response lifecycles.
    r   r6   c                    t                                                       | j                            | j        g| j        g| j        g| j        g| j        gd           d S r8   rd   rg   s    r   r=   zAsyncLifeCycleHook.__init__   ri   r   rj   r   r$   r%   rk   c                
   K   dS rm   r   rn   s      r   r   zAsyncLifeCycleHook.pre_request         tr   c                
   K   dS rq   r   rn   s      r   r   zAsyncLifeCycleHook.pre_send          tr   c                
   K   dS rt   r   rn   s      r   r   zAsyncLifeCycleHook.on_upload   s       tr   r   r   c                
   K   dS rv   r   rw   s      r   r   z!AsyncLifeCycleHook.early_response   r   r   rx   c                
   K   dS rz   r   rw   s      r   r   zAsyncLifeCycleHook.response   r   r   r]   r{   r|   r}   r~   r   r   s   @r   r   r      r   r   r   )r   r   )
r   r    r!   r"   r#   r   r$   r%   r   r   )
r   r    r!   r/   r#   r   r$   r%   r   r   )r   
__future__r   r1   typingcollections.abcr   _typingr   r   r   r	   r
   TYPE_CHECKINGmodelsr   r   r   r   r.   r3   r    ListUnionGenericr5   rb   r   r   r   r   <module>r      s   * # " " " " "   * * * * * *              
 211111111	 	 	* * * *   *   8/  /  /  /  / 
#v{6<8HJ_8_+`aabdjdrsvdw/  /  / d' ' ' ' '&s+ ' ' 'T' ' ' ' '+C0 ' ' ' ' 'r   