o
    ˷eM                     @   s   d Z ddlZddlmZ ddl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dedee f dedee f f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)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
   e/var/www/ideatree/venv/lib/python3.10/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 r"t| 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                    s.   z	| j  I d H W S  ty   tdd w )Nzgenerator didn't yield)r!   	__anext__StopAsyncIterationRuntimeErrorr   r
   r
   r   r   ;   s   
z(_AsyncGeneratorContextManager.__aenter__c              
      s  |d u rz| j  I d H  W td ty   Y d S w |d u r$| }z| j |||I d H  td tyI } z
||uW  Y d }~S d }~w tys } z||u r[W Y d }~dS t|ttfrn|j|u rnW Y d }~dS  d }~w ty } z||ur W Y d }~d S d }~ww )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)   _Tr"   .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"   r8   r
   r7   r   r   h   s   )r   r   	functoolsr   typingr   r   r   r   r   __all__ABCr	   r    r)   r5   r   r
   r
   r
   r   <module>   s"    
/