o
    fip
                     @  s.   d dl mZ d dlZd dlZG dd dZdS )    )annotationsNc                   @  st   e Zd ZdZdZeffddZdd Zedd Z	ed	d
 Z
edd Zdd Zdd ZedddZdd ZdS )ExceptionTrapa  
    A context manager that will catch certain exceptions and provide an
    indication they occurred.

    >>> with ExceptionTrap() as trap:
    ...     raise Exception()
    >>> bool(trap)
    True

    >>> with ExceptionTrap() as trap:
    ...     pass
    >>> bool(trap)
    False

    >>> with ExceptionTrap(ValueError) as trap:
    ...     raise ValueError("1 + 1 is not 3")
    >>> bool(trap)
    True
    >>> trap.value
    ValueError('1 + 1 is not 3')
    >>> trap.tb
    <traceback object at ...>

    >>> with ExceptionTrap(ValueError) as trap:
    ...     raise Exception()
    Traceback (most recent call last):
    ...
    Exception

    >>> bool(trap)
    False
    )NNNc                 C  s
   || _ d S N)
exceptions)selfr    r   Y/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/importlib_metadata/_context.py__init__,      
zExceptionTrap.__init__c                 C  s   | S r   r   r   r   r   r   	__enter__/   s   zExceptionTrap.__enter__c                 C  
   | j d S Nr   exc_infor   r   r   r   type2      
zExceptionTrap.typec                 C  r   )N   r   r   r   r   r   value6   r   zExceptionTrap.valuec                 C  r   )N   r   r   r   r   r   tb:   r   zExceptionTrap.tbc                 G  s&   |d }|ot || j}|r|| _|S r   )
issubclassr   r   )r   r   r   matchesr   r   r   __exit__>   s
   zExceptionTrap.__exit__c                 C  s
   t | jS r   )boolr   r   r   r   r   __bool__E   r
   zExceptionTrap.__bool___testc                  s   t  fdd}|S )a  
        Wrap func and replace the result with the truth
        value of the trap (True if an exception occurred).

        First, give the decorator an alias to support Python 3.8
        Syntax.

        >>> raises = ExceptionTrap(ValueError).raises

        Now decorate a function that always fails.

        >>> @raises
        ... def fail():
        ...     raise ValueError('failed')
        >>> fail()
        True
        c                    sF   t j}| i | W d     |S 1 sw   Y   |S r   )r   r   )argskwargstrapr   funcr   r   r   wrapper[   s   
z%ExceptionTrap.raises.<locals>.wrapper)	functoolswraps)r   r"   r   r#   r   r!   r   raisesH   s   zExceptionTrap.raisesc                 C  s   | j |tjdS )a  
        Wrap func and replace the result with the truth
        value of the trap (True if no exception).

        First, give the decorator an alias to support Python 3.8
        Syntax.

        >>> passes = ExceptionTrap(ValueError).passes

        Now decorate a function that always fails.

        >>> @passes
        ... def fail():
        ...     raise ValueError('failed')

        >>> fail()
        False
        r   )r&   operatornot_)r   r"   r   r   r   passesc   s   zExceptionTrap.passesN)__name__
__module____qualname____doc__r   	Exceptionr	   r   propertyr   r   r   r   r   r   r&   r)   r   r   r   r   r      s    !


r   )
__future__r   r$   r'   r   r   r   r   r   <module>   s    