o
    :i3                     @   s  d dl Z d dlZd dlmZmZmZ d dlZd dlmZ d dl	m
Z
 G dd dejejejejZG dd dejjejjejjejjZd	ed
efddZd	ed
efddZG dd deddejZG dd deddejjZ	d(deeeef  deg ef dB d
efddZ	d(deeeef  deg ef eg ee f B dB d
efddZd(deeef dB d
eeeef  fddZd(deeef dB d
eeedB f fddZ 				d)ded e!d!e"d"eeeef  dB deeef dB d#ej#dB deg ef dB d
ej$fd$d%Z%				d)ded e!d!e"d"eeeef  dB deeef dB d#ej#dB deg ef eg ee f B dB d
ejj$fd&d'Z&dS )*    N)Any	AwaitableCallable)ResourceExhaustedResponse)show_warning_oncec                   @      e Zd ZdefddZdedededefdd	Zdedededefd
dZdedededefddZdedededefddZ	dS )_GenericClientInterceptorinterceptor_functionc                 C   
   || _ d S N_fnselfr	    r   e/home/aiteam/pcaa-dev/dashboard-backend/venv/lib/python3.10/site-packages/qdrant_client/connection.py__init__      
z"_GenericClientInterceptor.__init__continuationclient_call_detailsrequestreturnc                 C   s:   |  |t|fdd\}}}||t|}|r||S |S NFr   iternext)r   r   r   r   new_detailsnew_request_iteratorpostprocessresponser   r   r   intercept_unary_unary   
   
z/_GenericClientInterceptor.intercept_unary_unaryc                 C   s:   |  |t|fdd\}}}||t|}|r||S |S NFTr   r   r   r   r   r   r   r   response_itr   r   r   intercept_unary_stream   r!   z0_GenericClientInterceptor.intercept_unary_streamrequest_iteratorc                 C   s0   |  ||dd\}}}|||}|r||S |S NTFr   r   r   r   r&   r   r   r   r   r   r   r   intercept_stream_unary(   
   

z0_GenericClientInterceptor.intercept_stream_unaryc                 C   s0   |  ||dd\}}}|||}|r||S |S NTr   r   r   r   r&   r   r   r   r$   r   r   r   intercept_stream_stream1   r*   z1_GenericClientInterceptor.intercept_stream_streamN
__name__
__module____qualname__r   r   r   r    r%   r)   r-   r   r   r   r   r      sL    
	
	
	r   c                   @   r   )_GenericAsyncClientInterceptorr	   c                 C   r
   r   r   r   r   r   r   r   A   r   z'_GenericAsyncClientInterceptor.__init__r   r   r   r   c           	         sR   |  |t|fddI d H \}}}t|}|||I d H }|r'||I d H S |S r   r   )	r   r   r   r   r   r   r   next_requestr   r   r   r   r    D   s   z4_GenericAsyncClientInterceptor.intercept_unary_unaryc                    sN   |  |t|fddI d H \}}}||t|I d H }|r%||I d H S |S r"   r   r#   r   r   r   r%   N   s   z5_GenericAsyncClientInterceptor.intercept_unary_streamr&   c                    sD   |  ||ddI d H \}}}|||I d H }|r ||I d H S |S r'   r   r(   r   r   r   r)   W      z5_GenericAsyncClientInterceptor.intercept_stream_unaryc                    sD   |  ||ddI d H \}}}|||I d H }|r ||I d H S |S r+   r   r,   r   r   r   r-   `   r4   z6_GenericAsyncClientInterceptor.intercept_stream_streamNr.   r   r   r   r   r2   ;   sL    


	
	r2   intercept_callr   c                 C      t | S r   )r   r5   r   r   r   !create_generic_client_interceptorj   s   r8   c                 C   r6   r   )r2   r7   r   r   r   'create_generic_async_client_interceptorn   s   r9   c                   @      e Zd ZdS )_ClientCallDetailsNr/   r0   r1   r   r   r   r   r;   v       r;   )methodtimeoutmetadatacredentialsc                   @   r:   )_ClientAsyncCallDetailsNr<   r   r   r   r   rB   }   r=   rB   new_metadataauth_token_providerc                    sJ   dt dt fdddtdt dt dt dttt t f f
 fd	d
}t|S )Nr   r   c              	   S   s~   |   tjjkr=d }|  D ]}|jdkr*zt|j}W n ty'   d }Y nw  nq| 	 r3| 	 nd}|r=t
||d| S )Nretry-after messageretry_after_s)codegrpc
StatusCodeRESOURCE_EXHAUSTEDtrailing_metadatakeyintvalue	Exceptiondetailsr   )r   retry_afteritemreason_phraser   r   r   process_response   s   
z2header_adder_interceptor.<locals>.process_responser   r&   _request_streaming_response_streamingc                    s   g }| j d urt| j }D ]\}}|||f q r1t s-|dd   f ntdt| j| j|| j	} | |fS )NauthorizationBearer z=Synchronous channel requires synchronous auth token provider.)
r@   listappendasyncioiscoroutinefunction
ValueErrorr;   r>   r?   rA   )r   r&   rX   rY   r@   headerrQ   rD   rC   rW   r   r   r5      s(   



z0header_adder_interceptor.<locals>.intercept_call)r   r;   tupler8   rC   rD   r5   r   rb   r   header_adder_interceptor   s    re   c                    sN   dt dt fdddtjjdt dt dt dttt t f f
 fd	d
}t|S )Ncallr   c                    s   z| I d H W S  t jjyV } zA| t jjkrQd }| D ]}|d dkr=zt|d }W n ty:   d }Y nw  nq|	 rF|	 nd}|rQt
||d| d }~ww )Nr   rE      rF   rG   )rK   aioAioRpcErrorrJ   rL   rM   rN   rP   rR   rS   r   )rf   errT   rU   rV   r   r   r   rW      s2   z8header_adder_async_interceptor.<locals>.process_responser   r&   rX   rY   c                    s   g }| j d urt| j }D ]\}}|||f q r6t r)  I d H }n  }|dd| f | j|d} | |fS )NrZ   r[   )r@   )r@   r\   r]   r^   r_   _replace)r   r&   rX   rY   r@   ra   rQ   tokenrb   r   r   r5      s"   



z6header_adder_async_interceptor.<locals>.intercept_call)r   rK   rh   ClientCallDetailsrc   rB   r9   rd   r   rb   r   header_adder_async_interceptor   s   rn   optionsc                 C   sN   ddg}| d u r
|S dd |   D }|D ]\}}|| vr$|||f q|S )N)zgrpc.max_send_message_length)zgrpc.max_receive_message_lengthrp   c                 S   s   g | ]\}}||fqS r   r   ).0option_nameoption_valuer   r   r   
<listcomp>   s    z)parse_channel_options.<locals>.<listcomp>)itemsr]   )ro   default_options_optionsrr   rs   r   r   r   parse_channel_options   s   rx   c                 C   s   t dddd}| du r|S |D ]2}| |d}d| | v r,td| dd| dd |du r1qt|ts=t| d|||< q|S )	zParse ssl credentials to create `grpc.ssl_channel_credentials` for `grpc.secure_channel`

    WARN: Directly modifies input `options`

    Return:
        dict[str, Optional[bytes]]: dict(root_certificates=..., private_key=..., certificate_chain=...)
    N)root_certificatesprivate_keycertificate_chainzgrpc.`z/` is supposed to be used without `grpc.` prefix
   )idx
stacklevelz must be a byte string)dictpopr   
isinstancebytes	TypeError)ro   ssl_optionsssl_option_namers   r   r   r   parse_ssl_credentials  s&   


r   hostportsslr@   compressionc                 C   s   |d ur|  nd }t|}t|}	t|pg |d}
|r7tjdi |}t|  d| ||	|}t||
S t|  d| |	|}t||
S )NrC   rD   :r   )	copyr   rx   re   rK   ssl_channel_credentialssecure_channelintercept_channelinsecure_channel)r   r   r   r@   ro   r   rD   _copied_options_ssl_cred_optionsrw   metadata_interceptor	ssl_credschannelr   r   r   get_channel$  s   r   c                 C   s   |d ur|  nd }t|}t|}	t|pg |d}
|r5tjdi |}tjj|  d| ||	||
gdS tjj|  d| |	||
gdS )Nr   r   )interceptorsr   )	r   r   rx   rn   rK   r   rh   r   r   )r   r   r   r@   ro   r   rD   r   r   rw   r   r   r   r   r   get_async_channel@  s&   r   r   )NNNN)'r^   collectionstypingr   r   r   rK   &qdrant_client.common.client_exceptionsr   $qdrant_client.common.client_warningsr   UnaryUnaryClientInterceptorUnaryStreamClientInterceptorStreamUnaryClientInterceptorStreamStreamClientInterceptorr   rh   r2   r8   r9   
namedtuplerm   r;   rB   r\   rc   strre   rn   r   rx   r   r   rP   boolCompressionChannelr   r   r   r   r   r   <module>   s    

./




	
8
,6,'
 