
    i)                        d dl Z d dlmZ d dlmZ d dlmZmZmZm	Z	 	 d dl
Z
 ee
j                  j                  d      d          dk\  Z	 d dlZdZ	 d dlZdZd d	lmZ d
 Zed        Zde	eef   defdZd Zdeeef   deeef   fdZd Zd ZddZddZ d Z!d Z"dede#defdZ$y# e$ r dZY iw xY w# e$ r dZY ow xY w# e$ r dZY uw xY w)    N)contextmanagerwraps)AnyDictMappingUnion.   FT)metadatac                 4    ddl m}  |j                  | fi |S )z
    Returns an active Valkey client generated from the given database URL.

    Will attempt to extract the database id from the path url fragment, if
    none is provided.
    r   )Valkey)valkey.clientr   from_url)urlkwargsr   s      ?/root/searxng-venv/lib/python3.12/site-packages/valkey/utils.pyr   r      s     %6??3)&))    c              #   T   K   | j                         }| |j                          y wN)pipelineexecute)
valkey_objps     r   r   r   +   s"     A
GIIKs   &(valuereturnc                 L    t        | t              r| j                  dd      S | S )Nzutf-8replace)errors)
isinstancebytesdecoder   s    r   str_if_bytesr$   2   s(    3=eU3KWY/QVr   c                 *    t        t        |             S r   )strr$   r#   s    r   safe_strr'   8   s    |E"##r   dictsc                  :    i }| D ]  }|j                  |        |S )za
    Merge all provided dicts into 1 dict.
    *dicts : `dict`
        dictionaries to merge
    )update)r(   mergedds      r   
dict_merger-   <   s+     F a Mr   c                 .    t         j                  | |      S r   )dictfromkeys)key_listcallbacks     r   list_keys_to_dictr3   J   s    ==8,,r   c                     t               }|j                         D ]  }|D ]  }|j                  |         t        |      S )z
    Merge all items in `res` into a list.

    This command is used when sending a command to multiple nodes
    and the result from each node should be merged into a single list.

    res : 'dict'
    )setvaluesaddlist)commandresresultvr   s        r   merge_resultr=   N   sG     UFZZ\  	EJJu	 <r   c                 t    dd l }d|  d}|r	|d| dz  }|r	|d| dz  }|j                  |t        |       y )Nr   zCall to deprecated r
   z ()z -- Deprecated since version )category
stacklevel)warningswarnDeprecationWarning)namereasonversionrA   rB   msgs         r   warn_deprecatedrI   `   sR    vQ
'CF81~.wiq99MM# 2zMJr   c                       fd}|S )z5
    Decorator to mark a function as deprecated.
    c                 6     t                fd       }|S )Nc                  N    t        xs j                  d        | i |S )N   )rA   )rI   __name__)argsr   funcrE   rF   rG   s     r   wrapperz7deprecated_function.<locals>.decorator.<locals>.wrapperq   s*    D1DMM67qQ(((r   r   )rP   rQ   rE   rF   rG   s   ` r   	decoratorz&deprecated_function.<locals>.decoratorp   s     	t	) 
	) r    )rF   rG   rE   rR   s   ``` r   deprecated_functionrT   k   s    
 r   c                  ^   dt         j                  j                  j                  j	                         vryt        j
                  d      } | j                  t         j                         t        j                         }|j                  t         j                         | j                  |       yy)zo
    Set up a logger that log info logs to stdout.
    (This is used by the default push response handler)
    push_responseN)
loggingrootmanager
loggerDictkeys	getLoggersetLevelINFOStreamHandler
addHandler)loggerhandlers     r   _set_info_loggerrc   {   sy    
 gll22==BBDD""?3%'')&'" Er   c                  j    	 t        j                  d      } | S # t         j                  $ r d} Y | S w xY w)Nvalkeyz99.99.99)r   rG   PackageNotFoundError)libvers    r   get_lib_versionrh      s?    !!(+ M (( Ms    22
host_error	exceptionc                     |j                   sd|  dS t        |j                         dk(  rd|j                   d    d|  dS d|j                   d    d|  d|j                   d    dS )NzError connecting to r
      zError r   z connecting to z. )rO   len)ri   rj   s     r   format_error_messagern      s~    >>%j\33	Y^^		!	q)*/*QGG Y^^A&'zl"~~a !$	
r   ) ro      )ro   ro   N)%rW   
contextlibr   	functoolsr   typingr   r   r   r	   	libvalkeyint__version__splitLIBVALKEY_AVAILABLEImportErrorsslSSL_AVAILABLEcryptographyCRYPTOGRAPHY_AVAILABLE	importlibr   r   r   r&   r!   r$   r'   r-   r3   r=   rI   rT   rc   rh   BaseExceptionrn   rS   r   r   <module>r      s>    %  , ,  i3399#>qABaGM#! 	*  c5j) c $wsCx( T#s(^ -$K 
#	
S 	
] 	
s 	
K      M  #"#s5   +B) 
B6 C )B32B36C ?C CC