o
    Þ­j°  ã                   @   s²   d Z ddlZddlZddlmZ ddlZddlmZ ddlmZ G dd„ de 	dd	¡ej
ƒZd
d„ Zdd„ ZddgZejd dkrUejd dkrWddlmZ e d¡ dS dS dS )z;Reference implementation for status mapping in gRPC Python.é    N)Ú
status_pb2é   )ÚGRPC_DETAILS_METADATA_KEY)Úcode_to_grpc_status_codec                   @   s   e Zd ZdS )Ú_StatusN)Ú__name__Ú
__module__Ú__qualname__© r
   r
   úS/var/www/html/CropPilot/venv/lib/python3.10/site-packages/grpc_status/rpc_status.pyr      s    r   ©ÚcodeÚdetailsÚtrailing_metadatac                 C   s”   |   ¡ du rdS |   ¡ D ];\}}|tkrGtj |¡}|  ¡ jd |jkr1tdt|jƒ|  ¡ f ƒ‚|  	¡ |j
krCtd|j
|  	¡ f ƒ‚|  S qdS )a¡  Returns a google.rpc.status.Status message corresponding to a given grpc.Call.

    This is an EXPERIMENTAL API.

    Args:
      call: A grpc.Call instance.

    Returns:
      A google.rpc.status.Status message representing the status of the RPC.

    Raises:
      ValueError: If the gRPC call's code or details are inconsistent with the
        status code and message inside of the google.rpc.status.Status.
    Nr   z8Code in Status proto (%s) doesn't match status code (%s)z>Message in Status proto (%s) doesn't match status details (%s))r   r   r   ÚStatusÚ
FromStringr   ÚvalueÚ
ValueErrorr   r   Úmessage)ÚcallÚkeyr   Úrich_statusr
   r
   r   Ú	from_call!   s(   ÿÿÿÿôr   c                 C   s    t t| jƒ| jt|  ¡ ffd�S )ad  Convert a google.rpc.status.Status message to grpc.Status.

    This is an EXPERIMENTAL API.

    Args:
      status: a google.rpc.status.Status message representing the non-OK status
        to terminate the RPC with and communicate it to the client.

    Returns:
      A grpc.Status instance representing the input google.rpc.status.Status message.
    r   )r   r   r   r   r   ÚSerializeToString)Ústatusr
   r
   r   Ú	to_statusC   s   
ÿýr   é   é   )Ú_asyncÚaio)Ú__doc__ÚcollectionsÚsysÚ
google.rpcr   ÚgrpcÚ_commonr   r   Ú
namedtupler   r   r   r   Ú__all__Úversion_infoÚ r   r   Úappendr
   r
   r
   r   Ú<module>   s(   

þ"þý