U
    ,hba                     @   s   d dl Z d dlZddlmZmZ dddddgZd	d Zd
d ZejddddG dd de j	Z
ejddddG dd de
ZejddddG dd de
ZdS )    N   )AlreadyUsedErrorremove_tb_framesErrorOutcomeValueacapturecapturec              
   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   )Zsync_fnargskwargsexc r   1/tmp/pip-unpacked-wheel-jbq3wtfl/outcome/_impl.pyr	   
   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
   )Zasync_fnr   r   r   r   r   r   r      s
    
FT)reprinitslotsc                   @   sR   e Zd ZdZejddddZdd Zej	dd Z
ej	dd	 Zej	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   c                 C   s   | j r
tt| dd d S )N
_unwrappedT)r   r   object__setattr__selfr   r   r   _set_unwrapped8   s    zOutcome._set_unwrappedc                 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   r   r   r   r   unwrap=   s    zOutcome.unwrapc                 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   r   genr   r   r   sendH   s    zOutcome.sendc                    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   Zagenr   r   r   asendS   s    zOutcome.asendN)__name__
__module____qualname____doc__attribr   r   abcabstractmethodr   r   r!   r   r   r   r   r   &   s   



)frozenr   r   c                   @   s8   e Zd ZdZe Zdd Zdd Zdd Z	dd	 Z
d
S )r   zFConcrete :class:`Outcome` subclass representing a regular value.

    c                 C   s   d| j dS )NzValue())valuer   r   r   r   __repr__h   s    zValue.__repr__c                 C   s   |    | jS N)r   r,   r   r   r   r   r   k   s    zValue.unwrapc                 C   s   |    || jS r.   )r   r   r,   r   r   r   r   r   o   s    z
Value.sendc                    s   |    || jI d H S r.   )r   r!   r,   r    r   r   r   r!   s   s    zValue.asendN)r"   r#   r$   r%   r&   r'   r,   r-   r   r   r!   r   r   r   r   r   _   s   c                   @   sD   e Zd ZdZejejedZ	dd Z
dd Zdd Zd	d
 ZdS )r   zIConcrete :class:`Outcome` subclass representing a raised exception.

    )Z	validatorc                 C   s   d| j dS )NzError(r+   )errorr   r   r   r   r-      s    zError.__repr__c                 C   s"   |    | j}z|W 5 ~~ X d S r.   )r   r/   )r   Zcaptured_errorr   r   r   r      s
    zError.unwrapc                 C   s   |    || jS r.   )r   throwr/   )r   itr   r   r   r      s    z
Error.sendc                    s   |    || jI d H S r.   )r   athrowr/   r    r   r   r   r!      s    zError.asendN)r"   r#   r$   r%   r&   r'   Z
validatorsZinstance_ofr   r/   r-   r   r   r!   r   r   r   r   r   x   s   )r(   r&   Z_utilr   r   __all__r	   r   sABCr   r   r   r   r   r   r   <module>   s   8