o
    aZ                     @   sH   d dl Z d dlmZ ddlmZ G dd dZG dd dZd	d
 ZdS )    N)wraps   )isasyncgenfunctionc                   @   s$   e Zd Zdd Zdd Zdd ZdS )aclosingc                 C   s
   || _ d S N_aiter)selfaiter r   9usr/lib/python3.10/site-packages/async_generator/_util.py__init__   s   
zaclosing.__init__c                    s   | j S r   r   r	   r   r   r   
__aenter__
   s   zaclosing.__aenter__c                    s   | j  I d H  d S r   )r   aclose)r	   argsr   r   r   	__aexit__   s   zaclosing.__aexit__N)__name__
__module____qualname__r   r   r   r   r   r   r   r      s    r   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )_AsyncGeneratorContextManagerc                 C   s    |j | _||i | | _d S r   )r   
_func_name	__aiter___agen)r	   funcr   kwdsr   r   r   r      s   z&_AsyncGeneratorContextManager.__init__c                    sH   t jdk r| jI d H | _z
| jd I d H W S  ty#   tdd w )N)         zasync generator didn't yield)sysversion_infor   asendStopAsyncIterationRuntimeErrorr   r   r   r   r      s   

z(_AsyncGeneratorContextManager.__aenter__c                    s  t | j4 I d H  |d u r1z| jd I d H  W td ty0   Y W d   I d H  dS w |d us7J z| j|||I d H  td tyf } z||uW  Y d }~W  d   I d H  S d }~w ty } z1||u rW Y d }~W d   I d H  dS t|ttfr|j|u rW Y d }~W d   I d H  dS  d }~w   t	
 d |u rY W d   I d H  dS  1 I d H sw   Y  d S )NFzasync generator didn't stopz*async generator didn't stop after athrow()r   )r   r   r!   r"   r#   athrow
isinstanceStopIteration	__cause__r   exc_info)r	   typevalue	tracebackexcr   r   r   r   &   sH   


"-z'_AsyncGeneratorContextManager.__aexit__c                 C   s   t dj| jd)Nz>use 'async with {func_name}(...)', not 'with {func_name}(...)')	func_name)r#   formatr   r   r   r   r   	__enter__V   s
   z'_AsyncGeneratorContextManager.__enter__c                 C   s   J d)NFz#Never called, but should be definedr   r   r   r   r   __exit__\   s   z&_AsyncGeneratorContextManager.__exit__N)r   r   r   r   r   r   r/   r0   r   r   r   r   r      s    0r   c                    s.   t  stdt  fdd}d|_|S )z Like @contextmanager, but async.z{must be an async generator (native or from async_generator; if using @async_generator then @acontextmanager must be on top.c                     s   t  | |S r   )r   )r   r   r   r   r   helperh   s   z#asynccontextmanager.<locals>.helperT)r   	TypeErrorr   Z__returns_acontextmanager__)r   r2   r   r1   r   asynccontextmanager`   s   r4   )r   	functoolsr   _implr   r   r   r4   r   r   r   r   <module>   s    G