o
    `f                     @   s  d dl Z 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jd ZeedZW n ey?   dZ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 ejd	krtd d
lmZ nd dl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"d*ddZ#d+d d!Z$d"d# Z%d$d% Z&d&ed'e'defd(d)Z(dS ),    N)contextmanagerwraps)AnyDictMappingUnionz0.pack_commandFT)      )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   D/home/ubuntu/webapp/venv/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   1   s   r   valuereturnc                 C   s   t | tr| jdddS | S )Nzutf-8replace)errors)
isinstancebytesdecoder   r   r   r   str_if_bytes8   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_mergeB   s   r)   c                 C   s   t | |S r   )dictfromkeys)key_listcallbackr   r   r   list_keys_to_dictP   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_resultT   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 .z ()z -- Deprecated since version )category
stacklevel)warningswarnDeprecationWarning)namereasonversionr=   r>   msgr   r   r   warn_deprecatedf   s   rE   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=   )rE   __name__)argsr   )funcrA   rB   rC   r   r   wrapperw   s   z7deprecated_function.<locals>.decorator.<locals>.wrapperr   )rH   rI   rA   rB   rC   )rH   r   	decoratorv   s   z&deprecated_function.<locals>.decoratorr   )rB   rC   rA   rK   r   rJ   r   deprecated_functionq   s   rL   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   
rZ   c                  C   s,   zt d} W | S  t jy   d} Y | S w )Nredisz99.99.99)r   rC   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. )rG   len)r_   r`   r   r   r   format_error_message   s   rc   )r8   r8   r9   )r8   r8   N))rN   sys
contextlibr   	functoolsr   typingr   r   r   r   hiredis__version__
startswithHIREDIS_AVAILABLEhasattrHIREDIS_PACK_AVAILABLEImportErrorsslSSL_AVAILABLEcryptographyCRYPTOGRAPHY_AVAILABLEversion_info	importlibr   importlib_metadatar   r   r"   r   r!   r#   r)   r.   r7   rE   rL   rZ   r^   BaseExceptionrc   r   r   r   r   <module>   sR    

"

