o
    Ch/!                     @   s  d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
mZmZmZmZmZmZ d dlmZ d dlmZmZmZ z*d dlZejdZeed  d	kpbeed  d	kobeed
 dkZesiedW n eyu   dZY nw zd dlZdZW n ey   dZY nw zd dl Z dZ!W n ey   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,dKd"d#Z-dLd$d%Z.	!	!	dKd&ee/e&f d'e&d(e&d)e&d*ef
d+d,Z0ed-ed.Z1d/gg d!d!fd0e/d1e/d(e&d)e&dee1ge1f f
d2d3Z2d4d5 Z3d6d7 Z4d8e&d9e5de&fd:d;Z6d<e&d=e&defd>d?Z7d@dA Z8				dMdBee dCee dDee dEee dee f
dFdGZ9dNdIdJZ:dS )O    N)Callable)contextmanagerwraps)AnyDictListMappingOptionalTypeVarUnion)	DataError)
AbsExpiryT
EncodableTExpiryT.         z"hiredis package should be >= 3.2.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   ]/var/www/html/myvaluetrips/my_value_trip_new/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   6   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_bytes=   s   r+   c                 C   s   t t| S r   )strr+   r*   r   r   r   safe_strC      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_mergeG   s   r3   c                 C   s   t | |S r   )dictfromkeys)key_listcallbackr   r   r   list_keys_to_dictU   r.   r8   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_resultY   s   	rA    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    () -- Deprecated since version category
stacklevelwarningswarnDeprecationWarning)namereasonversionrH   rJ   msgr   r   r   warn_deprecatedk   s   rQ   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   rH   )rQ   __name__)argsr   )funcrM   rN   rO   r   r   wrapper|   s   z7deprecated_function.<locals>.decorator.<locals>.wrapperr   rU   rV   rM   rN   rO   rU   r   	decorator{   s   z&deprecated_function.<locals>.decoratorr   )rN   rO   rM   rZ   r   rX   r   deprecated_functionv   s   r[   arg_namefunction_namerN   rO   rH   c                 C   sV   dd l }d| d|  d}|r|d| d7 }|r!|d| d7 }|j|t|d	 d S )
Nr   z	Call to 'z6' function with deprecated usage of input argument/s 'z'.rC   rD   rE   r   rF   rI   )r\   r]   rN   rO   rH   rJ   rP   r   r   r   warn_deprecated_arg_usage   s   r^   C)bound*args_to_warnallowed_argsc                    s    dt dt f fdd}|S )z
    Decorator to mark specified args of a function as deprecated.
    If '*' is in args_to_warn, all arguments will be marked as deprecated.
    rU   r#   c                    s    t   fdd}|S )Nc                     s   j jd j j }tt|| }|| |dd   D ]}||d  qD ])}|dkrDt|dkrDtt	|
 jdd q)||v rRt|jdd q)| i |S )Nselfra   r   r   rR   )__code__co_varnamesco_argcountr4   zipr0   poplenr^   r<   keysrS   )rT   r   	arg_namesprovided_argsallowed_argarg)rc   rb   rU   rN   rO   r   r   rV      s*   

z3deprecated_args.<locals>.decorator.<locals>.wrapperr   rW   rc   rb   rN   rO   rY   r   rZ      s   z"deprecated_args.<locals>.decorator)r_   )rb   rc   rN   rO   rZ   r   rp   r   deprecated_args   s   rq   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
loggerDictrk   	getLoggersetLevelINFOStreamHandler
addHandler)loggerhandlerr   r   r   _set_info_logger   s   
r~   c                  C   s,   zt d} W | S  t jy   d} Y | S w )Nredisz99.99.99)r   rO   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   r   zError r   z connecting to z. )rT   rj   )r   r   r   r   r   format_error_message   s   r   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   )r<   mapintsplitrj   rangeappend	enumerate)r   r   num_versions1num_versions2diff_iverr   r   r   compare_versions   s$   	r   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
   


r   expxexatpxatc                 C   s<  g }| d ur>| d t| tjr| t|   |S t| tr(| |  |S t| tr:|  r:| t|  |S td|d urj| d t|tjrZ| t| d  |S t|trf| | |S td|d urt|tjrzt|	 }|
d|g |S |d urt|tjrt|	 d }|
d|g |S )NEXz$ex must be datetime.timedelta or intPXi  z$px must be datetime.timedelta or intEXATPXAT)r   r'   datetime	timedeltar   total_secondsr,   isdigitr   	timestampextend)r   r   r   r   exp_optionsr   r   r   extract_expire_flags  s@   





r   d   c                 C   s   t j| |dddS )Nz...T)textwidthplaceholderbreak_long_words)textwrapshorten)txt
max_lengthr   r   r   truncate_text7  s   r   )rB   rB   r   )rB   rB   N)NNNN)r   );r   rs   r   collections.abcr   
contextlibr   	functoolsr   typingr   r   r   r	   r
   r   r   redis.exceptionsr   redis.typingr   r   r   hiredis__version__r   hiredis_versionr   HIREDIS_AVAILABLEImportErrorsslSSL_AVAILABLEcryptographyCRYPTOGRAPHY_AVAILABLE	importlibr   r   r   r,   r(   r+   r-   r3   r8   rA   rQ   r[   r<   r^   r_   rq   r~   r   BaseExceptionr   r   r   r   r   r   r   r   r   <module>   s    $
"




-

%