
    Owg                     x   d dl mZ d dlmZ er^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Zd dlmZ d dlmZ d dlmZ d dlmZ ddZddZ	 	 	 	 	 	 	 	 ddZ G d de      Z e       Z e jB                  Z!y)    wraps)TYPE_CHECKINGN)Any)BinaryIO)Callable)Dict)List)Optional)Type)Union)FirstMatchRegistry)HTTPAdapter)PreparedRequest)models)_F)BaseResponse)TextIOWrapper)RequestsMock)Response)
_real_send)OrderedRegistryc                     t        | t              r0| j                         D ci c]  \  }}|	|t        |       c}}S t        | t              r| D cg c]  }t        |       c}S | S c c}}w c c}w N)
isinstancedictitems_remove_noneslist)dkvis       J/var/www/horilla/myenv/lib/python3.12/site-packages/responses/_recorder.pyr   r       sc    !T01	K1Q]=##KK!T*+,Qa ,,H L,s   
A,A,A2c                     t        | t              rPg d}t        | d         D ];  \  }}|D ]  }||d   d   v s| d   |   d   d   |=  |d   d   r0| d   |   d   d= = | S )zo
    It would be too verbose to store these headers in the file generated by the
    record functionality.
    )zContent-LengthzContent-TypeDateServer
ConnectionzContent-Encoding	responsesresponseheaders)r   r   	enumerate)datakeys_to_remover#   r*   keys        r$   _remove_default_headersr0   (   s    
 $
 %T+%67 	@KAx% I(:.y99[)!,Z8CCHI J'	2%a(4Y?	@ K    c                 X   dg i}| D ]i  }	 |j                   }|d   j                  d|j                  |j                  |j                  |j
                  |j                  |j                  |di       k  |t        t        |            |       y # t        $ r}t        d      |d }~ww xY w)Nr)   r*   )methodurlbodystatusr+   content_typeauto_calculate_content_lengthzgCannot dump response object.Probably you use custom Response object that is missing required attributes)r8   appendr3   r4   r5   r6   r+   r7   AttributeErrorr0   r   )
registereddestinationdumperr-   rspcontent_lengthexcs          r$   _dumprA   ?   s    
 (,D 	 >>N$$"%**"ww #"%**#&;;(+(8(89G!
, "=#67E  	 ^ 	s   A&B	B)B$$B)c                        e Zd Zdeddeddddf fdZdd	Zd
d	 	 	 ddZdd	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 ddZ	dde
ddf fdZ xZS )Recorderz"requests.adapters.HTTPAdapter.sendtargetregistryrE   rF   zType[FirstMatchRegistry]returnNc                (    t         |   ||       y )NrD   )super__init__)selfrE   rF   	__class__s      r$   rJ   zRecorder.__init___   s     	:r1   c                 "    t               | _        y r   )r   	_registry)rK   s    r$   resetzRecorder.resetg   s    (*r1   zresponse.yaml)	file_pathc                     d fd}|S )Nc                 6     t               d fd       }|S )Nc                      5   | i |}j                  j                         j                         |cd d d        S # 1 sw Y   y xY w)N)rP   r;   )dump_to_fileget_registryr;   )argskwargsretrP   functionrK   s      r$   wrapperz5Recorder.record.<locals>.deco_record.<locals>.wrappern   sV     "D3F3C%%"+8I8I8K8V8V &    s   5AA)rV   r   rW   r   rG   r   r   )rY   rZ   rP   rK   s   ` r$   deco_recordz$Recorder.record.<locals>.deco_recordm   s     8_  Nr1   )rY   r   rG   zCallable[..., Any] )rK   rP   r[   s   `` r$   recordzRecorder.recordj   s    	 r1   )r;   c                    || j                         j                  }t        |d      5 }t        ||t        j
                         ddd       y# 1 sw Y   yxY w)z&Dump the recorded responses to a file.Nw)rU   r;   openrA   yamldump)rK   rP   r;   files       r$   rT   zRecorder.dump_to_file|   sO     **,77J)S! 	/T*dDII.	/ 	/ 	/s   AAc                    | j                  |j                        |_        ||_        t	        ||fi |}|j
                  j                         D ci c]  \  }}||
 }}}t        t        |j                        t        |j                  j                        |j                  |j                  |      }| j                  j                  |       |S c c}}w )N)r3   r4   r6   r5   r+   )_parse_request_paramspath_urlparams
req_kwargsr   r+   r   r   strr3   requestr4   status_codetextrN   add)	rK   adapterrj   rW   requests_responser/   valueheaders_valuesresponses_responses	            r$   _on_requestzRecorder._on_request   s     33G4D4DE#&wB6B):)B)B)H)H)J
%3CJ
 
 &w~~&%--112$00"''"
 	-.  
s   Callow_assertc                 &    t         |   d       y )NF)rt   )rI   stop)rK   rt   rL   s     r$   rv   zRecorder.stop   s    %(r1   )rG   N)rP   #Union[str, bytes, os.PathLike[Any]]rG   zUnion[Callable[[_F], _F], _F])rP   rw   r;   zOptional[List[BaseResponse]]rG   N)rn   r   rj   r   rW   r   rG   zmodels.Response)T)__name__
__module____qualname__r   ri   rJ   rO   r]   rT   rs   boolrv   __classcell__)rL   s   @r$   rC   rC   ^   s     ;/>	; ; -	;
 
;+ ETA	(, 6:	
/8
/ 3	
/
 

/!! #! 	!
 
!0) ) ) )r1   rC   )r    r   rG   r   )r-   r   rG   r   )r;   zList[BaseResponse]r<   zUnion[BinaryIO, TextIOWrapper]r=   zQCallable[[Union[Dict[Any, Any], List[Any]], Union[BinaryIO, TextIOWrapper]], Any]rG   N)"	functoolsr   typingr   osr   r   r   r	   r
   r   r   r   r)   r   r   r   r   r   r   ior   ra   r   r   r   responses.registriesr   r   r0   rA   rC   recorderr]   r\   r1   r$   <module>r      s      ,%) &   "    0.F$F1F `F 
	F>C)| C)L :	r1   