o
    1Xxi                     @   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< 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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/biblejyuku/back/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>F   s    z0BaseHTTPClient._clean_params.<locals>.<dictcomp>)items)r2   r   r   r   _clean_paramsC   s   zBaseHTTPClient._clean_paramsrespc                 C   s   z|    W dS  tjy   Y nw d}zt| j}d|v r1|d tjv r1tj|d  |d }W n	 ty;   Y nw |r@|z|    W dS  tjyT   t	| jw )zKRaises an error if the response is not ok, using a ChromaError if possible.Nerrormessage)
raise_for_statushttpxHTTPStatusErrorjsonloadstexterrorserror_typesBaseException	Exception)r9   chroma_errorbodyr   r   r   _raise_chroma_errorH   s.   
z"BaseHTTPClient._raise_chroma_error)Fr   r   )__name__
__module____qualname__r	   __annotations__r   intstaticmethodr&   r   r   boolr/   r   r   r   r0   r8   r=   ResponserH   r   r   r   r   r
      s2   
  r
   )typingr   r   r   r   urllib.parser   r   r   loggingorjsonr?   r=   chromadb.errorsrB   chromadb.configr	   	getLoggerrI   r"   r
   r   r   r   r   <module>   s    
