o
    &g                     @   s  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	 zd dl
Z
ee
jdd  dkZes3edW n ey?   dZY nw zd dlZd	ZW n eyS   dZY nw zd dlZd	ZW n eyg   dZY nw d d
lmZ dd Zedd Zde	eef defddZdd Zdeeef deeef fddZdd Zdd Zd0ddZd1d d!Z d"d# Z!d$d% Z"d&ed'e#defd(d)Z$d*ed+edefd,d-Z%d.d/ Z&dS )2    N)contextmanagerwraps)AnyDictMappingUnion.   z"hiredis package should be >= 3.0.0FT)metadatac                 K   s   ddl m} |j| fi |S )z
    Returns an active Redis client generated from the given database URL.

    Will attempt to extract the database id from the path url fragment, if
    none is provided.
    r   )Redis)redis.clientr   from_url)urlkwargsr    r   J/root/parts/websockify/install/lib/python3.10/site-packages/redis/utils.pyr   !   s   r   c                 c   s    |   }|V  |  d S N)pipelineexecute)	redis_objpr   r   r   r   -   s   r   valuereturnc                 C   s   t | tr| jdddS | S )Nutf-8replace)errors)
isinstancebytesdecoder   r   r   r   str_if_bytes4   s   r!   c                 C   s   t t| S r   )strr!   r    r   r   r   safe_str:      r#   dictsc                  G   s   i }| D ]}| | q|S )za
    Merge all provided dicts into 1 dict.
    *dicts : `dict`
        dictionaries to merge
    )update)r%   mergeddr   r   r   
dict_merge>   s   r)   c                 C   s   t | |S r   )dictfromkeys)key_listcallbackr   r   r   list_keys_to_dictL   r$   r.   c                 C   s0   t  }| D ]}|D ]}|| qq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   r   r   r   merge_resultP   s   	r7       c                 C   sP   dd l }d|  d}|r|d| d7 }|r|d| d7 }|j|t|d d S )Nr   zCall to deprecated r	   z ()z -- Deprecated since version )category
stacklevel)warningswarnDeprecationWarning)namereasonversionr<   r=   msgr   r   r   warn_deprecatedb   s   rD   c                    s    fdd}|S )z5
    Decorator to mark a function as deprecated.
    c                    s   t   fdd}|S )Nc                     s$   t p jdd  | i |S )Nr
   )r<   )rD   __name__)argsr   )funcr@   rA   rB   r   r   wrappers   s   z7deprecated_function.<locals>.decorator.<locals>.wrapperr   )rG   rH   r@   rA   rB   )rG   r   	decoratorr   s   z&deprecated_function.<locals>.decoratorr   )rA   rB   r@   rJ   r   rI   r   deprecated_functionm   s   rK   c                  C   sN   dt jjj vr%t d} | t j t  }|t j | 	| dS dS )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handlerr   r   r   _set_info_logger}   s   
rY   c                  C   s,   zt d} W | S  t jy   d} Y | S w )Nredisz99.99.99)r   rB   PackageNotFoundError)libverr   r   r   get_lib_version   s   r]   
host_error	exceptionc                 C   s\   |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. )rF   len)r^   r_   r   r   r   format_error_message   s   rb   version1version2c                 C   s   t tt| d}t tt|d}t|t|kr1t|t| }t|D ]}|d q(nt|t|k rMt|t| }t|D ]}|d qEt|D ]\}}|| || kr` dS || || k rk dS qQdS )z
    Compare two versions.

    :return: -1 if version1 > version2
             0 if both versions are equal
             1 if version1 < version2
    r	   r   r`   )r2   mapintsplitra   rangeappend	enumerate)rc   rd   num_versions1num_versions2diff_iverr   r   r   compare_versions   s$   	rr   c                 C   s*   t | tr
| dS t | tr| S td)Nr   z$Key must be either a string or bytes)r   r   r   r"   	TypeError)keyr   r   r   ensure_string   s
   


ru   )r8   r8   r9   )r8   r8   N)'rM   
contextlibr   	functoolsr   typingr   r   r   r   hiredisrg   __version__rh   HIREDIS_AVAILABLEImportErrorsslSSL_AVAILABLEcryptographyCRYPTOGRAPHY_AVAILABLE	importlibr   r   r   r"   r   r!   r#   r)   r.   r7   rD   rK   rY   r]   BaseExceptionrb   rr   ru   r   r   r   r   <module>   sR    
"

