o
    ˷eO                     @   s   d Z ddlZddl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
ej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.    Nc                   @   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
   ^/var/www/ideatree/venv/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_exceptions5   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_behaviorL   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_exceptionsS   s   r#   )r   abccollectionsr   r    loggingsix	getLoggerr   r   with_metaclassABCMetar   
namedtupler   r   r"   r#   r
   r
   r
   r   <module>   s$   

	