
    Owg                     x	   d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm Z  d dl!m"Z" d dl#Z#d dl$m%Z% d dl$m&Z& d dl'm(Z( d dl'm)Z) d dl*m+Z, d dl*m-Z. d dl*m/Z0 d d l1m2Z2 	 d d!l3m4Z4 d d"l6m7Z7 d d#l6m8Z8 d d$l9m:Z; d d%l<m=Z= d d&l<m>Z> d d'l<m?Z? d d(l<m@Z@ d d)l<mAZA d d*lBmCZC d d+lBmDZD d d,lEmFZF erd dlGZGd d-lmHZH d d.lImJZK d d/lLmMZM d d0lLmNZN d d1lOmPZQ  G d2 d3eH      ZReeSeTd4e7eUdf   ZVed5ef   ZWeeeeSeSf   eeeSeSf      f      ZXeed5eeYeSf   f      ZZeeeSd6f      Z[ed7eSf   Z\ee%eMeYee]ee]e]f   ee]df   df   eeYeSf   eeUeSeeeUeSf   eeUeSf   f   df   eeeSeSf      geNj                  f   Z_ G d8 d9e      Z`e%j                  Zb ec       Zd ej                  d:      Zf G d; d<      Zgd=eeeSeSf      d>ed5ef   fd?Z/d=eeeSef      d>ed5ef   fd@Z+dAeSd>eYfdBZhdCeSd>eSfdDZidddEdFed5ef   d:dGdHee   dIeeY   d>ed5ef   f
dJZj G dK dLee   e      Zk	 	 	 	 dbdMZldCeSd>eSfdNZmdOeeeUe7eSf      d>ee7e8f   fdPZn G dQ d6      ZodOee7e8f   dReeeSeSf      dSepdTeeS   d>eDf
dUZq G dV d4eo      Z^ G dW dXeo      Zr G dY dZeo      Zs G d[ dG      Zt etd\]      xZ:Zug d^Zveuj                  Zweuj                  Zxeuj                  Zyeuj                  Zzeuj                  Z{euj                  Z}euj                  Z~euj                  Zeuj                   Zeuj                  Zeuj                  Zeuj                  Zeuj                  Zeuj
                  Zeuj                  Zeuj                  Zeuj                  Zeuj                  Zeuj                  Zeuj                  Zeuj                  Zeuj                  Zeuj                  Zeuj                   Zeuj"                  Zeuj$                  Zeuj&                  Zeuj(                  Zeuj*                  Zeuj,                  Zeuj.                  Zeuj2                  Zg d_Zd`eSd>efdaZy# e5$ r
 d d!lm4Z4 Y w xY w)c    N)partialmethod)wraps)client)groupby)Pattern)Lock)TYPE_CHECKINGAny)Callable)Dict)Iterable)Iterator)List)Mapping)
NamedTuple)Optional)Sequence)Sized)Tuple)Type)Union)overload)warn)HTTPAdapter)MaxRetryError)ConnectionError)
RetryError)json_params_matcher)query_string_matcher)urlencoded_params_matcher)FirstMatchRegistry)Literal)BufferedReader)BytesIO)mock)	parse_qsl)quote)urlsplit)
urlunparse)
urlunsplit)HTTPHeaderDict)HTTPResponse)	parse_url)Protocol)_patch)PreparedRequest)models)Retryc            
       <    e Zd Zdededededej                  f
dZy)UnboundSendadapterrequestargskwargsreturnc                      y N )selfr6   r7   r8   r9   s        I/var/www/horilla/myenv/lib/python3.12/site-packages/responses/__init__.py__call__zUnboundSend.__call__D   s         N)	__name__
__module____qualname__r   r1   r   r2   Responser@   r=   rA   r?   r5   r5   C   s;    	 	 %	 		
 	 __	rA   r5   rE   .BaseResponsezPattern[str]c                   "    e Zd ZU ded<   ded<   y)Callr1   r7   _BodyresponseN)rB   rC   rD   __annotations__r=   rA   r?   rH   rH   b   s    rA   rH   	responsesc                       e Zd ZdZdefdZy)	FalseBoolzClass to mock up built-in False boolean.

    Used for backwards compatibility, see
    https://github.com/getsentry/responses/issues/464
    r:   c                      yNFr=   r>   s    r?   __bool__zFalseBool.__bool__t   s    rA   N)rB   rC   rD   __doc__boolrR   r=   rA   r?   rN   rN   m   s    $ rA   rN   paramsr:   c                 8    t        dt               t        |       S )NzVFunction is deprecated. Use 'from responses.matchers import urlencoded_params_matcher')r   DeprecationWarning_urlencoded_params_matcherrU   s    r?   r!   r!   x   s    ` &f--rA   c                 8    t        dt               t        |       S )NzPFunction is deprecated. Use 'from responses.matchers import json_params_matcher')r   rW   _json_params_matcherrY   s    r?   r   r      s    Z  ''rA   sc                 &    t        d | D              S )Nc              3   8   K   | ]  }t        |      d kD    yw)   N)ord).0chars     r?   	<genexpr>z_has_unicode.<locals>.<genexpr>   s     -4s4y3-s   )any)r\   s    r?   _has_unicodere      s    -1---rA   urlc                    t        t        |             }|d   }t        |      rw|j                  d      }t	        |      D ]9  \  }}t        |      sd|j                  d      j                  d      z   }|||<   ; dj                  |      |d<   t        |      } t        |       }t	        |      D ]"  \  }}t        |      dkD  st        |      ||<   $ dj                  |      S )a  Clean up URLs, which use punycode to handle unicode chars.

    Applies percent encoding to URL path and query if required.

    Parameters
    ----------
    url : str
        URL that should be cleaned from unicode

    Returns
    -------
    str
        Cleaned URL

       .zxn--punycodeasciir_    )listr)   re   split	enumerateencodedecodejoinr+   r`   r(   )rf   urllistnetlocdomainsidcharsxs           r?   _clean_unicoderz      s      8C=!GQZFF,,s#g& 	DAqAQXXj188AA
	 XXg&
! IE%   1q6C<QxE!H  775>rA   registryassert_all_requests_are_firedfuncRequestsMockr|   r}   c                $    t         j                  j                  d|      t        j                         r+t               dt        dt        dt        f fd       }|S t               dt        dt        dt        f fd       }|S )aO  Wrap provided function inside ``responses`` context manager.

    Provides a synchronous or asynchronous wrapper for the function.


    Parameters
    ----------
    func : Callable
        Function to wrap.
    responses : RequestsMock
        Mock object that is used as context manager.
    registry : FirstMatchRegistry, optional
        Custom registry that should be applied. See ``responses.registries``
    assert_all_requests_are_fired : bool
        Raise an error if not all registered responses were executed.

    Returns
    -------
    Callable
        Wrapped function

    r}   )target	attributenewr8   r9   r:   c                     K   j                         5  5   | i | d {   cd d d        cd d d        S 7 # 1 sw Y   nxY wd d d        y # 1 sw Y   y xY wwr<   _set_registryr8   r9   assert_mockr~   r|   rL   s     r?   wrapperzget_wrapped.<locals>.wrapper   sg     #''1 3i 3!426223 3 323 3 3 3 3sE   A"AA?A	A
A"AA
	A	A"AA"c                      j                         5  5   | i |cd d d        cd d d        S # 1 sw Y   nxY wd d d        y # 1 sw Y   y xY wr<   r   r   s     r?   r   zget_wrapped.<locals>.wrapper   sZ    #''1 -i - T,V,	- - - - - - -s   A
5	A
>	A

A)std_mockpatchobjectinspectiscoroutinefunctionr   r   )r~   rL   r|   r}   r   r   s   ```  @r?   get_wrappedr      s    : ..''1) ( K ""4(	t	3 	3 	3 	3 
	3( N 
t	-3 	-# 	-# 	- 
	- NrA   c                       e Zd ZddZdee   fdZdefdZe	dedefd       Z
e	dddee   fd	       Z
deeef   deeee   f   fd
Z
ddZdeddfdZddZy)CallListr:   Nc                     g | _         y r<   _callsrQ   s    r?   __init__zCallList.__init__   s	    "$rA   c                 ,    t        | j                        S r<   )iterr   rQ   s    r?   __iter__zCallList.__iter__   s    DKK  rA   c                 ,    t        | j                        S r<   lenr   rQ   s    r?   __len__zCallList.__len__   s    4;;rA   idxc                      y r<   r=   r>   r   s     r?   __getitem__zCallList.__getitem__       rA   zslice[int, int, Optional[int]]c                      y r<   r=   r   s     r?   r   zCallList.__getitem__   r   rA   c                      | j                   |   S r<   r   r   s     r?   r   zCallList.__getitem__   s    {{3rA   c                 N    | j                   j                  t        ||             y r<   )r   appendrH   )r>   r7   rJ   s      r?   addzCallList.add  s    423rA   callc                 :    | j                   j                  |       y r<   )r   r   )r>   r   s     r?   add_callzCallList.add_call  s    4 rA   c                     g | _         y r<   r   rQ   s    r?   resetzCallList.reset  s	    rA   r:   N)r7   r1   rJ   rI   r:   N)rB   rC   rD   r   r   rH   r   intr   r   r   r   r   slicer   r   r   r=   rA   r?   r   r      s    %!(4. !    s t   ? DJ   uS%Z0  U4d;K5L  4!T !d !rA   r   c                 ~    t        | t              r,t        t        |             }|d   dk(  rd|d<   t	        |      } | S )aW  Add empty URL path '/' if doesn't exist.

    Examples
    --------
    >>> _ensure_url_default_path("http://example.com")
    "http://example.com/"

    Parameters
    ----------
    url : str or re.Pattern
        URL to validate.

    Returns
    -------
    url : str or re.Pattern
        Modified URL if str or unchanged re.Pattern

       rl   /)
isinstancestrrm   r)   r+   )rf   	url_partss     r?   _ensure_url_default_pathr     s@    * #s#'	Q<2IaLY'CJrA   c                     t        |       }t        |j                  |j                  |j                  dddg      }t        |      j                  S )a  Construct URL only containing scheme, netloc and path by truncating other parts.

    This method complies with RFC 3986.

    Examples
    --------
    >>> _get_url_and_path("http://example.com/path;segment?ab=xy&zed=qwe#test=1&foo=bar")
    "http://example.com/path;segment"


    Parameters
    ----------
    url : str
        URL to parse.

    Returns
    -------
    url : str
        URL with scheme, netloc and path

    N)r)   r*   schemert   pathr.   rf   )rf   
url_parsedurl_and_paths      r?   _get_url_and_pathr   )  sJ    , #J			J--zdDQL \"&&&rA   bodyc                     t        | t              r| j                  d      } t        | t              r| S t	        |       dt
        ffd}|_        S )zGenerates `Response` body.

    Parameters
    ----------
    body : str or bytes or BufferedReader
        Input data to generate `Response` body.

    Returns
    -------
    body : BufferedReader or BytesIO
        `Response` body

    zutf-8r:   c                       j                   s$ j                  d      r j                  dd       y j                   s j                          yy)a  
        Real Response uses HTTPResponse as body object.
        Thus, when method is_closed is called first to check if there is any more
        content to consume and the file-like object is still opened

        This method ensures stability to work for both:
        https://github.com/getsentry/responses/issues/438
        https://github.com/getsentry/responses/issues/394

        where file should be intentionally be left opened to continue consumption
        rh   FT)closedreadseekclose)datas   r?   	is_closedz_handle_body.<locals>.is_closed]  s?     {{tyy|IIb!;;

 rA   )r   r   rp   r$   r%   rT   isclosed)r   r   r   s     @r?   _handle_bodyr   F  sO      ${{7#$'4=Dt 2 DMKrA   c                   z   e Zd ZU dZeed<   dZee   ed<   dZ	ee
eef      ed<   dZee   ed<   	 	 dddded	d
deeef   dddeddfdZdedefdZdedefdZdeeef   deeef   fdZd	d
dedefdZedddddeeef   fd       ZdefdZdddefdZdddeeef   fdZedefd       Zedefd       Z y)rF   FpassthroughNcontent_typeheadersstream)r   methodrf   _URLPatternTypematch_querystringmatch_MatcherIterabler:   c                   || _         t        |      | _        | j                  |      r5t	        |      t        t        | j                        j                        fz   }|| _        t               | _
        || _        d| _        d| _        y )N   rl   )r   r   rf   _should_match_querystringtuple_query_string_matcherr)   queryr   r   r   r   statusr   )r>   r   rf   r   r   r   s         r?   r   zBaseResponse.__init__  sx     "&>s&C))*;<%L%htxx&8&>&>?$ E */
 (
&	rA   otherc                 R   t        |t              sy| j                  |j                  k7  ryt        | j                  t              r| j                  j
                  n| j                  }t        |j                  t              r|j                  j
                  n|j                  }||k(  S rP   )r   rF   r   rf   r   pattern)r>   r   self_url	other_urls       r?   __eq__zBaseResponse.__eq__  ss    %.;;%,,&
 (2$((G'D488##$(()3EIIw)GEII%%UYY	9$$rA   c                 &    | j                  |       S r<   )r   )r>   r   s     r?   __ne__zBaseResponse.__ne__  s    ;;u%%%rA   match_querystring_argumentc                     t        | j                  t              ry|"t        |t              st	        dt
               |S t        t        | j                        j                        S )NFzArgument 'match_querystring' is deprecated. Use 'responses.matchers.query_param_matcher' or 'responses.matchers.query_string_matcher')	r   rf   r   rN   r   rW   rT   r)   r   )r>   r   s     r?   r   z&BaseResponse._should_match_querystring  s[     dhh(%18)DD ' .-HTXX&,,--rA   c                     t        |t              r-t        |      rt        |      }t	        |      t	        |      k(  S t        |t
              r|j                  |      ryy)a  Compares two URLs.

        Compares only scheme, netloc and path. If 'url' is a re.Pattern, then checks that
        'other' matches the pattern.

        Parameters
        ----------
        url : Union["Pattern[str]", str]
            Reference URL or Pattern to compare.

        other : str
            URl that should be compared.

        Returns
        -------
        bool
            True, if URLs are identical or 'other' matches the pattern.

        TF)r   r   re   rz   r   r   r   )r>   rf   r   s      r?   _url_matcheszBaseResponse._url_matches  sS    ( c3C $S)$S)->u-EEEW%#))E*: rA   r7   r1   c                 8    | D ]  } ||      \  }}|rd|fc S  y)NFTrl   r=   )r   r7   matchervalidreasons        r?   _req_attr_matcheszBaseResponse._req_attr_matches  s3      	%G#G,ME6f}$	%
 rA   c                     t               }| j                  r)| j                  rd| j                  vr| j                  |d<   | j                  r|j                  | j                         |S )NContent-Type)r,   r   r   extend)r>   r   s     r?   get_headerszBaseResponse.get_headers  sU     " dll B&*&7&7GN# <<NN4<<(rA   c                     t         r<   )NotImplementedErrorr>   r7   s     r?   get_responsezBaseResponse.get_response  s    !!rA   c                     |j                   | j                   k7  ry| j                  | j                  t        |j                              sy| j	                  | j
                  |      \  }}|sd|fS y)N)FzMethod does not match)FzURL does not matchFr   )r   r   rf   r   r   r   )r>   r7   r   r   s       r?   matcheszBaseResponse.matches  s_    >>T[[(1  3w{{+;<...tzz7Cv&= rA   c                 ,    t        | j                        S r<   r   rQ   s    r?   
call_countzBaseResponse.call_count
  s    4;;rA   c                     | j                   S r<   r   rQ   s    r?   callszBaseResponse.calls      {{rA   )Nr=   )!rB   rC   rD   r   rT   rK   r   r   r   r   r   r   r   r   r   r   r   r   r   r   staticmethodr   r   r,   r   r-   r   r   propertyr   r   r   r   r=   rA   r?   rF   rF   z  s   K"&L(3-&+/GXgc3h'(/"FHTN" 26$&  "     !v.	 
 "    
 2%C %D %&C &D &.*/f*=.	tV|	.* 1 # $ @ !,=	tSy	 ^ "$5 ", "0 U495E   C     x  rA   r   r   request_methodc           	          t               }|j                          	 t        ||d      }t        |t        j                  j                  |d      | ||d|      S )a9  
    Function to generate `urllib3.response.HTTPResponse` object.

    The cookie handling functionality of the `requests` library relies on the response object
    having an original response object with the headers stored in the `msg` attribute.
    Instead of supplying a file-like object of type `HTTPMessage` for the headers, we provide
    the headers directly. This approach eliminates the need to parse the headers into a file-like
    object and then rely on the library to unparse it back. These additional conversions can
    introduce potential errors.
    F)r   msgpreload_contentN)r   r   r   r   original_responser   r   )r%   r   r-   r   rL   get)r   r   r   r   r   orig_responses         r?   _form_responser    se    " 9DJJL !M
 ##FD1'% rA   c                        e Zd Zdddddedfdedddd	d
ee   dedeeeef      dee	   de
eef   de	deddf fdZdddefdZdefdZ xZS )rE   rl   Nr   Fr   rf   r   r   rI   jsonr   r   r   r   auto_calculate_content_lengthr9   r:   c
                 :   t        |   ||fi |
 |#|rJ t        j                  |      }|t        u rd}|t        u r t        |t              rt        |      rd}nd}|| _        || _	        || _
        |t        dt               || _        || _        |	| _        y )Nzapplication/jsonztext/plain; charset=utf-8
text/plainGstream argument is deprecated. Use stream parameter in request directly)superr   json_moduledumps_UNSETr   r   re   r   r   r   r   rW   r   r   r  )r>   r   rf   r   r  r   r   r   r   r  r9   	__class__s              r?   r   zResponse.__init__?  s     	// O8$$T*Dv%16!$$d);:+!	!4;Y"
 '-!-3P*rA   r7   r1   c                    | j                   r=t        | j                   t              r#t        | j                   d|       | j                   | j	                         }| j
                  }t        | j                   t        t        f      rJ t        | j                         }| j                  r;t        |t              r+d|vr't        |j                               }t        |      |d<   t        ||||j                        S )Nr7   zContent-Length)r   r   	Exceptionsetattrr   r   rE   BaseExceptionr   r  r%   r   getvaluer   r  r   )r>   r7   r   r   r   content_lengths         r?   r   zResponse.get_responsej  s    99DIIy9DIIy'2))O""$dii(M)BCCCDII& ..4) / 1N(+N(;G$%dGVW^^DDrA   c                     dj                  | j                  | j                  | j                  t	        j
                  | j                              S )NzY<Response(url='{url}' status={status} content_type='{content_type}' headers='{headers}')>)rf   r   r   r   )formatrf   r   r   r  r  r   rQ   s    r?   __repr__zResponse.__repr__  sH    BBH&HH{{!..#))$,,7	 CI C	
rA   )rB   rC   rD   r  r   r   r   r   r   rT   r   r   r   r-   r   r  __classcell__r  s   @r?   rE   rE   >  s    
 "/3!%+1.3)Q)Q )Q 	)Q
 sm)Q )Q '#s(+,)Q )Q CK()Q (,)Q )Q 
)QVE$5 E, E*	
# 	
rA   c                   j     e Zd Z	 	 ddedddeegef   dee   dee   ded	df fd
Zddd	e	fdZ
 xZS )CallbackResponseNr   rf   r   callbackr   r   r9   r:   c                 v    t        |   ||fi | || _        |t        dt               || _        || _        y )Nr
  )r  r   r  r   rW   r   r   )r>   r   rf   r  r   r   r9   r  s          r?   r   zCallbackResponse.__init__  sE     	// Y" '-+7rA   r7   r1   c                    | j                         }| j                  |      }t        |t              r||\  }}}t        |t              r|d}t        |t              rd|v rd}nCt        |t
              r3t        |D cg c]  }|s|d   j                         dk(  s|  c}      }|r|j                  dd        t        |      }|j                  |       t        ||||j                        S c c}w )NFr   Tr   content-type)r   r  r   r  dictrm   rd   lowerpopr   r   r  r   )	r>   r7   r   resultr   	r_headersr   has_content_typehs	            r?   r   zCallbackResponse.get_response  s    ""$w'fi(L"(	4dI&J
 !i&>Y+F#	4("%Nqqtzz|~/MN  KK-D!y!dGVW^^DD Os   >C0C0C0)Nr	  )rB   rC   rD   r   r   r   r   rT   r   r-   r   r  r  s   @r?   r  r    s~     "&&288 8 C5#:&	8
 8 sm8 8 
8*E$5 E, ErA   r  c                   (     e Zd Zdedef fdZ xZS )PassthroughResponser8   r9   c                 (    t        |   |ddi| y )Nr   T)r  r   )r>   r8   r9   r  s      r?   r   zPassthroughResponse.__init__  s    $;D;F;rA   )rB   rC   rD   r   r   r  r  s   @r?   r)  r)    s    <c <S < <rA   r)  c                      e Zd ZU dZed   ed<   dZed   ed<   dZed   ed<   dZed   ed<   dZ	ed   ed<   dZ
ed   ed<   dZed   ed<   eZee   ed<   d	d
lmZ dZeeegef      ed<   ddddefeddedeeegef      deedf   dedee   ddddfdZdefdZdee   ddfdZdYdZ	 	 	 	 dZddd d!d"d#d$d%d&ed'edefd(Z eee      Z  eee      Z! eee      Z" eee      Z# eee	      Z$ eee
      Z% eee      Z&	 	 	 	 d[d)Z'd\d*Z(d]d,Z)	 	 d^d-dd d!de*e   fd.Z+	 	 	 d_d-dd d!d"d#d&ed'edefd/Z,	 	 	 d_d-dd d!d"d#d&ed'edefd0Z- e.       d1dfded d+d2ed3ge/e0ee1e2eef   d#f   f   f   d4e/ee.f   d5ee   d6d7ddfd8Z3de*d9   fd:Z4e5de6fd;       Z7d`d<Z8d=ed>ed?edefd@Z9e:dadbdC       Z;e:dddDdee   dededBgdBf   fdE       Z;	 dcddFdDdAedB   deee      dede/edBgdBf   dBf   fdGZ;dHd3deed9   e*e   f   fdIZ<d ede=ee/ee1e>e*ee/ee1e>f         f   f   fdJZ?d"e/ee@eAdf   de/ee@df   fdKZBddLdMdNdHd3dOedP   d'eddQf
dRZCdddSZDdYdTZEdedUeddfdVZFd edWe1defdXZGy)fr   DELETEGETHEADOPTIONSPATCHPOSTPUTrE   r   )matchersNresponse_callbackTr=   z"requests.adapters.HTTPAdapter.send)real_adapter_sendr}   passthru_prefixes.r   r|   r5  _HTTPAdapterSendr:   c                    t               | _        | j                           |       | _        || _        || _        t        |      | _        || _        d | _	        t               | _        || _        y r<   )r   r   r   	_registryr}   r4  r   r6  r   _patcher_ThreadingLock_thread_lock
_real_send)r>   r}   r4  r6  r   r|   r5  s          r?   r   zRequestsMock.__init__  s]     !)


-5Z3P*FW>CDU>V!8<*,+rA   c                     | j                   S )zReturns current registry instance with responses.

        Returns
        -------
        FirstMatchRegistry
            Current registry instance with responses.

        )r9  rQ   s    r?   get_registryzRequestsMock.get_registry  s     ~~rA   new_registryc                 V    | j                         rd}t        |       |       | _        y)zReplaces current registry with `new_registry`.

        Parameters
        ----------
        new_registry : Type[FirstMatchRegistry]
            Class reference of the registry that should be set, eg OrderedRegistry

        z_Cannot replace Registry, current registry has responses.
Run 'responses.registry.reset()' firstN)
registeredAttributeErrorr9  )r>   r@  err_msgs      r?   r   zRequestsMock._set_registry  s.     ??9  !))%rA   c                 d    t               | _        | j                  j                          d| _        y)zMResets registry (including type), calls, passthru_prefixes to default values.r=   N)r"   r9  r   r   r6  rQ   s    r?   r   zRequestsMock.reset  s$    +-!#rA   r   _HTTPMethodOrResponserf   zOptional[_URLPatternType]r   rI   adding_headers
_HeaderSetr8   r9   c                    t        |t              r| j                  j                  |      S ||j	                  d|       d|v r8d|v r4|d   /|d   D cg c]  }|j                          }}d|v rt        d      |J t        |t              sJ t        d|||d|}	| j                  j                  |	      S c c}w )ay  
        >>> import responses

        A basic request:
        >>> responses.add(responses.GET, 'http://example.com')

        You can also directly pass an object which implements the
        ``BaseResponse`` interface:

        >>> responses.add(Response(...))

        A JSON payload:

        >>> responses.add(
        >>>     method='GET',
        >>>     url='http://example.com',
        >>>     json={'foo': 'bar'},
        >>> )

        Custom headers:

        >>> responses.add(
        >>>     method='GET',
        >>>     url='http://example.com',
        >>>     headers={'X-Header': 'foo'},
        >>> )

        r   r   r   zqYou cannot define both `content_type` and `headers[Content-Type]`. Using the `content_type` kwarg is recommended.r   rf   r   r=   )	r   rF   r9  r   
setdefaultr"  RuntimeErrorr   rE   )
r>   r   rf   r   rG  r8   r9   headerheader_keysrJ   s
             r?   r   zRequestsMock.add  s    J fl+>>%%f--%i8f$V#y!-8>y8IJf6<<>JKJ,"F 
 &#&&&H6sHH~~!!(++ Ks   B<c                 r    t        |      5 }t        j                  |      }d d d        |S # 1 sw Y   S xY wr<   )openyaml	safe_load)r>   	file_pathfiler   s       r?   _parse_response_filez!RequestsMock._parse_response_fileO  s5     )_ 	(>>$'D	(	(s   ,6c                     | j                  |      }|d   D ]:  }|d   }| j                  |d   |d   |d   |d   d|v r|d   nd |d   |d	   
       < y )NrL   rJ   r   rf   r   r   r   r   r  )r   rf   r   r   r   r   r  )rU  r   )r>   rS  r   rsps       r?   _add_from_filezRequestsMock._add_from_fileV  s}    ((3$ 
	Cj/CHH8}J[8}*3s*:I 0.12Q.R  
	rA   r   c                 |    t        |t              st        |      rt        |      }| xj                  |fz  c_        y)a  
        Register a URL prefix or regex to passthru any non-matching mock requests to.

        For example, to allow any request to 'https://example.com', but require
        mocks for the remainder, you would add the prefix as so:

        >>> import responses
        >>> responses.add_passthru('https://example.com')

        Regex can be used like:

        >>> import re
        >>> responses.add_passthru(re.compile('https://example.com/\w+'))
        N)r   r   re   rz   r6  )r>   prefixs     r?   add_passthruzRequestsMock.add_passthrue  s2     &'*|F/C#F+F6)+rA   method_or_responsec                     t        |t              r|}n#|J t        |t              sJ t        ||      }| j                  j	                  |      S )as  
        Removes a response previously added using ``add()``, identified
        either by a response object inheriting ``BaseResponse`` or
        ``method`` and ``url``. Removes all matching responses.

        >>> import responses
        >>> responses.add(responses.GET, 'http://example.org')
        >>> responses.remove(responses.GET, 'http://example.org')
        )r   rf   )r   rF   r   r9  remove)r>   r\  rf   rJ   s       r?   r^  zRequestsMock.removex  sQ     (,7)H?"?0#666#+=3GH~~$$X..rA   c                     t        |t              r|}n%|J t        |t              sJ t        d|||d|}| j                  j                  |      S )a  
        Replaces a response previously added using ``add()``. The signature
        is identical to ``add()``. The response is identified using ``method``
        and ``url``, and the first matching response is replaced.

        >>> import responses
        >>> responses.add(responses.GET, 'http://example.org', json={'data': 1})
        >>> responses.replace(responses.GET, 'http://example.org', json={'data': 2})
        rJ  r=   )r   rF   r   rE   r9  replace)r>   r\  rf   r   r8   r9   rJ   s          r?   r`  zRequestsMock.replace  s\    " (,7)H?"?0#666X'9sXQWXH~~%%h//rA   c                     	  | j                   |||g|i |S # t        $ r  | j                  |||g|i |cY S w xY w)a  
        Replaces a response previously added using ``add()``, or adds the response
        if no response exists.  Responses are matched using ``method``and ``url``.
        The first matching response is replaced.

        >>> import responses
        >>> responses.add(responses.GET, 'http://example.org', json={'data': 1})
        >>> responses.upsert(responses.GET, 'http://example.org', json={'data': 2})
        )r`  
ValueErrorr   )r>   r\  rf   r   r8   r9   s         r?   upsertzRequestsMock.upsert  sY    "	L4<< 2COOOO 	L488.TKDKFKK	Ls    !>>r	  r  r1   r   r   r   r   c           
      X    | j                   j                  t        ||||||             y )N)rf   r   r  r   r   r   )r9  r   r  )r>   r   rf   r  r   r   r   s          r?   add_callbackzRequestsMock.add_callback  s0     	!)"3		
rA   rF   c                 .    | j                   j                  S r<   )r9  rB  rQ   s    r?   rB  zRequestsMock.registered  s    ~~(((rA   c                     | j                   S r<   r   rQ   s    r?   r   zRequestsMock.calls  r   rA   c                 &    | j                          | S r<   )startrQ   s    r?   	__enter__zRequestsMock.__enter__  s    

rA   typevalue	tracebackc                 ~    |d u }	 | j                  |       | j                          |S # | j                          w xY w)N)allow_assert)stopr   )r>   rk  rl  rm  successs        r?   __exit__zRequestsMock.__exit__  s9    $,	II7I+JJL JJLs   * <r~   _Fc                      y)z8Overload for scenario when 'responses.activate' is used.Nr=   )r>   r~   s     r?   activatezRequestsMock.activate      rA   r{   c                     y)zOverload for scenario when
        'responses.activate(registry=, assert_all_requests_are_fired=True)' is used.
        See https://github.com/getsentry/responses/pull/469 for more details
        Nr=   )r>   r|   r}   s      r?   ru  zRequestsMock.activate  rv  rA   Fc                Z     |t        |       S dddt        dt        f   f fd}|S )Nfunctionrs  r:   .c                 "    t        |       S )Nr{   )r   )ry  r}   r|   r>   s    r?   deco_activatez,RequestsMock.activate.<locals>.deco_activate  s    !.K	 rA   )r   r   r   )r>   r~   r|   r}   r{  s   ` `` r?   ru  zRequestsMock.activate  s<     tT**	D 	Xc3h-? 	 rA   r7   c                 |    | j                   5  | j                  j                  |      cddd       S # 1 sw Y   yxY w)aU  
        Iterates through all available matches and validates if any of them matches the request

        :param request: (PreparedRequest), request object
        :return:
            (Response) found match. If multiple found, then remove & return the first match.
            (list) list with reasons why other matches don't match
        N)r<  r9  findr   s     r?   _find_matchzRequestsMock._find_match  s4      	0>>&&w/	0 	0 	0s   2;c                     i }t        t        t        |      j                        d       D ]3  \  }}t	        t        d |            }t        |      dk(  r|d   }|||<   5 |S )Nc                     | d   S )Nr   r=   )kvs    r?   <lambda>z4RequestsMock._parse_request_params.<locals>.<lambda>  s
    2a5 rA   c                     | d   S )Nrh   r=   )ry   s    r?   r  z4RequestsMock._parse_request_params.<locals>.<lambda>   s
    ! rA   rh   r   )r   r'   r)   r   rm   mapr   )r>   rf   rU   keyvalvaluess         r?   _parse_request_paramsz"RequestsMock._parse_request_params  sk     @B	(3-*=*= >@PQ 	!HC#nc23F6{a F3K		!
 rA   c                     t        |t              st        |t              s||S t        |d      st        |t              r|j                         S |S )Nr   )r   r   byteshasattrr$   r   )r>   r   s     r?   _read_filelike_bodyz RequestsMock._read_filelike_body&  sF     dC JtU$;t|K 4 Jt^$D99;rA   )retriesr6   r   r  _Retrymodels.Responsec          	      
   | j                  |j                        |_        ||_        t	        |j
                        }| j                  |j                        |_        | j                  |      \  }}| j                  }|<t        | j                  D 	cg c]4  }	t        |	t              r|	j                  |      n|j                  |	      6 c}	      r-t         j#                  dd|i        | j$                  ||fi |S d|j&                   d| d}
t)        | j+                               D ]2  \  }}|
dj-                  |j&                  |j
                  ||         z  }
4 | j                  r|
dz  }
| j                  D ]  }	|
d	|	 d
z  }
 t/        |
      }||_        | j2                  j5                  ||       ||j6                  r.t         j#                  dd|i        | j$                  ||fi |}n"	 |j9                  ||j;                  |            }|r ||      }t?        ||      }| j2                  jA                  |       |jB                  jA                  |       |xs |jD                  }|jG                  |j0                  j&                  |jH                        rS	 |jK                  |j0                  j&                  |j
                  |jL                        } | jN                  ||fd|i|S |S c c}	w # t<        $ rH}t?        ||      }| j2                  jA                  |       |jB                  jA                  |        d }~ww xY w# tP        $ r&}|jR                  r	 tU        ||      |cY d }~S d }~ww xY w)Nzrequest.allowed-passthrurf   )extraz[Connection refused by Responses - the call doesn't match any registered mock.

Request: 
-  z

Available matches:
z- {} {} {}
zPassthru prefixes:
z- 
zrequest.passthrough-response)r   status_code)r   rf   rJ   r  )r7   )+r  path_urlrU   
req_kwargsr   rf   r  r   r~  r4  rd   r6  r   r   r   
startswithloggerinfor=  r   ro   rB  r  r   r7   r   r   r   build_responser   r  rH   r   r   max_retriesis_retryr  	incrementraw_on_requestr   raise_on_statusr   )r>   r6   r7   r  r9   request_urlr   match_failed_reasonsresp_callbackp	error_msgrv   mrJ   r   es                   r?   r  zRequestsMock._on_request6  s}    33G4D4DE#'++&//=&*&6&6w&?##..=
 "33	  "!W- GGK($//23 6uk>RS&twB6BB ^^$Ak] 3''  "$//"34 1^22HHaee%9!%< 	
 %%33	// ,A2aS+I, 'y1H&HKKOOGX.NKK6uk>RKS&twB6BH"11U//8 $X.HGX&T"T"0W00 ##**8L8L  
 !++#++22 %\\ , 
 (t''T'TVTT aR ! GX.$$T*$$T*	2 !  ** %Q88 s>   9K:7!K? &AM ?	MAMM	NM=7N=Nc           
      8     dddddt         dt         ddf
 fd	}|S )
Nr6   r   r7   r1   r8   r9   r:   r  c                     |r)	 |d   |d<   |d   |d<   |d   |d<   |d   |d<   |d	   |d
<    j                  | |fi |S # t         $ r Y w xY w)Nr   r   rh   timeoutr   verify   cert   proxies)
IndexErrorr  )r6   r7   r8   r9   r>   s       r?   sendz*RequestsMock.unbound_on_send.<locals>.send  s     
'+AwF8$(,QF9%'+AwF8$%)!WF6N(,QF9%
 $4##GW???	 " s   (A 	AAr
   )r>   r  s   ` r?   unbound_on_sendzRequestsMock.unbound_on_send  sC    	@"	@&	@ 	@ 		@
 	@. rA   c                     | j                   ry t        j                  | j                  | j	                               | _         | j                   j                          y )N)r   r   )r:  r   r   r   r  ri  rQ   s    r?   ri  zRequestsMock.start  s=    ==  dkkt?S?S?UVrA   ro  c           	      l   | j                   r!| j                   j                          d | _         | j                  sy |sy | j                         D cg c]  }|j                  dk(  s| }}|r>t        dj                  |D cg c]  }|j                  |j                  f c}            y c c}w c c}w )Nr   z(Not all requests have been executed {!r})	r:  rp  r}   rB  r   AssertionErrorr  r   rf   )r>   ro  r  
not_calledr   s        r?   rp  zRequestsMock.stop  s    ==MM  !DM11!%!2HAalla6GaH
H :AA<FG5ellEII.G   I Hs   B,%B,B1countc           	          t        | j                  D cg c]&  }|j                  j                  t	        |      k(  rd( c}      }||k(  ryt        d| d| d| d      c c}w )Nrh   TzExpected URL 'z' to be called z times. Called z times.)r   r   r7   rf   r   r  )r>   rf   r  r   r   s        r?   assert_call_countzRequestsMock.assert_call_count  sx     !JJ<<##'?'DD 

   _UG?:,V]^ s   +A!r   )NNrl   N)rS  #Union[str, bytes, os.PathLike[Any]]r:   zDict[str, Any])rS  r  r:   N)rZ  r   r:   N)NN)NNrl   )r:   r   ).)r~   rs  r:   rs  r<   )r:   r5   )T)HrB   rC   rD   r,  r#   rK   r-  r.  r/  r0  r1  r2  rE   r   rL   r3  r4  r   r   r   r"   r=  rT   r   r   r   r?  r   r   rF   r   r   deleter  headoptionsr   postputrU  rX  r[  r   r^  r`  rc  rN   r   r  r   r   re  rB  r   r   r   rj  rr  r   ru  r~  r   floatr  r  r$   r  r  r  ri  rp  r  r=   rA   r?   r   r     s    (FGH(C"D'&/""+GWY+%E77%"D'&/"C'Hd8n' #8<x# 45< /3<@-/:-?, 1;,'+, $HcUCZ$89, !c?	,
 , )*, ., 
,*	0 	($/A*B (t ($$ +/+/'+9,'9, )9, 	9,
 %9, 9, 9, 
9,v 3'F
S
!Cd#DC)G#u%Ed#D
S
!C>	,* 7;+//3/ )/ 
l		/2 7;+/	030 )0 	0
 0 0 
08 7;+/	L3L )L 	L
 L L 
L< 5>K&2$&

 
 )U3S(97#BCCDF
	
 !y1
 sm
 "
 

.)D0 ) x  S     G G  ".1		 s)	 (,		
 
4&$,		 	  $ )-.3tn 49%	
 (, 
x%t+	,(0(0	x'c2	30			c5c5$xc3o8N/O*PPQQ	R	#und:;	sE4	 * '+dd #d
 (#d d 
dL4  .S   rA   F)r}   )#r  rE   r   ru  r   rX  re  r[  )_deprecated_assert_all_requests_are_firedr  r   r  r,  r  r-  r  r.  r  r/  _deprecated_passthru_prefixesr   r0  r  r1  r  r2  rB  r^  r`  r   r4  ri  rp  _deprecated_targetrc  )r}   r6  r   namec                     | t         v r%t        |  d|  t               t               d|     S t	        dt
         d|        )Nz+ is deprecated. Please use 'responses.mock._deprecated_zmodule z has no attribute )deprecated_namesr   rW   globalsrC  rB   )r  s    r?   __getattr__r  6  sT    f?vF	
 y<v.//
78*,>tfE
FFrA   )rf   r   r:   r   )r   r  r  logging	functoolsr   r   httpr   	itertoolsr   rer   	threadingr   r;  typingr	   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   warningsr   rQ  requests.adaptersr   r   requests.exceptionsr   r   responses.matchersr   r[   r    r   r!   rX   responses.registriesr"   typing_extensionsr#   ImportErrorior$   r%   unittestr&   r   urllib.parser'   r(   r)   r*   r+   urllib3.responser,   r-   urllib3.util.urlr.   osr/   unittest.mockr0   _mock_patcherrequestsr1   r2   urllib3r3   r  r5   r   r  r  rI   rs  rH  rT   r   rF  r   r  rE   r7  rH   r  r=  r   r  	getLoggerr  rN   re   rz   r   r   r   r   r   rF   r   r  r  r)  r   _default_mock__all__ru  r   rX  re  r[  r}   r  r  r   r  r,  r  r-  r  r.  r  r/  r6  r  r   r0  r  r1  r  r2  rB  r^  r`  r   r4  ri  rp  r   r  rc  r  r  r=   rA   r?   <module>r     s      #     ,                    ) + / * J L V 3)   % "  ! # # + ) &5('h  #}j.%MNE	#s(	B%S 14c3h3H HIJJeD#I.>)> ?@$U3+>%?@NC/0O%ue|,eE4K.@$FG$)%eE%*$5uUCZ7H$HI4OPWS#X&'	
 			: 
 
				;	' .htCH~&> .8CQTHCU .(c3h 8 (Xc3h=O (.C .D .! ! !P #48:
38
:: sm	:
 $,D>: c3h:zx}e >	:'3 '3 ':1
534
51
>7"#1hV Vr(
'
((gc3h'(( ( SM	(
 (VJ
| J
Z1E| 1Eh<, <
` `H $%H H}%P !!--)))),9,W,W )!33 						





 - ? ? %%
			


!33 ")) 			 T Gc Gc G[(  s   R* *R98R9