
    BTh$C                     @   d Z ddlZddl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  ej                  e      Zej                   Zej$                  Z	 ddlmZmZ eZeZeZdZdZ 	 ddl!m"Z  ddl#m$Z e jJ                  Z&e j                   Z'e j$                  Z(	 ddl)Z)e)jT                  dk  r ed	      	 ddl+Z+e+jX                  Z-e+j\                  Z/e+j`                  Z1	 ddl2Z3e3jh                  jj                  jl                  Z7	 ddl8Z3e3jr                  jt                  jl                  Z;	 ddl<Z=e=j                  j|                  j~                  Z@	 ddlAZAeAj                  j                  ZDeAj                  j                  ZF G d
 d      ZG G d d      ZHd ZIej                  d        ZKy# e$ r$Z	 ddlZ ed      e# e$ r Y nw xY wY dZ[hdZ[ww xY w# e$ r Y Cw xY w# e$ r Y 3w xY w# e$ r Y w xY w# e$ r Y w xY w# e$ r Y w xY w# e$ r Y w xY w# e$ r Y w xY w)z#Utilities for patching in cassettes    N)mock   )VCRHTTPConnectionVCRHTTPSConnection)AWSHTTPConnectionAWSHTTPSConnectionzcvcrpy >=4.2.2 and botocore <1.11.0 are not compatible; please upgrade botocore (or downgrade vcrpy)i zcvcrpy >=4.2.2 and requests <2.16.2 are not compatible; please upgrade requests (or downgrade vcrpy)c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
ed	        Zd
 Zed        Zd Zd Zd Zed        Zed        Zed        Zed        Zd Zy)CassettePatcherBuilderc                 B     t        j                          fd       }|S )Nc                 :    | j                   | g|i |      S N)!_build_patchers_from_mock_triples)selfargskwargsfunctions      [/var/www/catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/vcr/patch.pywrappedzSCassettePatcherBuilder._build_patchers_from_mock_triples_decorator.<locals>.wrappedi   s$    99(4:Y$:YRX:YZZ    )	functoolswraps)r   r   s   ` r   +_build_patchers_from_mock_triples_decoratorzBCassettePatcherBuilder._build_patchers_from_mock_triples_decoratorh   s'    		"	[ 
#	[ r   c                      || _         i | _        y r   )	_cassette_class_to_cassette_subclass)r   cassettes     r   __init__zCassettePatcherBuilder.__init__o   s    !+-(r   c                 b   t        j                  | j                         | j                         | j	                         | j                         | j                         | j                         | j                         | j                         | j                  | j                  j                        	      S r   )	itertoolschain_httplib	_requests_boto3_urllib3	_httplib2_tornado_aiohttp_httpxr   r   custom_patchesr   s    r   buildzCassettePatcherBuilder.builds   su    MMONNKKMMMONNMMOMMOKKM224>>3P3PQ

 
	
r   c              #   F   K   |D ]  } | j                   | }|s|  y wr   )_build_patcher)r   mock_triplesr   patchers       r   r   z8CassettePatcherBuilder._build_patchers_from_mock_triples   s/       	D)d))40G	s   !!c                 |    t        ||      sy t        j                  j                  ||| j	                  |            S r   )hasattrr   patchobject(_recursively_apply_get_cassette_subclass)r   objpatched_attributereplacement_classs       r   r-   z%CassettePatcherBuilder._build_patcher   s<    s-.zz  99:KL
 	
r   c                     t        |t              r0|j                         D ]  \  }}| j                  |      }|||<    |S t	        |d      r| j                  |      }|S )a  One of the subtleties of this class is that it does not directly
        replace HTTPSConnection with `VCRRequestsHTTPSConnection`, but a
        subclass of the aforementioned class that has the `cassette`
        class attribute assigned to `self._cassette`. This behavior is
        necessary to properly support nested cassette contexts.

        This function exists to ensure that we use the same class
        object (reference) to patch everything that replaces
        VCRRequestHTTP[S]Connection, but that we can talk about
        patching them with the raw references instead, and without
        worrying about exactly where the subclass with the relevant
        value for `cassette` is first created.

        The function is recursive because it looks in to dictionaries
        and replaces class values at any depth with the subclass
        described in the previous paragraph.
        r   )
isinstancedictitemsr4   r1   _get_cassette_subclass)r   replacement_dict_or_objkeyreplacement_objs       r   r4   z?CassettePatcherBuilder._recursively_apply_get_cassette_subclass   ss    $ -t4(?(E(E(G ?$_"&"O"OP_"`/>',? +**J7&*&A&ABY&Z#&&r   c                     |j                   |S || j                  vr | j                  |      }|| j                  |<   | j                  |   S r   )r   r   _build_cassette_subclass)r   klasssubclasss      r   r<   z-CassettePatcherBuilder._get_cassette_subclass   sP    >>%L88844U;H6>D,,U3//66r   c                     |f}t        |t              s
|t        fz  }t        |j                   | j                  j
                   |d| j                  i      S )Nr   )
issubclassr3   type__name__r   _path)r   
base_classbasess      r   rA   z/CassettePatcherBuilder._build_cassette_subclass   sU    *f-fYEz**+DNN,@,@+ABEJX\XfXfKghhr   c              #   H   K   t         dt        f t         dt        f y w)NHTTPConnectionHTTPSConnection)httplibr   r   r*   s    r   r!   zCassettePatcherBuilder._httplib   s$     '):::(*<<<s    "c                 d    	 ddl m} | j                  t        t
        |      S # t        $ r Y yw xY w)Nr   )requests_stubs )stubsrP   ImportError_urllib3_patcherscpoolconn)r   rP   s     r   r"   z CassettePatcherBuilder._requests   s5    	- %%eT>BB  		s   # 	//c              #      K   	 dd l m} ddlm} t        j                  d|       |j                  d|j                  f |j                  d|j                  f y # t        $ r Y y w xY ww)Nr   r   )boto3_stubszPatching boto3 cpool with %sConnectionCls)botocore.awsrequest
awsrequestrR   rX   logdebugAWSHTTPConnectionPoolVCRRequestsHTTPConnectionAWSHTTPSConnectionPoolVCRRequestsHTTPSConnectionrS   )r   rU   rX   s      r   r#   zCassettePatcherBuilder._boto3   sh     
	h/ +II4e<--@e@eee..AgAggg  		s(   A,A AA,	A)&A,(A))A,c                 `    |j                   t        j                        dfd	       }|S )Nc                      | |      }t        | d      r| j                  n        }t        ||      s | |      }t        ||      s|S )NrY   )r1   rY   r9   )pooltimeout
connectionconnection_classconnection_class_getterget_conns       r   patched_get_connzBCassettePatcherBuilder._patched_get_conn.<locals>.patched_get_conn   sX    !$0J&-dO&D""JaJc  !-=>%dG4
 !-=>r   r   )	_get_connr   r   )r   connection_pool_classrh   rj   ri   s     ` @r   _patched_get_connz(CassettePatcherBuilder._patched_get_conn   s1    (22		"	 
#	  r   c                 ^    |j                   t        j                        fd       }|S )Nc                 <     |       }j                  | |       |S r   )add_connection_to_pool_entry)rd   new_connectionconnection_removernew_conns     r   patched_new_connzBCassettePatcherBuilder._patched_new_conn.<locals>.patched_new_conn   s"    %d^N;;D.Q!!r   )	_new_connr   r   )r   rl   rr   rt   rs   s     ` @r   _patched_new_connz(CassettePatcherBuilder._patched_new_conn   s1    (22		"	" 
#	"
  r   c                 l    	 dd l m} dd lm} ddlm} | j                  |||      S # t        $ r Y yw xY w)Nr   rQ   r   )urllib3_stubs)urllib3.connectionrf   urllib3.connectionpoolconnectionpoolrS   rR   rx   rT   )r   rV   rU   rx   s       r   r$   zCassettePatcherBuilder._urllib3   s;    	-2 	)%%eT=AA	  		s   ' 	33c              #   t   K   	 dd l }ddlm}m} |d|f |d|f |d||df y # t        $ r Y y w xY ww)Nr   r   )VCRHTTPConnectionWithTimeoutVCRHTTPSConnectionWithTimeoutHTTPConnectionWithTimeoutHTTPSConnectionWithTimeoutSCHEME_TO_CONNECTION)httphttps)httplib2stubs.httplib2_stubsr}   r~   rS   )r   rU   r}   r~   s       r   r%   z CassettePatcherBuilder._httplib2   s`     	$ j46RRR57TTT&8:   		s   8) !8	5858c              #     K   	 dd l m} ddlm}  || j                  t
              }|j                  d|f 	 dd lm	} ddlm}  || j                  t              }|j                  d|f y # t        $ r Y Aw xY w# t        $ r Y y w xY ww)Nr   r   )vcr_fetch_impl
fetch_impl)tornado.simple_httpclientsimple_httpclientstubs.tornado_stubsr   r   !_SimpleAsyncHTTPClient_fetch_implSimpleAsyncHTTPClientrS   tornado.curl_httpclientcurl_httpclient_CurlAsyncHTTPClient_fetch_implCurlAsyncHTTPClient)r   simpler   new_fetch_implcurls        r   r&   zCassettePatcherBuilder._tornado  s     	M6 <+DNN<]^N..nLL	I2 <+DNN<[\N**L.HH  		  		sI   BA. .BA= /B.	A:7B9A::B=	B	BB		Bc              #      K   	 dd l m} ddlm}  || j                  t
              }|j                  d|f y # t        $ r Y y w xY ww)Nr   r   )vcr_request_request)aiohttp.clientclientstubs.aiohttp_stubsr   r   _AiohttpClientSessionRequestClientSessionrS   )r   r   r   new_requests       r   r'   zCassettePatcherBuilder._aiohttp&  sK     	@+ 9%dnn6RSK&&
K??  		s%   A9 /A	AAAAc              #      K   	 dd l }ddlm}m}  || j                  t
              }|j                  d|f  || j                  t              }|j                  d|f y # t        $ r Y y w xY ww)Nr   r   )async_vcr_sendsync_vcr_send_send_single_request)
httpxstubs.httpx_stubsr   r   r   %_HttpxAsyncClient_send_single_requestAsyncClient$_HttpxSyncClient_send_single_requestClientrS   )r   r   r   r   new_async_client_sendnew_sync_client_sends         r   r(   zCassettePatcherBuilder._httpx2  st     	M I$24>>Ch$i!##%;=RRR#0Ae#f ,, 68LLL  		s(   A0A! AA0!	A-*A0,A--A0c           
          t        | j                  |j                              }t        | j                  |j                              }|d|j                  f|d|j                  f|d|j                  fdt	        j
                  d      fj                  d|j                  fj                  d|j                  ff}|j                  d| j                  j                  fd	      fj                  d| j                  j                  fd
      fj                  d| j                  j                  |      fj                  d| j                  j                  |      ffz  }t        j                  | j                  |      ||f      S )NVerifiedHTTPSConnectionrL   rM   is_connection_droppedF)return_valuerY   rk   c                       j                   S r   )rL   rU   s   r   <lambda>z:CassettePatcherBuilder._urllib3_patchers.<locals>.<lambda>V  s    I]I] r   c                       j                   S r   )rM   r   s   r   r   z:CassettePatcherBuilder._urllib3_patchers.<locals>.<lambda>[  s    %J_J_ r   ru   )ConnectionRemoverr<   r_   ra   r   MockHTTPConnectionPoolHTTPSConnectionPoolrm   rv   r   r    r   )r   rU   rV   rR   http_connection_removerhttps_connection_removerr.   s    `     r   rT   z(CassettePatcherBuilder._urllib3_patchersA  s   "3''(G(GH#
 $5''(H(HI$
  ,e.N.NO#U%D%DE$e&F&FG+TYYE-JK%%8W8WX&&9Y9YZ
 	((&&u'?'?A]^ ))&&u'@'@B_` ((&&u'?'?AXY ))&&u'@'@BZ[!
 	
. 22<@$&>?
 	
r   N)rG   
__module____qualname__r   r   r+   r   r-   r4   r<   rA   r!   r"   r#   rm   rv   r$   r%   r&   r'   r(   rT   rQ   r   r   r
   r
   g   s    .

'67i 1= 1=C 1h 1h *	 B 1 1& 1I 1I( 1	@ 1	@ 1M 1M+
r   r
   c                   $    e Zd Zd Zd Zd Zd Zy)r   c                      || _         i | _        y r   )_connection_class_connection_pool_to_connections)r   rg   s     r   r   zConnectionRemover.__init__p  s    !1/1,r   c                     t        || j                        r4| j                  j                  |t	                     j                  |       y y r   )r9   r   r   
setdefaultsetadd)r   rd   rf   s      r   rp   z.ConnectionRemover.add_connection_to_pool_entryt  s:    j$"8"8900;;D#%HLLZX :r   c                     | S r   rQ   r*   s    r   	__enter__zConnectionRemover.__enter__x  s    r   c                    | j                   j                         D ]  \  }}g }|j                  r|j                  j                         s|r|j                  j	                         }t        || j                        r"|j                  |       |j                          n|j                  |       |j                  r|j                  j                         s|r|D ]  }|j                  |        |D ]  }|j                            y r   )r   r;   rd   emptygetr9   r   removecloseappend	_put_conn)r   r   rd   connectionsreadd_connectionsrf   s         r   __exit__zConnectionRemover.__exit__{  s    !%!E!E!K!K!M 	#D+ "))DIIOO$5+!YY]]_
j$*@*@A&&z2$$&%,,Z8 ))DIIOO$5+ 0 +
z*+) #
  "#	#r   N)rG   r   r   r   rp   r   r   rQ   r   r   r   r   o  s    2Y#r   r   c               #     K   t         j                  j                  t        dt               t         j                  j                  t        dt
               	 dd lm}  dd lm	} t         j                  j                  | dt               t         j                  j                  | dt               t         j                  j                  | dt               t        |j                  d      rct         j                  j                  |j                  dt               t         j                  j                  |j                  dt               	 	 dd lm} t        |j&                  d      rbt         j                  j                  |j&                  dt(               t         j                  j                  |j*                  dt,               t        |d      r(t         j                  j                  |dt,               	 	 dd l}t         j                  j                  |dt0               t         j                  j                  |dt2               t         j                  j                  |d	t4               	 dd lm} t         j                  j                  |j:                  d
t<               	 dd lm } t         j                  j                  |jB                  d
tD               y # t         $ r Y w xY w# t         $ r Y w xY w# t         $ r Y w xY w# t         $ r Y sw xY w# t         $ r Y y w xY ww)NrL   rM   r   r   rY   r   r   r   r   r   )#r   r2   r3   rN   _HTTPConnection_HTTPSConnectionry   rf   rz   r{   _VerifiedHTTPSConnection_connHTTPConnection_connHTTPSConnectionr1   r   r   rS   rZ   r[   r^   _cpoolBoto3HTTPConnectionr`   _cpoolBoto3HTTPSConnectionr   _HTTPConnectionWithTimeout_HTTPSConnectionWithTimeout_SCHEME_TO_CONNECTIONr   r   r   r   r   r   r   r   )rV   rU   r   r   s       r   reset_patchersr     s}    
**

G%5
GG
**

G%68H
IIf). jj&?AYZZjj&68KLLjj&79MNN5++_=**##E$<$<oObcc**##E$=$=Pdee]+ 5..@**##E$?$?Rkll**##E$@$@/Smnn5./**##E+?A[\\V  jj'BD^__jj'CE`aajj'=?TUUo2 jj < <lLmnni. jj 8 8,HghhW          s   AL?K2 &C.L?L B,L?L A5L?L! 1L?:L0  2L?2	K?;L?>K??L?	LL?LL?	LL?LL?!	L-*L?,L--L?0	L<9L?;L<<L?c               #      K   t        j                         5 } t               D ]  }| j                  |        d  d d d        y # 1 sw Y   y xY wwr   )
contextlib	ExitStackr   enter_context)
exit_stackr/   s     r   force_resetr     sK     				 :%' 	.G$$W-	.  s   A%A	AA
A)L__doc__r   r   http.clientr   rN   r   loggingunittestr   rR   r   r   	getLoggerrG   r\   rL   r   rM   r   rZ   r   r   _Boto3VerifiedHTTPSConnectionr   r   rS   ebotocore.vendored.requestsbotocoreRuntimeErrorrU   rV   ry   rf   rz   r{   r   r   r   r   requests	__build__r   r   r   r   r   r   r   r   tornador   r   r   r   r   r   r   r   r   aiohttpr   r   r   r   r   r   r   r   r   r
   r   r   contextmanagerr   rQ   r   r   <module>r      s   )       8g!((** 4I %7! 1!30%*  $;;--//	
 H$=
 	
: "*!C!C"*"E"E$99c$ )0(A(A(W(W(b(b%]" '.&=&=&Q&Q&\&\#I $+>>#?#?#H#H S ,1<<+L+L(,1,=,=,R,R)E
 E
P# #82ij  [  	) =
 	  		*  		  		  		  		  		  		  		s   F$ %G G 2G( G4  G? %H
 
H $G*F7.	G7F?<G>F??GGGGG%$G%(G10G14G<;G<?HH
HHHH