o
    Lj:<                     @   s  d dl Z d dlZ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mZ d dlmZ d dlmZmZmZ erRd dlmZ z*d dlZejd	Ze ed  d
kpte ed  d
kote ed dkZ!e!s{e"d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 zd dl%Z%dZ&W n e"y   dZ&Y nw d dl'm(Z( e) Z*de+deddfddZ,edd Z-dee+e.f de+fddZ/dd Z0dfddZ1d ee+ef dee+ef fd!d"Z2d#d$ Z3d%d& Z4dgd(d)Z5dhd*d+Z6	'	'	dgd,ee7e+f d-e+d.e+d/e+d0e f
d1d2Z8ed3ed4Z9	did5ed6e:de;d7eee+  de;f
d8d9Z<			'	'djd:eee+  d7eee+  d.e+d/e+dee9ge9f f
d;d<Z=d=d> Z>d
Z?	
dkd?e+e B e)B dB d@e de@fdAdBZAdCdD ZBdEe+dFeCde+fdGdHZDdIe+dJe+de fdKdLZEdMdN ZF				dldOee dPee dQee dRee dee f
dSdTZGdmdVdWZHdXdY ZIdZd[ ZJd\d] ZKdnd^d_ZLdee9ge9f fd`daZM	dnd,ee7e+f d-e+d0e fdbdcZN	did:eee+  dee9ge9f fdddeZOdS )o    N)Callable)contextmanager)wraps)TYPE_CHECKINGAnyDictListMappingOptionalTypeVarUnion)	DataError)
AbsExpiryT
EncodableTExpiryTRedis.         z"hiredis package should be >= 3.2.0FT)metadataurlkwargsreturnr   c                 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   r   )redis.clientr   from_url)r   r   r    r   I/home/djax/ivt_ai_plugin/venv/lib/python3.10/site-packages/redis/utils.pyr   4   s   r   c                 c   s    |   }|V  |  d S N)pipelineexecute)	redis_objpr   r   r   r    @   s   r    valuec                 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_bytesG   s   r,   c                 C   s   t t| S r   )strr,   r+   r   r   r   safe_strM      r.   c                 C   sJ   t | ts| S |r!|dur!||v r!|| }|du r| S | |dS t| S )a  Decode a field value respecting optional per-field encoding overrides.

    - If *field_encodings* is provided and *key* is in it, the corresponding
      encoding is used (``None`` means keep raw bytes).
    - Otherwise falls back to :func:`str_if_bytes`.
    Nr&   )r(   r)   r*   r,   )r$   keyfield_encodingsencodingr   r   r   decode_field_valueQ   s   
r3   dictsc                  G   s   i }| D ]}| | q|S )za
    Merge all provided dicts into 1 dict.
    *dicts : `dict`
        dictionaries to merge
    )update)r4   mergeddr   r   r   
dict_mergeb   s   r8   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   	rF    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versionrM   rO   msgr   r   r   warn_deprecated   s   rV   c                    s    fdd}|S )z5
    Decorator to mark a function as deprecated.
    c                    sF   t  rt  fdd}|S t  fdd}|S )Nc                     s,   t p jdd  | i |I d H S Nr   rM   rV   __name__argsr   funcrR   rS   rT   r   r   async_wrapper   s   z=deprecated_function.<locals>.decorator.<locals>.async_wrapperc                     s$   t p jdd  | i |S rW   rY   r[   r]   r   r   wrapper   s   z7deprecated_function.<locals>.decorator.<locals>.wrapperinspectiscoroutinefunctionr   r^   r_   r`   rR   rS   rT   r^   r   	decorator   s   
z&deprecated_function.<locals>.decoratorr   )rS   rT   rR   rg   r   re   r   deprecated_function   s   rh   arg_namefunction_namerS   rT   rM   c                 C   sV   dd l }d| d|  d}|r|d| d7 }|r!|d| d7 }|j|t|d	 d S )
Nr   	Call to 'z6' function with deprecated usage of input argument/s ''.rH   rI   rJ   r   rK   rN   )ri   rj   rS   rT   rM   rO   rU   r   r   r   warn_deprecated_arg_usage   s   rm   C)boundr^   r\   allowed_argsc                 C   sV   | j jd| j j }tt||}|| |dd |r)|D ]}||d q |S )z
    Extract arguments from function call that should be checked for deprecation/experimental warnings.
    Excludes 'self' and any explicitly allowed args.
    Nself)__code__co_varnamesco_argcountr9   zipr5   pop)r^   r\   r   rp   	arg_namesfilterable_argsallowed_argr   r   r   _get_filterable_args   s   
rz   args_to_warnc                    sF   du rdgdu rg fdd 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.
    N*c                    s\    D ])}|dkrt |dkrtt| | jdd q||v r+t|| jdd qdS )z*Check and warn about deprecated arguments.r|   r      rX   N)lenrm   rA   keysrZ   r^   rx   arg)r{   rS   rT   r   r   _check_deprecated_args   s   
z/deprecated_args.<locals>._check_deprecated_argsr^   r   c                    sB   t  rt  fdd}|S t  fdd}|S )Nc                     s.   t | |} | | i |I d H S r   rz   r\   r   rx   r   rp   r^   r   r   r_      s   
z9deprecated_args.<locals>.decorator.<locals>.async_wrapperc                     s&   t | |} | | i |S r   r   r   r   r   r   r`      s   
z3deprecated_args.<locals>.decorator.<locals>.wrapperra   rd   )r   rp   rf   r   rg      s   
z"deprecated_args.<locals>.decoratorrn   )r{   rp   rS   rT   rg   r   )r   rp   r{   rS   rT   r   deprecated_args   s   
r   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
loggerDictr   	getLoggersetLevelINFOStreamHandler
addHandler)loggerhandlerr   r   r   _set_info_logger	  s   
r   protocolexpected_versionc                 C   sN   | d u s| t u r
t} t| tr#z	t| } W | |kS  ty"   Y dS w | |kS )NF)SENTINELDEFAULT_RESP_VERSIONr(   r-   int
ValueError)r   r   r   r   r   check_protocol_version  s   

r   c                  C   s,   zt d} W | S  t jy   d} Y | S w )Nredisz99.99.99)r   rT   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. )r\   r~   )r   r   r   r   r   format_error_message3  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   )rA   mapr   splitr~   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)r0   r   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_flagsf  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_text  s   r   c                   C   s   dS )zT
    Fake function for a Retry object if you don't need to handle each failure.
    Nr   r   r   r   r   
dummy_fail  s   r   c                      s   dS )zZ
    Async fake function for a Retry object if you don't need to handle each failure.
    Nr   r   r   r   r   dummy_fail_async  s   r   c                    s&    j t fdd}| _  S )z4
    Decorator to mark a class as experimental.
    c                    s2   t j j dtdd | g|R i | d S )NzD is an experimental and may change or be removed in future versions.r   rK   )rO   rP   rZ   UserWarning)rq   r\   r   clsoriginal_initr   r   new_init  s   
zexperimental.<locals>.new_init)__init__r   )r   r   r   r   r   experimental  s
   r   c                 C   s(   dd l }d|  d}|j|t|d d S )Nr   zCall to experimental method zS. Be aware that the function arguments can change or be removed in future versions.rK   rO   rP   r   )rR   rM   rO   rU   r   r   r   warn_experimental  s   
r   c                  C   s   dt dt fdd} | S )z7
    Decorator to mark a function as experimental.
    r^   r   c                    s:   t  rt  fdd}|S t  fdd}|S )Nc                     s$   t  jdd  | i |I d H S Nr   rX   r   rZ   r[   rf   r   r   r_     s   z=experimental_method.<locals>.decorator.<locals>.async_wrapperc                     s   t  jdd  | i |S r   r   r[   rf   r   r   r`     s   z7experimental_method.<locals>.decorator.<locals>.wrapperra   rd   r   rf   r   rg     s   
z&experimental_method.<locals>.decoratorr   )rg   r   r   r   experimental_method  s   r   c                 C   s.   dd l }d| d|  d}|j|t|d d S )Nr   rk   z6' method with experimental usage of input argument/s 'rl   rK   r   )ri   rj   rM   rO   rU   r   r   r   warn_experimental_arg_usage  s   r   c                    s4   du rdgfdd dt dt f fdd}|S )	z
    Decorator to mark specified args of a function as experimental.
    If '*' is in args_to_warn, all arguments will be marked as experimental.
    Nr|   c                    sT    D ]%}|dkrt |dkrtt| | jdd q||v r't|| jdd qdS )z,Check and warn about experimental arguments.r|   r      rX   N)r~   r   rA   r   rZ   r   )r{   r   r   _check_experimental_args  s   z3experimental_args.<locals>._check_experimental_argsr^   r   c                    s>   t  rt  fdd}|S t  fdd}|S )Nc                     s8   t | |}t|dkr | | i |I d H S Nr   rz   r~   r   r   r^   r   r   r_     s
   
z;experimental_args.<locals>.decorator.<locals>.async_wrapperc                     s0   t | |}t|dkr | | i |S r   r   r   r   r   r   r`     s   
z5experimental_args.<locals>.decorator.<locals>.wrapperra   rd   )r   rf   r   rg     s   
z$experimental_args.<locals>.decoratorr   )r{   rg   r   )r   r{   r   experimental_args  s
   
r   )NN)rG   rG   r   )rG   rG   Nr   )NNrG   rG   )r   )NNNN)r   )r   )Pr   rb   r   r   rO   collections.abcr   
contextlibr   	functoolsr   typingr   r   r   r   r	   r
   r   r   redis.exceptionsr   redis.typingr   r   r   r   r   hiredis__version__r   hiredis_versionr   HIREDIS_AVAILABLEImportErrorsslSSL_AVAILABLEcryptographyCRYPTOGRAPHY_AVAILABLE	importlibr   objectr   r-   r   r    r)   r,   r.   r3   r8   r=   rF   rV   rh   rA   rm   rn   tupler9   rz   r   r   r   boolr   r   BaseExceptionr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s   (

"








6



%



