o
    ¨Ýjp
  ã                   @  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   úV/var/www/html/chatgpt/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ÚkwargsZ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    