
    h/                        d dl mZ d dlmZ d dlmZmZ d dlmZm	Z	m
Z
 d dlmZ d dlmZmZmZmZ  edd	      Z ed
dd      Z G d deeef         Z G d deeef         Z G d d      Z G d d      Zy)    )annotations)abstractmethod)AbstractAsyncContextManagerAbstractContextManager)
isasyncgeniscoroutineisgenerator)TracebackType)ProtocolTypeVarcastfinal_T_coT)	covariant	_ExitT_cozbool | None)r   boundc                      e Zd ZddZy)_SupportsCtxMgrc                     y N selfs    AD:\jyotish\venv\Lib\site-packages\anyio/_core/_contextmanagers.py__contextmanager__z"_SupportsCtxMgr.__contextmanager__   s    c    N)returnz(AbstractContextManager[_T_co, _ExitT_co])__name__
__module____qualname__r   r   r   r   r   r      s    Qr   r   c                      e Zd Z	 	 ddZy)_SupportsAsyncCtxMgrc                     y r   r   r   s    r   __asynccontextmanager__z,_SupportsAsyncCtxMgr.__asynccontextmanager__   s    8;r   N)r   z-AbstractAsyncContextManager[_T_co, _ExitT_co])r   r   r    r$   r   r   r   r"   r"      s    <	6<r   r"   c                  j    e Zd ZU dZdZded<   edd       Ze	 	 	 	 	 	 	 	 	 	 d	d       Ze	d
d       Z
y)ContextManagerMixina  
    Mixin class providing context manager functionality via a generator-based
    implementation.

    This class allows you to implement a context manager via :meth:`__contextmanager__`
    which should return a generator. The mechanics are meant to mirror those of
    :func:`@contextmanager <contextlib.contextmanager>`.

    .. note:: Classes using this mix-in are not reentrant as context managers, meaning
        that once you enter it, you can't re-enter before first exiting it.

    .. seealso:: :doc:`contextmanagers`
    Nz2AbstractContextManager[object, bool | None] | None_ContextManagerMixin__cmc                   t        | t              sJ | j                  #t        d| j                  j
                   d      | j                         }t        |t              s.t        |      rt        d      t        d|j                        || u r"t        | j                  j
                   d      |j                         }|| _        |S )Nthis  has already been enteredz__contextmanager__() returned a generator object instead of a context manager. Did you forget to add the @contextmanager decorator?zB__contextmanager__() did not return a context manager object, but zq.__contextmanager__() returned self. Did you forget to add the @contextmanager decorator and a 'yield' statement?)
isinstancer&   r'   RuntimeError	__class__r    r   r   r	   	TypeError	__enter__r   cmvalues      r   r/   zContextManagerMixin.__enter__(   s     $ 344499 3344MN  $$&"452!  ||&( 
 :>>../ 0% &  	r   c                    t        | t              sJ | j                  #t        d| j                  j
                   d      | j                  }| `t        t        |j                  |||            S Nr)   z has not been entered yet)	r+   r&   r'   r,   r-   r    r   r   __exit__r   exc_typeexc_valexc_tbr1   s        r   r5   zContextManagerMixin.__exit__J   sn     $ 3444993344MN 
 YYIIr{{8WfEFFr   c                     y)a  
        Implement your context manager logic here.

        This method **must** be decorated with
        :func:`@contextmanager <contextlib.contextmanager>`.

        .. note:: Remember that the ``yield`` will raise any exception raised in the
            enclosed context block, so use a ``finally:`` block to clean up resources!

        :return: a context manager object
        Nr   r   s    r   r   z&ContextManagerMixin.__contextmanager__^       r   )r   z#_SupportsCtxMgr[_T_co, bool | None]r   r   )
r   z"_SupportsCtxMgr[object, _ExitT_co]r7   type[BaseException] | Noner8   BaseException | Noner9   TracebackType | Noner   r   )r   z+AbstractContextManager[object, bool | None])r   r   r    __doc__r'   __annotations__r   r/   r5   r   r   r   r   r   r&   r&      s     @DD
<C
 B G0G,G &G %	G
 
G G&  r   r&   c                  n    e Zd ZU dZdZded<   edd       Ze	 	 	 	 	 	 	 	 	 	 d	d       Ze		 	 d
d       Z
y)AsyncContextManagerMixina  
    Mixin class providing async context manager functionality via a generator-based
    implementation.

    This class allows you to implement a context manager via
    :meth:`__asynccontextmanager__`. The mechanics are meant to mirror those of
    :func:`@asynccontextmanager <contextlib.asynccontextmanager>`.

    .. note:: Classes using this mix-in are not reentrant as context managers, meaning
        that once you enter it, you can't re-enter before first exiting it.

    .. seealso:: :doc:`contextmanagers`
    Nz7AbstractAsyncContextManager[object, bool | None] | None_AsyncContextManagerMixin__cmc                  K   t        | t              sJ | j                  #t        d| j                  j
                   d      | j                         }t        |t              sTt        |      rt        d      t        |      r|j                          t        d      t        d|j                        || u r"t        | j                  j
                   d      |j                          d {   }|| _        |S 7 w)Nr)   r*   z__asynccontextmanager__() returned an async generator instead of an async context manager. Did you forget to add the @asynccontextmanager decorator?z__asynccontextmanager__() returned a coroutine object instead of an async context manager. Did you forget to add the @asynccontextmanager decorator and a 'yield' statement?zG__asynccontextmanager__() did not return an async context manager, but z{.__asynccontextmanager__() returned self. Did you forget to add the @asynccontextmanager decorator and a 'yield' statement?)r+   rB   rC   r,   r-   r    r$   r   r   r.   r   close
__aenter__r0   s      r   rF   z#AsyncContextManagerMixin.__aenter__~   s     $ 899999 3344MN  ))+"9:"~6 
 R
N  ||&( 
 :>>../ 0% &  mmo%	 &s   C/D1C?2Dc                   K   t        | t              sJ | j                  #t        d| j                  j
                   d      | j                  }| `t        t        |j                  |||       d {         S 7 wr4   )	r+   rB   rC   r,   r-   r    r   r   	__aexit__r6   s        r   rH   z"AsyncContextManagerMixin.__aexit__   sx      $ 8999993344MN 
 YYIIR\\(GV%LLMMLs   A0A=2A;
3	A=c                     y)a  
        Implement your async context manager logic here.

        This method **must** be decorated with
        :func:`@asynccontextmanager <contextlib.asynccontextmanager>`.

        .. note:: Remember that the ``yield`` will raise any exception raised in the
            enclosed context block, so use a ``finally:`` block to clean up resources!

        :return: an async context manager object
        Nr   r   s    r   r$   z0AsyncContextManagerMixin.__asynccontextmanager__   r;   r   )r   z(_SupportsAsyncCtxMgr[_T_co, bool | None]r   r   )
r   z'_SupportsAsyncCtxMgr[object, _ExitT_co]r7   r<   r8   r=   r9   r>   r   r   )r   z0AbstractAsyncContextManager[object, bool | None])r   r   r    r?   rC   r@   r   rF   rH   r   r$   r   r   r   rB   rB   m   s     EID
AH
& &P N5N,N &N %	N
 
N N$ 	9 r   rB   N)
__future__r   abcr   
contextlibr   r   inspectr   r   r	   typesr
   typingr   r   r   r   r   r   r   r"   r&   rB   r   r   r   <module>rP      s~    "  J 8 8  1 14(K4}E	Rhui/0 R<8E9$45 <S Sl[ [r   