
    h/!                        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 	 d dlZej0                  j3                  d      Z eed          d	kD  xs  eed          d	k(  xr  eed
         dk\  Zes ed      	 	 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,d8dZ-d9dZ.	 	 	 d8dee/e&f   de&de&d e&d!ef
d"Z0 ed#e$      Z1d%gg ddfd&e/d'e/de&d e&dee1ge1f   f
d(Z2d) Z3d* Z4d+e&d,e5de&fd-Z6d.e&d/e&defd0Z7d1 Z8	 	 	 	 d:d2ee   d3ee   d4ee   d5ee   dee   f
d6Z9d;d7Z:y# e$ r dZY w xY w# e$ r dZY w xY w# e$ r dZ!Y w xY w)<    N)Callable)contextmanagerwraps)AnyDictListMappingOptionalTypeVarUnion)	DataError)
AbsExpiryT
EncodableTExpiryT.         z"hiredis package should be >= 3.2.0FT)metadatac                 4    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   s      m/var/www/fastuser/data/www/generator.snapmosaic.io/flask_app/venv/lib/python3.12/site-packages/redis/utils.pyr   r   *   s     #5>>#(((    c              #   T   K   | j                         }| |j                          y wN)pipelineexecute)	redis_objps     r   r!   r!   6   s"     A
GIIKs   &(valuereturnc                 L    t        | t              r| j                  dd      S | S )Nutf-8replace)errors)
isinstancebytesdecoder%   s    r   str_if_bytesr/   =   s(    3=eU3KWY/QVr   c                 *    t        t        |             S r    )strr/   r.   s    r   safe_strr2   C   s    |E"##r   dictsc                  :    i }| D ]  }|j                  |        |S )za
    Merge all provided dicts into 1 dict.
    *dicts : `dict`
        dictionaries to merge
    )update)r3   mergedds      r   
dict_merger8   G   s+     F a Mr   c                 .    t         j                  | |      S r    )dictfromkeys)key_listcallbacks     r   list_keys_to_dictr>   U   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_resultrH   Y   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    () -- Deprecated since version category
stacklevelwarningswarnDeprecationWarning)namereasonversionrP   rR   msgs         r   warn_deprecatedrY   k   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 )Nr   rP   )rY   __name__)argsr   funcrU   rV   rW   s     r   wrapperz7deprecated_function.<locals>.decorator.<locals>.wrapper|   s*    D1DMM67qQ(((r   r   )r`   ra   rU   rV   rW   s   ` r   	decoratorz&deprecated_function.<locals>.decorator{   s     	t	) 
	) r    )rV   rW   rU   rb   s   ``` r   deprecated_functionrd   v   s    
 r   arg_namefunction_namerV   rW   rP   c                 z    dd l }d| d|  d}|r	|d| dz  }|r	|d| dz  }|j                  |t        |	       y )
Nr   z	Call to 'z6' function with deprecated usage of input argument/s 'z'.rK   rL   rM   r   rN   rQ   )re   rf   rV   rW   rP   rR   rX   s          r   warn_deprecated_arg_usagerh      sg      M? #''/j	4  F81~.wiq99MM# 2zMJr   C)bound*args_to_warnallowed_argsc                 8     dt         dt         f f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.
    r`   r&   c                 8     t                fd       }|S )Nc                     j                   j                  d j                   j                   }t        t	        ||             }|j                  |       |j                  dd        D ]  }|j                  |d         D ]f  }|dk(  r@t        |      dkD  r2t        t        |j                               j                  	
d       H||v sMt        |j                  	
d       h  | i |S )Nselfrk   r   r   r]   )__code__co_varnamesco_argcountr:   zipr5   poplenrh   rC   keysr^   )r_   r   	arg_namesprovided_argsallowed_argargrm   rl   r`   rV   rW   s         r   ra   z3deprecated_args.<locals>.decorator.<locals>.wrapper   s     112MDMM4M4MNI Y!56M  (fd++ 5!!+t45 $ #:#m"4q"8-]//12#$ M)-T]]FG (((r   r   )r`   ra   rm   rl   rV   rW   s   ` r   rb   z"deprecated_args.<locals>.decorator   s     	t	) 
	)6 r   )ri   )rl   rm   rV   rW   rb   s   ```` r   deprecated_argsr}      s#     a  > 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
loggerDictrx   	getLoggersetLevelINFOStreamHandler
addHandler)loggerhandlers     r   _set_info_loggerr      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redisz99.99.99)r   rW   PackageNotFoundError)libvers    r   get_lib_versionr      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   r   zError r   z connecting to z. )r_   rw   )r   r   s     r   format_error_messager      s~    >>%j\33	Y^^		!	q)*/*QGG Y^^A&'zl"~~a !$	
r   version1version2c                 <   t        t        t        | j                  d                  }t        t        t        |j                  d                  }t	        |      t	        |      kD  r9t	        |      t	        |      z
  }t        |      D ]  }|j                  d        nOt	        |      t	        |      k  r8t	        |      t	        |      z
  }t        |      D ]  }|j                  d        t        |      D ]  \  }}||   ||   kD  r y||   ||   k  s y y)z
    Compare two versions.

    :return: -1 if version1 > version2
             0 if both versions are equal
             1 if version1 < version2
    r   r   r   )rC   mapintsplitrw   rangeappend	enumerate)r   r   num_versions1num_versions2diff_ivers           r   compare_versionsr      s    S(.."567MS(.."567M
=C..=!C$66t 	$A  #	$	]	c-0	0=!C$66t 	$A  #	$ M* 3mA..1a 00	 r   c                 ~    t        | t              r| j                  d      S t        | t              r| S t	        d      )Nr(   z$Key must be either a string or bytes)r+   r,   r-   r1   	TypeError)keys    r   ensure_stringr   	  s6    #uzz'""	C	
>??r   expxexatpxatc                    g }| |j                  d       t        | t        j                        r*|j                  t	        | j                                      |S t        | t              r|j                  |        |S t        | t              r,| j                         r|j                  t	        |              |S t        d      ||j                  d       t        |t        j                        r-|j                  t	        |j                         dz               |S t        |t              r|j                  |       |S t        d      |Ht        |t        j                        rt	        |j                               }|j                  d|g       |S |It        |t        j                        rt	        |j                         dz        }|j                  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_secondsr1   isdigitr   	timestampextend)r   r   r   r   exp_optionss        r   extract_expire_flagsr     s    %'K	~4 b(,,-s2#3#3#5670 / C r", + C RZZ\s2w'( % BCC	4 b(,,-s2#3#3#5#<=>  C r"  BCC		dH--.t~~'(DFD>*  
	dH--.t~~'$./DFD>*r   c                 4    t        j                  | |dd      S )Nz...T)textwidthplaceholderbreak_long_words)textwrapshorten)txt
max_lengths     r   truncate_textr   7  s    
 r   )rI   rI   r   )rI   rI   N)NNNN)d   );r   r   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!   r1   r,   r/   r2   r8   r>   rH   rY   rd   rC   rh   ri   r}   r   r   BaseExceptionr   r   r   r   r   rc   r   r   <module>r      s      $ %  E E E & 8 8 ))//4OOA./!3 OA1$E_Q-?)@A)E  >?? 
M#! 	)  c5j) c $wsCx( T#s(^ -$K& KD#IKK K 	K
 K( Cx  	*** * 	*
 qc1f*Z
#	
S 	
] 	
s 	
s c c <@ ! !%!%	""" :
" :
	"
 
*"JC	    M  #"#s7   AE( E5 "F (E21E25E?>E?FF