
    EEi                         d dl Z ddlmZmZmZmZ ed        Zd Zd ZdZ		  e
d       e j                  j                  e	 d
      d        Zd Zd Zd Zd Zd Zd Zd Zy# e$ r d	Z	Y Cw xY w)    N   )aclosingasync_generatoryield_asynccontextmanagerc                    K   	 t        |       D ]  }t        |       d {     y 7 # t        $ r d|d<   Y y w xY ww)NTr   )ranger   GeneratorExit)countclosed_slotis      l/home/sietch6/trending-topics-pipeline/venv/lib/python3.12/site-packages/async_generator/_tests/test_util.pyasync_ranger      sC     u 	A)OO	 As(   >* (* >* ;>;>c                  j  K   dg} t        t        d|             4 d {   }t        t        d            }|2 3 d {   }|t	        |      k(  sJ |dk(  s d d d       d {    | d   sJ dg} 	 t        t        d|             4 d {   }t        t        d            }|2 3 d {   }|t	        |      k(  sJ |dk(  st               7 7 6 ~7 r# 1 d {  7  sw Y   xY w7 `7 C6 d d d       d {  7   n# 1 d {  7  sw Y   nxY wn# t
        $ r Y nw xY w| d   sJ y w)NF
      r   )r   r   iterr	   next
ValueError)r   genititems       r   test_aclosingr      sH    'KB45  %)_ 	 	$48###qy  q>>'KKK89 	' 	'SeBiB! ' 'dtBx'''19$,&	#   	''c	' 	' 	' 	' 	'  q>>s  D3CD3CCCCCCD3%C&D35D C/D D)C3-C1.C31D
DD3CCD3C, C#!C,(D3/D 1C33D4D ?D D DDDD D3	D(%D3'D((D3c                    K   t         t        d               } t        j                  t              5 } |        4 d {    t
        7 
# 1 d {  7  sw Y   nxY w	 d d d        n# 1 sw Y   nxY wj                  j                  d   dk(  sJ t        |j                  j                  t
              sJ t        j                  t              5 } |        4 d {  7   t        d      }|# 1 d {  7  sw Y   nxY w	 d d d        n# 1 sw Y   nxY w|j                  j                  d   dk(  sJ |j                  j                  }|j                  d   dk(  sJ |j                  u sJ t        j                  t              5 } |        4 d {  7   t        d      # 1 d {  7  sw Y   nxY w	 d d d        n# 1 sw Y   nxY w|j                  j                  d   dk(  sJ |j                  j                  J t         t        d               }t        j                  t              5   |       4 d {  7   t        # 1 d {  7  sw Y   nxY w	 d d d        y # 1 sw Y   y xY ww)Nc                  p   K   	 t                d {    y 7 # t        $ r} t        d      | d } ~ ww xY ww)Nissue29692:Chained)r   	ExceptionRuntimeError)excs    r   manager_issue29692z[test_contextmanager_do_not_unchain_non_stopiteration_exceptions.<locals>.manager_issue29692'   s1     	>(NN 	>34#=	>s(   6  6 	3.36r   r   issue29692:Unchainedzgenerator raised StopIterationc                  4   K   t                d {    y 7 wNr        r   noop_async_context_managerzctest_contextmanager_do_not_unchain_non_stopiteration_exceptions.<locals>.noop_async_context_managerF         h   )r   r   pytestraisesr   ZeroDivisionErrorvalueargs
isinstance	__cause__StopIterationStopAsyncIteration)r    excinfor   causer'   s        r   ?test_contextmanager_do_not_unchain_non_stopiteration_exceptionsr5   &   sU    >  > 
|	$ $%' 	$ 	$##	$ 	$ 	$ 	$ 	$$ $ $ ==a $8888gmm--/@AAA 
|	$ %' 	 	 67CI	 	 	 	   ==a $8888MM##E::a=<<<<??c!!!	)	* =g%' 	= 	=$%;<<	= 	= 	= 	== = = ==a $::::==""***   
}	%  -/ 	  	 	  	  	  	      s  /I<A)AA)A
A)
A	AA	A) 	I<)A2.A$I<DC!D#C11D	7C:8D	?D	I<DA8I<G	FG	F**F<	0F31F<	8G	 	I<	GA+I<9I0II0
II#	II#	I0'	I<0I95I<Tz
@asynccontextmanager
async def manager_issue29692_2():
    try:
        yield
    except Exception as exc:
        raise RuntimeError('issue29692:Chained') from exc
Fz1Python < 3.6 doesn't have native async generators)reasonc            	        K   t        j                  t              5 } t               4 d {    t        7 
# 1 d {  7  sw Y   nxY w	 d d d        n# 1 sw Y   nxY w j
                  j                  d   dk(  sJ t        | j
                  j                  t              sJ t        t        fD ]  }t        j                  |      5 } t               4 d {  7    |d      # 1 d {  7  sw Y   nxY w	 d d d        n# 1 sw Y   nxY w| j
                  j                  d   dk(  sJ | j
                  j                  J  y w)Nr   r   r!   )r*   r+   r   manager_issue29692_2r,   r-   r.   r/   r0   r1   r2   )r3   clss     r   Ftest_native_contextmanager_do_not_unchain_non_stopiteration_exceptionsr:   a   s6     
|	$ $') 	$ 	$##	$ 	$ 	$ 	$ 	$$ $ $ ==a $8888gmm--/@AAA12 /]]3 	27+- 2 20112 2 2 2	2 	2 	2 }}!!!$(>>>>}}&&.../s   EA6A8AA
	AA
	A	EA A/EDC
D	C((C:.C1/C:6D>	ED	;EEc            	      ~  K   t         t        d               } t        t        t        fD ])  }t        j                  |      5   |        4 d {    |  |        4 d {    	 d d d       d {    y 7 )# 1 d {  7  sw Y   nxY w	 d d d        o# 1 sw Y   xxY w7 C7 4# 1 d {  7  sw Y   y xY ww)Nc                  4   K   t                d {    y 7 wr#   r$   r%   r&   r   r'   zRtest_asynccontextmanager_exception_passthrough.<locals>.noop_async_context_managerx   r(   r)   )r   r   r2   r   r   r*   r+   )r'   exc_types     r   .test_asynccontextmanager_exception_passthroughr>   v   s        (zB ]]8$ 	13   *+    	    	 	 	
    s   ?B=BA7
BA9B= B$!B=$B(&B=1B&2B=7B9B?B BB	B=B!	B=&B=(B:.B1/B:6B=c                     K   t         t        d               }  |        4 d {    t        7 
# 1 d {  7  sw Y   y xY ww)Nc                     K   t        j                  t              5  t                d {    d d d        y 7 # 1 sw Y   y xY wwr#   )r*   r+   r   r   r%   r&   r   catch_itz<test_asynccontextmanager_catches_exception.<locals>.catch_it   s:      ]]:& 	(NN	 		 	s$   A:8:	A:AA)r   r   r   )rA   s    r   *test_asynccontextmanager_catches_exceptionrB      sL        z     s*   !A.A0AA9AAc                     K   t         t        d               } t        j                  t              5   |        4 d {    t
        7 
# 1 d {  7  sw Y   nxY w	 d d d        y # 1 sw Y   y xY ww)Nc                  \   K   	 t                d {    y 7 # t        $ r t        w xY wwr#   )r   KeyErrorr   r%   r&   r   	switch_itz?test_asynccontextmanager_different_exception.<locals>.switch_it   s(     	(NN 		s    ,  , ),)r   r   r*   r+   r   rE   )rF   s    r   ,test_asynccontextmanager_different_exceptionrG      sq        
z	" ; 	 	N	 	 	 	 	  sJ   /A5A)AA)A
A)
A	AA	A) 	A5)A2.A5c                  l  K   t         t        d               }  |        }t        j                  t              5 }|5  	 d d d        d d d        dt        j                        v sJ |4 d {    	 d d d       d {    y # 1 sw Y   GxY w# 1 sw Y   KxY w7 .7 # 1 d {  7  sw Y   y xY ww)Nc                  4   K   t                d {    y 7 wr#   r$   r%   r&   r   xxxz@test_asynccontextmanager_nice_message_on_sync_enter.<locals>.xxx   r(   r)   z
async withr   r   r*   r+   r   strr-   )rJ   cmr3   s      r   3test_asynccontextmanager_nice_message_on_sync_enterrN      s        
B	|	$  		 3w}}----    	 	     st   6B4BBB'B4,B-B40B2B4=B>B4B	BBB4B4B1%B(&B1-B4c                    K   t         t        d               } t        j                  t              5 } |        4 d {    J 7 # 1 d {  7  sw Y   nxY w	 d d d        n# 1 sw Y   nxY wdt        j                        v sJ y w)Nc                     K   y wr#   r%   r%   r&   r   yeehawz1test_asynccontextmanager_no_yield.<locals>.yeehaw   s      	s   zdidn't yieldrK   )rQ   r3   s     r   !test_asynccontextmanager_no_yieldrR      s        
|	$ 8 	 	5	 	 	 	 	   S////sJ   /BA%AA%AA%A	AA	A%	B%A.*!Bc                  J  K   dt         t        fd              } t        j                  t              5 } |        4 d {    	 d d d       d {    d d d        dt        j                        v sJ dk(  sJ t        j                  t              5 } |        4 d {    t        7 m7 ^# 1 d {  7  sw Y   nxY w# 1 sw Y   rxY w7 /# 1 d {  7  sw Y   nxY w	 d d d        n# 1 sw Y   nxY wdt        |j                        v sJ dk(  sJ y w)Nr   c                     K   	 t                d {    	 t                d {     dz   y 7 # t        $ r Y &w xY w7 #  dz   w xY ww)N   )r   r   )closed_counts   r   doubleyieldz=test_asynccontextmanager_too_many_yields.<locals>.doubleyield   sX     	(NN	(NN AL  		  ALsM   A2 02 A AA A2 	>A>AA A

Azdidn't stoprU   zdidn't stop after athrowr   )r   r   r*   r+   r   rL   r-   r   )rW   r3   rV   s     @r   (test_asynccontextmanager_too_many_yieldsrX      s$    L	  	 
|	$ = 	 		 	 C....1	|	$ = 	 		 	 	 	 	 	 	 	 	 	   &W]]);;;;1s   3D#C	B0C	B4C	B2C	AD#C6%C&C6)C0C	2C	4C	:B=;C	C		CD#C6C)	C C)	%C6-	D#6C?;(D#c                     K   t        j                  t              5  t        d        } d d d        y # 1 sw Y   y xY ww)Nc               3      K   d  y wr#   r%   r%   r&   r   syncgenzCtest_asynccontextmanager_requires_asyncgenfunction.<locals>.syncgen   s	     s   )r*   r+   	TypeErrorr   )r[   s    r   2test_asynccontextmanager_requires_asyncgenfunctionr]      s8     	y	! 		 
	  s   >2	>;>)r*    r   r   r   r   r   r   r5   nativeasyncgeneratorsexecSyntaxErrormarkskipifr:   r>   rB   rG   rN   rR   rX   r]   r%   r&   r   <module>rd      s     E E  .' V  "		 >  /	/""$
0>C  "!"s   A$ $A.-A.