
    Owg-                         d dl Z d dlmZ d dlmZ d dlmZ d dlmZ erd dlmZ d dlm	Z	  G d d	      Z
 G d
 de
      Zy)    N)TYPE_CHECKING)List)Optional)Tuple)PreparedRequest)BaseResponsec                       e Zd ZddZeded   fd       ZddZdddee	d   ee
   f   fd	ZddZd
dded   fdZddZy)FirstMatchRegistryreturnNc                     g | _         y N
_responsesselfs    K/var/www/horilla/myenv/lib/python3.12/site-packages/responses/registries.py__init__zFirstMatchRegistry.__init__   s	    02    r   c                     | j                   S r   r   r   s    r   
registeredzFirstMatchRegistry.registered   s    r   c                     g | _         y r   r   r   s    r   resetzFirstMatchRegistry.reset   s	    r   requestr   c                 f   d }d }g }t        | j                        D ]  \  }}|j                  |      \  }}|rd||}|}#| j                  |   j                  dkD  r"| j                  j	                  |       |} ||fS | j                  j	                  |      |fc S |j                  |        ||fS )Nr   )	enumerater   matches
call_countpopappend)	r   r   foundfound_matchmatch_failed_reasonsiresponsematch_resultreasons	            r   findzFirstMatchRegistry.find   s     !$T__5 	4KAx#+#3#3G#< L&=E"*Ku-881<++E2&.
 000  ??..u57KKK$++F3	4  000r   r$   c                     t        fd| j                  D              rt        j                        | j                  j	                         S )Nc              3   &   K   | ]  }|u  
 y wr    ).0respr$   s     r   	<genexpr>z)FirstMatchRegistry.add.<locals>.<genexpr>2   s     <Dx4<s   )anyr   copydeepcopyr   )r   r$   s    `r   addzFirstMatchRegistry.add1   s<    <DOO<< }}X.Hx(r   c                     g }|| j                   v r;| j                   j                  |       |j                  |       || j                   v r;|S r   )r   remover   )r   r$   removed_responsess      r   r3   zFirstMatchRegistry.remove;   sJ    $//)OO""8,$$X. $//) ! r   c                     	 | j                   j                  |      }|| j                   |<   |S # t        $ r t        d|j                         w xY w)Nz#Response is not registered for URL )r   index
ValueErrorurl)r   r$   r6   s      r   replacezFirstMatchRegistry.replaceB   s[    	SOO))(3E "*  	SB8<<.QRR	Ss	   . "A)r   N)r$   r   r   r   )__name__
__module____qualname__r   propertyr   r   r   r   r   strr'   r1   r3   r9   r*   r   r   r
   r
      sv    3 D0  1(1	x'c2	310!~ !$~2F !r   r
   c                   6    e Zd ZdZdddeed   ee   f   fdZy)OrderedRegistrya  Registry where `Response` objects are dependent on the insertion order and invocation index.

    OrderedRegistry applies the rule of first in - first out. Responses should be invoked in
    the same order in which they were added to the registry. Otherwise, an error is returned.
    r   r   r   r   c                     | j                   sddgfS | j                   j                  d      }|j                  |      \  }}|s,| j                          | j	                  |       d| d}d|gfS |g fS )aR  Find the next registered `Response` and check if it matches the request.

        Search is performed by taking the first element of the registered responses list
        and removing this object (popping from the list).

        Parameters
        ----------
        request : PreparedRequest
            Request that was caught by the custom adapter.

        Returns
        -------
        Tuple[Optional["BaseResponse"], List[str]]
            Matched `Response` object and empty list in case of match.
            Otherwise, None and a list with reasons for not finding a match.

        NzNo more registered responsesr   zHNext 'Response' in the order doesn't match due to the following reason: .)r   r   r   r   r1   )r   r   r$   r%   r&   s        r   r'   zOrderedRegistry.findR   s    * 8999??&&q)'//8fJJLHHX006xq:  &>!|r   N)	r:   r;   r<   __doc__r   r   r   r>   r'   r*   r   r   r@   r@   K   s/    #(#	x'c2	3#r   r@   )r/   typingr   r   r   r   requestsr   	responsesr   r
   r@   r*   r   r   <module>rG      s5         (&: :z*( *r   