
    ei                         d dl mZ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mZmZ  e
j(                  e      Z G d de      Zy)    )AnyDictMappingOptionalTypeVar)quoteurlparse
urlunparseN)	ComponentSettingsSystemc                   x    e Zd ZU eed<   dZeed<   dZeed<   de	f fdZ
dej                  fd	Zedej                  fd
       Zededdfd       Ze	 	 	 ddedee   dee   dee   def
d       Z edeeef         Zededefd       Zedej6                  ddfd       Zdeeef   fdZdefdZ xZ S )BaseHTTPClient	_settingsNpre_flight_checksg      D@DEFAULT_KEEPALIVE_SECSsystemc                     t         |   |       |j                  | _        | j                  j                  }||nt
        j                  | _        | j                         | _	        y N)
super__init__settingsr   chroma_http_keepalive_secsr   r   keepalive_secs_build_limits_http_limits)selfr   keepalive_setting	__class__s      g/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/chromadb/api/base_http_client.pyr   zBaseHTTPClient.__init__   s\      NNEE !, 66 	
 !..0    returnc                     i }| j                   | j                   |d<   | j                  j                  }|||d<   | j                  j                  }|||d<   t	        j
                  di |S )Nkeepalive_expirymax_connectionsmax_keepalive_connections )r   r   chroma_http_max_connections%chroma_http_max_keepalive_connectionshttpxLimits)r   limit_kwargsr%   r&   s       r    r   zBaseHTTPClient._build_limits   sw    ')*/3/B/BL+,..DD&.=L*+$(NN$X$X!$08QL45||+l++r!   c                     | j                   S r   )r   r   s    r    http_limitszBaseHTTPClient.http_limits.   s       r!   hostc                     t        |       }d| v r'|j                  dvrt        d|j                   d      d| v r| j                  d      st        d      y y )N/>   httphttpsz%Invalid URL. Unrecognized protocol - .r3   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)r0   parseds     r    _validate_hostzBaseHTTPClient._validate_host2   sh    $$;6==0AA:6==/K  $; 7>  !8;r!   chroma_server_hostchroma_server_ssl_enableddefault_api_pathchroma_server_http_portc           
         d}| }t         j                  |       |j                  d      rt        j	                  d       d}t        |      }|rdn|j                  xs d}|j                  xs |j                  xs | }|sdt        |j                  xs |      z   nd}	|j                  xs |}
|
r|
|k(  r|r|nd}
|
j                  |xs d      s	|r|
|z   nd}
t        || |	 t        |
j                  dd	            dddf      }|S )
NFr3   z/Skipping port as the user is passing a full URLTr4   : z//r2   )r   r:   r8   loggerdebugr	   r6   netlochostnamestrportpathendswithr
   r   replace)r;   r<   r=   r>   
_skip_port_chroma_server_hostr9   r6   net_locrG   rH   full_urls               r    resolve_urlzBaseHTTPClient.resolve_urlA   s    
0%%&9:))&1LLJKJ-.56==;RF--H6??H6HEOC#fkk<%<==UW 	 {{..tw'7#RD}}-34.>4**BDy't||D#/F)GRQST
 r!   T)boundparamsc                 \    | j                         D ci c]  \  }}|	|| c}}S c c}}w )z&Remove None values from provided dict.)items)rR   kvs      r    _clean_paramszBaseHTTPClient._clean_paramsd   s*     "(AA1=1AAAs   
((respc                 f   	 | j                          y# t        j                  $ r Y nw xY wd}	 t        j                  | j
                        }d|v rW|d   t        j                  v rBt        j                  |d      |d         }| j                  j                  d      }|r||_
        n# t        $ r Y nw xY w|r|	 | j                          y# t        j                  $ rN | j                  j                  d      }|rt        | j
                   d| d      t        | j
                        w xY 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_statusr*   HTTPStatusErrorjsonloadstexterrorserror_typesheadersgettrace_idBaseException	Exception)rX   chroma_errorbodyrf   s       r    _raise_chroma_errorz"BaseHTTPClient._raise_chroma_errori   s(   	!!#$$ 		 	::dii(D$=F$6$66#)#5#5d7m#DT)_#UL#||//0ABH08- 		 	)!!#$$ 	)||''(9:H499+\(1 EFFTYY'(		)s+    ))A:B* *	B65B6>C A!D0c                     i S )z&Return headers used for HTTP requests.r'   r.   s    r    get_request_headersz"BaseHTTPClient.get_request_headers   s    	r!   c                      y)z#Return the API URL for this client.rA   r'   r.   s    r    get_api_urlzBaseHTTPClient.get_api_url   s    r!   )FrA   i@  )!__name__
__module____qualname__r   __annotations__r   r   r   floatr   r   r*   r+   r   propertyr/   staticmethodrF   r:   r   boolintrO   r   r   rP   rW   Responserk   r   rm   ro   __classcell__)r   s   @r    r   r      sX   !s!$(E(	1v 	1,u|| , !U\\ ! ! S T    5:*,15	#+D> #3- "*#	
 
 @ 	4S>*ABa BA B B )%.. )T ) )BWS#X%6 S r!   r   )typingr   r   r   r   r   urllib.parser   r	   r
   loggingorjsonr_   r*   chromadb.errorsrb   chromadb.configr   r   r   	getLoggerrp   rB   r   r'   r!   r    <module>r      sC    8 8 4 4      7 7			8	$
BY Br!   