o
    3Ihj                     @   sx   d dl mZmZmZmZ d dlmZmZmZ d dl	Z	d dl
Zd dlZd dlmZ d dlmZ e	eZG dd dZdS )    )AnyDictOptionalTypeVar)quoteurlparse
urlunparseN)Settingsc                   @   s   e Zd ZU eed< dZeed< dZeed< ede	ddfd	d
Z
e			dde	dee dee	 dee de	f
ddZedeeef dZededefddZedejddfddZdS )BaseHTTPClient	_settings_max_batch_size(   keepalive_secshostreturnNc                 C   sN   t | }d| v r|jdvrtd|j dd| v r#| ds%tdd S d S )N/>   httphttpsz%Invalid URL. Unrecognized protocol - .r   zInvalid URL. Seems that you are trying to pass URL as a host but without                   specifying the protocol. Please add http:// or https:// to the host.)r   scheme
ValueError
startswith)r   parsed r   ]/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/chromadb/api/base_http_client.py_validate_host   s   zBaseHTTPClient._validate_hostF @  chroma_server_hostchroma_server_ssl_enableddefault_api_pathchroma_server_http_portc                 C   s   d}| }t | |drtd d}t|}|rdn|jp!d}|jp)|jp)| }|s5dt	|j
p2| nd}	|jp;|}
|
rB|
|krH|rF|nd}
|
|pMdsW|rU|
| nd}
t|| |	 t|
dd	dddf}|S )
NFr   z/Skipping port as the user is passing a full URLTr   :r   z//r   )r
   r   r   loggerdebugr   r   netlochostnamestrportpathendswithr   r   replace)r   r    r!   r"   
_skip_port_chroma_server_hostr   r   net_locr)   r*   full_urlr   r   r   resolve_url!   s(   



"zBaseHTTPClient.resolve_urlT)boundparamsc                 C   s   dd |   D S )z&Remove None values from provided dict.c                 S   s   i | ]\}}|d ur||qS )Nr   ).0kvr   r   r   
<dictcomp>G   s    z0BaseHTTPClient._clean_params.<locals>.<dictcomp>)items)r4   r   r   r   _clean_paramsD   s   zBaseHTTPClient._clean_paramsrespc                 C   s   z|    W dS  tjy   Y nw d}z)t| j}d|v r<|d tjv r<tj|d  |d }| j	d}|r<||_
W n	 tyF   Y nw |rK|z|    W dS  tjyr   | j	d}|rmt| j d| dt| jw )zKRaises an error if the response is not ok, using a ChromaError if possible.Nerrormessagezchroma-trace-idz (trace ID: ))raise_for_statushttpxHTTPStatusErrorjsonloadstexterrorserror_typesheadersgettrace_idBaseException	Exception)r;   chroma_errorbodyrI   r   r   r   _raise_chroma_errorI   s:   
z"BaseHTTPClient._raise_chroma_error)Fr   r   )__name__
__module____qualname__r	   __annotations__r   intr   staticmethodr(   r   r   boolr1   r   r   r   r2   r:   r@   ResponserN   r   r   r   r   r
      s4   
  r
   )typingr   r   r   r   urllib.parser   r   r   loggingorjsonrB   r@   chromadb.errorsrE   chromadb.configr	   	getLoggerrO   r$   r
   r   r   r   r   <module>   s    
