o
    Ifba                     @   s   d dl Z d dlZddlmZmZ g d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   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   )Zsync_fnargskwargsexc r   1usr/lib/python3.10/site-packages/outcome/_impl.pyr	   
   s   
r	   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
   )Zasync_fnr   r   r   r   r   r   r      s   
r   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      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.unwrapc                 C   r   )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   r   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    



r   )frozenr   r   c                   @   s:   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      d| j dS )NzValue())valuer   r   r   r   __repr__h      zValue.__repr__c                 C   s   |    | jS N)r   r/   r   r   r   r   r   k   s   zValue.unwrapc                 C      |    || jS r2   )r   r!   r/   r   r   r   r   r!   o      z
Value.sendc                       |    || jI d H S r2   )r   r#   r/   r"   r   r   r   r#   s      zValue.asendN)r$   r%   r&   r'   r(   r)   r/   r0   r   r!   r#   r   r   r   r   r   _   s    r   c                   @   sF   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.

    )	validatorc                 C   r-   )NzError(r.   )errorr   r   r   r   r0      r1   zError.__repr__c                 C   s   |    | j}z|~~ w r2   )r   r8   )r   Zcaptured_errorr   r   r   r      s
   zError.unwrapc                 C   r3   r2   )r   throwr8   )r   itr   r   r   r!      r4   z
Error.sendc                    r5   r2   )r   athrowr8   r"   r   r   r   r#      r6   zError.asendN)r$   r%   r&   r'   r(   r)   Z
validatorsZinstance_ofr   r8   r0   r   r!   r#   r   r   r   r   r   x   s    r   )r*   r(   Z_utilr   r   __all__r	   r   sABCr   r   r   r   r   r   r   <module>   s    8