U
    ڲg                     @   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rejd dkrddlmZ ed 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
   :/tmp/pip-unpacked-wheel-1epo4o9_/grpc_status/rpc_status.pyr      s   r   codedetailstrailing_metadatac                 C   s   |   dkrdS |   D ]v\}}|tkrtj|}|  jd |jkrbtdt|j|  f | 	 |j
krt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   StatusZ
FromStringr   value
ValueErrorr   r   message)callkeyr   Z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   ZSerializeToString)statusr
   r
   r   	to_statusC   s    
r         )_asyncaio)__doc__collectionssysZ
google.rpcr   ZgrpcZ_commonr   r   
namedtupler   r   r   r   __all__version_info r   r   appendr
   r
   r
   r   <module>   s$   

"