o
    }MfO  ã                   @   s„   d Z ddlmZ ddlZddlZddlZddlZe e¡Z	G dd„ deƒZ
G dd„ de dg d¢¡e
ƒZd	d
„ Zdd„ Zdd„ ZdS )z%Utilities for working with callables.é    )ÚABCNc                   @   s(   e Zd ZdZejG dd„ dejƒƒZdS )ÚOutcomea•  A sum type describing the outcome of some call.

    Attributes:
      kind: One of Kind.RETURNED or Kind.RAISED respectively indicating that the
        call returned a value or raised an exception.
      return_value: The value returned by the call. Must be present if kind is
        Kind.RETURNED.
      exception: The exception raised by the call. Must be present if kind is
        Kind.RAISED.
    c                   @   s   e Zd ZdZeƒ Zeƒ ZdS )zOutcome.Kindz8Identifies the general kind of the outcome of some call.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚobjectÚRETURNEDÚRAISED© r   r   úi/var/www/html/analyze/labelStudio/lib/python3.10/site-packages/grpc/framework/foundation/callable_util.pyÚKind%   s    
r   N)r   r   r   r   ÚenumÚuniqueÚEnumr   r   r   r   r   r      s    r   c                   @   s   e Zd ZdZdS )Ú_EasyOutcomez$A trivial implementation of Outcome.N)r   r   r   r   r   r   r   r   r   -   s    r   )ÚkindÚreturn_valueÚ	exceptionc              
   O   s\   zt tjj| |i |¤Žd ƒW S  ty- } zt |¡ t tjjd |ƒW  Y d }~S d }~ww ©N)r   r   r   r	   Ú	ExceptionÚ_LOGGERr   r
   )ÚbehaviorÚmessageÚargsÚkwargsÚer   r   r   Ú_call_logging_exceptions6   s   ÿ
€þr   c                    s   t  ˆ ¡‡ ‡fdd„ƒ}|S )aÍ  Wraps a callable in a try-except that logs any exceptions it raises.

    Args:
      behavior: Any callable.
      message: A string to log if the behavior raises an exception.

    Returns:
      A callable that when executed invokes the given behavior. The returned
        callable takes the same arguments as the given behavior but returns a
        future.Outcome describing whether the given behavior returned a value or
        raised an exception.
    c                     s   t ˆ ˆg| ¢R i |¤ŽS r   ©r   )r   r   ©r   r   r   r   Úwrapped_behaviorN   s   z0with_exceptions_logged.<locals>.wrapped_behavior)Ú	functoolsÚwraps)r   r   r    r   r   r   Úwith_exceptions_logged@   s   r#   c                 O   s   t | |g|¢R i |¤ŽS )a®  Calls a behavior in a try-except that logs any exceptions it raises.

    Args:
      behavior: Any callable.
      message: A string to log if the behavior raises an exception.
      *args: Positional arguments to pass to the given behavior.
      **kwargs: Keyword arguments to pass to the given behavior.

    Returns:
      An Outcome describing whether the given behavior returned a value or raised
        an exception.
    r   )r   r   r   r   r   r   r   Úcall_logging_exceptionsU   s   r$   )r   Úabcr   Úcollectionsr   r!   ÚloggingÚ	getLoggerr   r   r   Ú
namedtupler   r   r#   r$   r   r   r   r   Ú<module>   s"   

ÿü	
