o
    e×  ã                   @   s@   d dl Z d dlmZ d dlT dd„ Zdd„ Zdd	„ Zd
d„ ZdS )é    N)Úservice_pb2)Ú*c                 C   s   t |  ¡ t|  ¡ ƒ|  ¡ dS )zÃConvert a gRPC error to an InferenceServerException.

    Parameters
    ----------
    rpc_error : grpc.RpcError
        The gRPC error

    Returns
    -------
    InferenceServerException
    )ÚmsgÚstatusZdebug_details)ZInferenceServerExceptionÚdetailsÚstrÚcodeZdebug_error_string©Z	rpc_error© r
   úHD:\Projects\ConvertPro\env\Lib\site-packages\tritonclient/grpc/_utils.pyÚget_error_grpc"   s
   
ýr   c                 C   s
   t | ƒd‚)zÂRaise an InferenceServerException from a gRPC error.

    Parameters
    ----------
    rpc_error : grpc.RpcError
        The gRPC error

    Raises
    -------
    InferenceServerException
    N)r   r	   r
   r
   r   Úraise_error_grpc5   s   
r   c                 C   sª  t  ¡ }| |_||_|dkr||_|D ]}|j | ¡ g¡ | ¡ d ur-|j	 | ¡ g¡ q|d ur@|D ]}|j
 | ¡ g¡ q4|dkrf|dkrft|tƒrT||jd _n||jd _||jd _||jd _|dkrp||jd _|	d urz|	|jd _|
rÓ|
 ¡ D ]R\}}|dks˜|dks˜|dks˜|dks˜|dkr¡td	|› d
ƒ q€t|tƒr­||j| _q€t|tƒr¹||j| _q€t|tƒrÅ||j| _q€tdt|ƒ› d|› dƒ q€|S )NÚ r   Úsequence_idÚsequence_startÚsequence_endÚpriorityÚtimeoutZbinary_data_outputzParameter "z2" is a reserved parameter and cannot be specified.zThe parameter datatype "z" for key "z" is not supported.)r   ZModelInferRequestÚ
model_nameÚmodel_versionÚidÚinputsÚextendZ_get_tensorZ_get_contentZraw_input_contentsÚoutputsÚ
isinstancer   Ú
parametersZstring_paramZint64_paramZ
bool_paramZuint64_paramÚitemsZraise_errorÚboolÚintÚtype)r   r   r   Z
request_idr   r   r   r   r   r   r   ÚrequestZinfer_inputZinfer_outputÚkeyÚvaluer
   r
   r   Ú_get_inference_requestD   sV   €

ÿ


ÿr#   c                 C   sH   | d u rt jjS |  ¡ dkrt jjS |  ¡ dkrt jjS tdƒ t jjS )NÚdeflateÚgzipzWThe provided client-side compression algorithm is not supported... using no compression)ÚgrpcZCompressionZNoCompressionÚlowerZDeflateZGzipÚprint)Zalgorithm_strr
   r
   r   Ú_grpc_compression_type„   s   ÿr)   )r&   Ztritonclient.grpcr   Ztritonclient.utilsr   r   r#   r)   r
   r
   r
   r   Ú<module>   s   @