U
    ~fh                     @  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rzd dlmZmZ edZndd	 Zd
dddddgZedddZedZedddd
dddZedddddddZdddddddZedddd
dddZed ddddd!dZd ddd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 ))    )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   1/tmp/pip-unpacked-wheel-58dcm9s0/outcome/_impl.pyr      s    r   ErrorOutcomeMaybeValueacapturecaptureValueTT)	covariantResultTzCallable[ArgsT, NoReturn]z
ArgsT.argszArgsT.kwargs)sync_fnargskwargsreturnc                 O  s   d S r   r   r    r!   r"   r   r   r   r   $   s    zCallable[ArgsT, ResultT]zValue[ResultT] | Errorc                 O  s   d S r   r   r$   r   r   r   r   .   s    c              
   O  sN   zt | ||W S  tk
rH } zt|d}t| W Y S d}~X Y nX dS )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
    
z$Callable[ArgsT, Awaitable[NoReturn]])async_fnr!   r"   r#   c                   s   d S r   r   r(   r!   r"   r   r   r   r   I   s    z#Callable[ArgsT, Awaitable[ResultT]]c                   s   d S r   r   r)   r   r   r   r   R   s    c              
     sT   zt | ||I dH W S  tk
rN } zt|d}t| W Y S d}~X Y nX dS )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                   @  sx   e Zd ZU dZejddddZded< dddd	Ze	j
d
dddZe	j
dddddZe	j
dd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eqr+   bool
_unwrappedNoner#   c                 C  s   | j r
tt| dd d S )Nr0   T)r0   r   object__setattr__selfr   r   r   _set_unwrapped   s    zOutcome._set_unwrappedr   c                 C  s   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   r5   r   r   r   unwrap   s    zOutcome.unwrap"Generator[ResultT, ValueT, object]r   genr#   c                 C  s   dS )zSend or throw the contained value or exception into the given
        generator object.

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

        Nr   r6   r;   r   r   r   send   s    zOutcome.sendAsyncGenerator[ResultT, ValueT]agenr#   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   r6   r@   r   r   r   asend   s    zOutcome.asendN)__name__
__module____qualname____doc__attribr0   __annotations__r7   abcabstractmethodr8   r=   rB   r   r   r   r   r   m   s   


)frozenr*   r,   c                   @  s^   e Zd ZU dZe Zded< ddddZdddd	Z	d
ddddZ
dddddZdS )r   zFConcrete :class:`Outcome` subclass representing a regular value.

    r   valuestrr2   c                 C  s   d| j dS )NzValue())rM   r5   r   r   r   __repr__   s    zValue.__repr__c                 C  s   |    | jS r   )r7   rM   r5   r   r   r   r8      s    zValue.unwrapr9   r   r:   c                 C  s   |    || jS r   )r7   r=   rM   r<   r   r   r   r=      s    z
Value.sendr>   r?   c                   s   |    || jI d H S r   )r7   rB   rM   rA   r   r   r   rB      s    zValue.asendN)rC   rD   rE   rF   rG   rH   rM   rI   rP   r8   r=   rB   r   r   r   r   r      s   
c                   @  sj   e Zd ZU dZejejedZ	de
d< ddddZd	dd
dZdddddZdddddZdS )r   zIConcrete :class:`Outcome` subclass representing a raised exception.

    )Z	validatorr&   errorrN   r2   c                 C  s   d| j dS )NzError(rO   )rQ   r5   r   r   r   rP      s    zError.__repr__r	   c                 C  s"   |    | j}z|W 5 ~~ X d S r   )r7   rQ   )r6   Zcaptured_errorr   r   r   r8      s
    zError.unwrapz$Generator[ResultT, NoReturn, object]r   r:   c                 C  s   |    || jS r   )r7   throwrQ   r<   r   r   r   r=      s    z
Error.sendz!AsyncGenerator[ResultT, NoReturn]r?   c                   s   |    || jI d H S r   )r7   athrowrQ   rA   r   r   r   rB      s    zError.asendN)rC   rD   rE   rF   rG   rH   Z
validatorsZinstance_ofr&   rQ   rI   rP   r8   r=   rB   r   r   r   r   r      s   

)!
__future__r   rJ   typingr   r   r   r   r   r   r	   r
   r   r   rG   Z_utilr   r   Ztyping_extensionsr   r   r   __all__r   r   r   r   sABCr   r   r   r   r   r   r   r   <module>   s<   0
	8-