a
    Q\a\                     @   s   d Z ddlZddlmZ ddlmZmZmZmZm	Z	 ddl
Z
dgZG dd dejZG dd	 d	ZG d
d deeZe	dZedee f edee f dddZdS )z
@asynccontextmanager code, copied from Python 3.7's contextlib.
For usage in Python 3.6.
Types have been added to this file, just enough to make Mypy happy.
    Nwraps)TYPE_CHECKINGAsyncContextManagerAsyncIteratorCallableTypeVarasynccontextmanagerc                   @   s2   e Zd ZdZdd Zejdd Zedd Z	dS )	AbstractAsyncContextManagerz9An abstract base class for asynchronous context managers.c                    s   | S )z0Return `self` upon entering the runtime context. selfr   r   Mlib/python3.9/site-packages/prompt_toolkit/eventloop/async_context_manager.py
__aenter__   s    z&AbstractAsyncContextManager.__aenter__c                    s   dS )z9Raise any exception triggered within the runtime context.Nr   )r   exc_type	exc_value	tracebackr   r   r   	__aexit__   s    z%AbstractAsyncContextManager.__aexit__c                 C   s   | t u rt|ddS tS )Nr   r   )r
   _collections_abc_check_methodsNotImplemented)clsCr   r   r   __subclasshook__   s    z,AbstractAsyncContextManager.__subclasshook__N)
__name__
__module____qualname____doc__r   abcabstractmethodr   classmethodr   r   r   r   r   r
      s   
r
   c                   @   s   e Zd ZdZdd ZdS )_GeneratorContextManagerBasezBShared functionality for @contextmanager and @asynccontextmanager.c                 C   sN   ||i || _ |||  | _| _| _t|dd }|d u rDt| j}|| _d S )Nr   )genfuncargskwdsgetattrtyper   )r   r#   r$   r%   docr   r   r   __init__'   s    
z%_GeneratorContextManagerBase.__init__N)r   r   r   r   r)   r   r   r   r   r!   $   s   r!   c                   @   s    e Zd ZdZdd Zdd ZdS )_AsyncGeneratorContextManagerz Helper for @asynccontextmanager.c                    s4   z| j  I d H W S  ty.   tdd Y n0 d S )Nzgenerator didn't yield)r"   	__anext__StopAsyncIterationRuntimeErrorr   r   r   r   r   ;   s    z(_AsyncGeneratorContextManager.__aenter__c              
      s0  |d u r<z| j  I d H  W n ty0   Y d S 0 tdn|d u rJ| }z"| j |||I d H  tdW n ty } z||uW  Y d }~S d }~0  t y } zJ||u rW Y d }~dS t|ttfr|j|u rW Y d }~dS  W Y d }~n:d }~0  ty* } z||ur W Y d }~n
d }~0 0 d S )Nzgenerator didn't stopz$generator didn't stop after athrow()F)	r"   r+   r,   r-   athrow
isinstanceStopIteration	__cause__BaseException)r   typvaluer   excr   r   r   r   A   s.    


z'_AsyncGeneratorContextManager.__aexit__N)r   r   r   r   r   r   r   r   r   r   r*   6   s   r*   _T.)r#   returnc                    s   t   fdd}|S )a  @asynccontextmanager decorator.
    Typical usage:
        @asynccontextmanager
        async def some_async_generator(<arguments>):
            <setup>
            try:
                yield <value>
            finally:
                <cleanup>
    This makes this:
        async with some_async_generator(<arguments>) as <variable>:
            <body>
    equivalent to this:
        <setup>
        try:
            <variable> = <value>
            <body>
        finally:
            <cleanup>
    c                     s   t  | |S )N)r*   )r$   r%   r#   r   r   helper   s    z#asynccontextmanager.<locals>.helperr   )r#   r9   r   r8   r   r	   h   s    )r   r   	functoolsr   typingr   r   r   r   r   r   __all__ABCr
   r!   r*   r6   r	   r   r   r   r   <module>   s   
/