o
    Rh                     @  s|  d dl mZ d dlZd dlmZmZmZmZmZm	Z	m
Z
mZmZmZ d dlZddlmZmZ er=d dlmZmZ edZndd	 Zg d
ZedddZedZed,ddZed-ddZd-ddZed.dd Zed/d"d Zd/d#d Zejd$d$dd%G d&d' d'eje	e Zeejdd$dd(G d)d* d*ee e	e Zeejdd$dd(G d+d dee
 Zeee ef Z dS )0    )annotationsN)
TYPE_CHECKINGAsyncGenerator	AwaitableCallable	GeneratorGenericNoReturnTypeVarUnionoverload   )AlreadyUsedErrorremove_tb_frames)	ParamSpecfinalArgsTc                 C  s   | S N )funcr   r   O/home/air/sanwanet/backup_V2/venv/lib/python3.10/site-packages/outcome/_impl.pyr      s   r   )ErrorOutcomeMaybeValueacapturecaptureValueTT)	covariantResultTsync_fnCallable[ArgsT, NoReturn]args
ArgsT.argskwargsArgsT.kwargsreturnr   c                 O     d S r   r   r    r"   r$   r   r   r   r   $   s   r   Callable[ArgsT, ResultT]Value[ResultT] | Errorc                 O  r'   r   r   r(   r   r   r   r   .   s   c              
   O  sL   z
t | |i |W S  ty% } zt|d}t|W  Y d}~S d}~ww )zRun ``sync_fn(*args, **kwargs)`` and capture the result.

    Returns:
      Either a :class:`Value` or :class:`Error` as appropriate.

    r   Nr   BaseExceptionr   r   )r    r"   r$   excr   r   r   r   7   s   
async_fn$Callable[ArgsT, Awaitable[NoReturn]]c                      d S r   r   r.   r"   r$   r   r   r   r   I      r   #Callable[ArgsT, Awaitable[ResultT]]c                   r0   r   r   r1   r   r   r   r   R   r2   c              
     sT   zt | |i |I dH W S  ty) } zt|d}t|W  Y d}~S d}~ww )zRun ``await async_fn(*args, **kwargs)`` and capture the result.

    Returns:
      Either a :class:`Value` or :class:`Error` as appropriate.

    Nr   r+   )r.   r"   r$   r-   r   r   r   r   [   s   
F)reprinitslotsc                   @  sd   e Zd ZU dZejddddZded< ddd	Ze	j
dddZe	j
dddZe	j
dddZdS )r   a;  An abstract class representing the result of a Python computation.

    This class has two concrete subclasses: :class:`Value` representing a
    value, and :class:`Error` representing an exception.

    In addition to the methods described below, comparison operators on
    :class:`Value` and :class:`Error` objects (``==``, ``<``, etc.) check that
    the other object is also a :class:`Value` or :class:`Error` object
    respectively, and then compare the contained objects.

    :class:`Outcome` objects are hashable if the contained objects are
    hashable.

    F)defaulteqr5   bool
_unwrappedr&   Nonec                 C  s   | j rtt| dd d S )Nr:   T)r:   r   object__setattr__selfr   r   r   _set_unwrapped   s   zOutcome._set_unwrappedr   c                 C     dS )zReturn or raise the contained value or exception.

        These two lines of code are equivalent::

           x = fn(*args)
           x = outcome.capture(fn, *args).unwrap()

        Nr   r>   r   r   r   unwrap       zOutcome.unwrapgen"Generator[ResultT, ValueT, object]r   c                 C  rA   )zSend or throw the contained value or exception into the given
        generator object.

        Args:
          gen: A generator object supporting ``.send()`` and ``.throw()``
              methods.

        Nr   r?   rD   r   r   r   send   rC   zOutcome.sendagenAsyncGenerator[ResultT, ValueT]c                   s   dS )zSend or throw the contained value or exception into the given async
        generator object.

        Args:
          agen: An async generator object supporting ``.asend()`` and
              ``.athrow()`` methods.

        Nr   r?   rH   r   r   r   asend   s    zOutcome.asendN)r&   r;   r&   r   rD   rE   r&   r   rH   rI   r&   r   )__name__
__module____qualname____doc__attribr:   __annotations__r@   abcabstractmethodrB   rG   rK   r   r   r   r   r   m   s   
 


r   )frozenr4   r6   c                   @  sL   e Zd ZU dZe Zded< 	 dddZddd	Z	dddZ
dddZdS )r   zFConcrete :class:`Outcome` subclass representing a regular value.

    r   valuer&   strc                 C     d| j dS )NzValue())rY   r>   r   r   r   __repr__      zValue.__repr__c                 C  s   |    | jS r   )r@   rY   r>   r   r   r   rB      s   zValue.unwraprD   rE   r   c                 C     |    || jS r   )r@   rG   rY   rF   r   r   r   rG         z
Value.sendrH   rI   c                      |    || jI d H S r   )r@   rK   rY   rJ   r   r   r   rK         zValue.asendNr&   rZ   rL   rM   rN   )rO   rP   rQ   rR   rS   rT   rY   rU   r]   rB   rG   rK   r   r   r   r   r      s   
 


r   c                   @  sX   e Zd ZU dZejejedZ	de
d< 	 dddZdd
dZdddZdddZdS )r   zIConcrete :class:`Outcome` subclass representing a raised exception.

    )	validatorr,   errorr&   rZ   c                 C  r[   )NzError(r\   )re   r>   r   r   r   r]      r^   zError.__repr__r	   c                 C  s   |    | j}z|~~ w r   )r@   re   )r?   captured_errorr   r   r   rB      s
   zError.unwraprD   $Generator[ResultT, NoReturn, object]r   c                 C  r_   r   )r@   throwre   rF   r   r   r   rG      r`   z
Error.sendrH   !AsyncGenerator[ResultT, NoReturn]c                   ra   r   )r@   athrowre   rJ   r   r   r   rK      rb   zError.asendNrc   )r&   r	   )rD   rg   r&   r   )rH   ri   r&   r   )rO   rP   rQ   rR   rS   rT   
validatorsinstance_ofr,   re   rU   r]   rB   rG   rK   r   r   r   r   r      s   
 



)r    r!   r"   r#   r$   r%   r&   r   )r    r)   r"   r#   r$   r%   r&   r*   )r.   r/   r"   r#   r$   r%   r&   r   )r.   r3   r"   r#   r$   r%   r&   r*   )!
__future__r   rV   typingr   r   r   r   r   r   r	   r
   r   r   rS   _utilr   r   typing_extensionsr   r   r   __all__r   r   r   r   sABCr   r   r   r   r   r   r   r   <module>   s>    0
	

8-