§
    +P„j×  ã                  óÊ   — d Z ddlmZ ddlZddlmZ ddlZddlZddlmZm	Z	m
Z
  e
d¦  «        Z G d„ dej        e	e         ¦  «        Z G d	„ d
eej                 ¦  «        ZdS )zContextmanager utils.é    )ÚannotationsN)ÚIterable)ÚAnyÚGenericÚTypeVarÚ_Tc                  ób   ‡ — e Zd ZdZˆ fd„Zej        dd„¦   «         Zde_        dd„Z	dd
„Z
ˆ xZS )ÚContextManageraƒ  ContextManager allows to define contextmanager class using yield-syntax.

  Example:

  ```python
  class A(epy.ContextManager):

    def __contextmanager__(self) -> Iterable[A]:
      yield self


  with A() as a:
    pass
  ```

  One the code is more mature, this could be merged to `contextlib` directly.
  https://discuss.python.org/t/yield-based-contextmanager-for-classes/8453

  c                ó¼   •—  t          ¦   «         j        di |¤Ž t          | j        d¦  «        s,t	          j        | j        ¦  «        | _        d| j        _        d S d S )NÚ	_cm_addedT© )ÚsuperÚ__init_subclass__ÚhasattrÚ__contextmanager__Ú
contextlibÚcontextmanagerr   )ÚclsÚkwargsÚ	__class__s     €úY/root/disk_3tb/conda_envs/Huy-visual/lib/python3.11/site-packages/etils/epy/contextlib.pyr   z ContextManager.__init_subclass__9   sk   ø€ Ø…E�G„GÔÐ'Ð' Ð'Ð'Ð'õ �3Ô)¨;Ñ7Ô7ð Ý)Ô8¸Ô9OÑPÔP€cÔà
ð 
ÔÔ&Ð&Ð&ðð ó    ÚreturnúIterable[_T]c                ó   — d S ©Nr   ©Úselfs    r   r   z!ContextManager.__contextmanager__C   s   € à€Dr   Tr   c                ó�   — t                                | d|                      ¦   «         ¦  «         | j                             ¦   «         S )NÚ_epy_cm)ÚobjectÚ__setattr__r   r    Ú	__enter__r   s    r   r#   zContextManager.__enter__I   s:   € å
×Ò�t˜Y¨×(?Ò(?Ñ(AÔ(AÑBÔBÐBØŒ<×!Ò!Ñ#Ô#Ð#r   ÚNonec                ó:   — | j                              |||¦  «        S r   )r    Ú__exit__)r   Úexc_typeÚ	exc_valueÚ	tracebacks       r   r&   zContextManager.__exit__N   s   € ØŒ<× Ò  ¨9°iÑ@Ô@Ð@r   )r   r   )r   r   )r   r$   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚabcÚabstractmethodr   r   r#   r&   Ú__classcell__)r   s   @r   r
   r
   $   s¡   ø€ € € € € ðð ð(ð ð ð ð ð Ôð	ð 	ð 	ñ Ôð	ð "&ÐÔð$ð $ð $ð $ð
Að Að Að Að Að Að Að Ar   r
   c                  ó"   — e Zd ZdZd	d„Zd
d„ZdS )Ú	ExitStacka'  Like `contextlib.ExitStack` but allows to set contextmanagers at init time.

  ```python
  with epy.ExitStack([A(), B()]) as stack:
    pass
  ```

  Outputs are not available.

  See:
  https://discuss.python.org/t/add-init-self-contexts-iterable-contextmanager-to-contextlib-exitstack/19906
  Úcontextsú$Iterable[typing.ContextManager[Any]]c                ó.   — t          |¦  «        | _        d S r   )ÚlistÚ	_contexts)r   r3   s     r   Ú__init__zExitStack.__init__a   s   € Ý˜(‘^”^€D„N€N€Nr   r   úIterable[contextlib.ExitStack]c              #  ó¨   K  — t          j        ¦   «         5 }| j        D ]}|                     |¦  «         Œ|V — d d d ¦  «         d S # 1 swxY w Y   d S r   )r   r2   r7   Úenter_context)r   ÚstackÚcontexts      r   r   zExitStack.__contextmanager__d   s§   è è € Ý	Ô	Ñ	Ô	ð  5Ø”^ð %ð %ˆ'Ø×Ò˜GÑ$Ô$Ð$Ð$Ø€k€k€kðð ð ñ ô ð ð ð ð ð ð ð øøøð ð ð ð ð ð s   –$AÁAÁAN)r3   r4   )r   r9   )r*   r+   r,   r-   r8   r   r   r   r   r2   r2   S   sF   € € € € € ðð ð$ð $ð $ð $ðð ð ð ð ð r   r2   )r-   Ú
__future__r   r.   Úcollections.abcr   r   Útypingr   r   r   r   ÚABCr
   r2   r   r   r   ú<module>rB      sñ   ðð Ð à "Ð "Ð "Ð "Ð "Ð "à 
€
€
€
Ø $Ð $Ð $Ð $Ð $Ð $Ø Ð Ð Ð Ø €€€Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ð (à€WˆT�]„]€ð+Að +Að +Að +Að +A�S”W˜g bœkñ +Aô +Að +Að^ð ð ð ð �˜zÔ3Ô4ñ ô ð ð ð r   