o
    wi                     @   sP   d dl Z d dlmZ d dlZd dlmZmZ dd Zdd Z	dd	 Z
d
d ZdS )    N)
quote_plus)InferenceServerExceptionraise_errorc              
   C   s   | j dkrGd}z |  d}t|rt|nddi}t|d t| j dW S  tyF } ztd| t| j |dW  Y d}~S d}~ww dS )	z
    Returns the :py:class:`InferenceServerException` object if response
    indicates the error. If no error then return None
       Nzutf-8errorz2client received an empty response from the server.)msgstatuszAan exception occurred in the client while decoding the response: )r   r   debug_details)	status_codereaddecodelenjsonloadsr   str	Exception)responsebodyerror_responsee r   U/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/tritonclient/http/_utils.py
_get_error#   s(   
r   c                 C   s   t | }|dur
|dS )zi
    Raise :py:class:`InferenceServerException` if received non-Success
    response from the server
    N)r   )r   r   r   r   r   _raise_if_error>   s   r   c              	   C   sz   g }|   D ]-\}}t|tr$|D ]}|dt|tt|f  qq|dt|tt|f  q|r;d|S dS )Nz%s=%s& )items
isinstancelistappendr   r   join)query_paramsparamskeyvalueitemr   r   r   _get_query_stringH   s   
  
r&   c	                 C   s\  i }	i }
|dkr||	d< |dkr |dkr ||
d< ||
d< ||
d< |dkr(||
d< |d ur0||
d< d	d
 | D |	d< |rEdd
 |D |	d< nd|
d< |ru|  D ]%\}}|dksg|dksg|dksg|dksg|dkrptd| d qO||
|< qO|
r{|
|	d< t|	}t|}| g}| D ]}| }|d ur|| qt|dkr|d d fS d||fS )Nr   idr   sequence_idsequence_startsequence_endprioritytimeoutc                 S      g | ]}|  qS r   _get_tensor).0
this_inputr   r   r   
<listcomp>m   s    z*_get_inference_request.<locals>.<listcomp>inputsc                 S   r-   r   r.   )r0   this_outputr   r   r   r2   o   s    outputsTbinary_data_outputzParameter "z2" is a reserved parameter and cannot be specified.
parameters       )	r   r   r   dumpsr   encode_get_binary_datar   r    )r3   
request_idr5   r(   r)   r*   r+   r,   custom_parametersinfer_requestr7   r#   r$   request_json	json_sizerequest_bodyinput_tensorraw_datar   r   r   _get_inference_requestU   sT   




rE   )structurllib.parser   	rapidjsonr   tritonclient.utilsr   r   r   r   r&   rE   r   r   r   r   <module>   s   
