
    Pf                         d dl Z d dlZd dlZd dlmZmZ d dlZd dlmZm	Z	 dedee	df         dee	         fdZ
d	 Zd
 Zd Zd Zd ZddZd Zd Zd Zd ZdS )    N)ListTuple)KeysTKeyTkeysargs.returnc                     	 t          |            t          | t          t          f          r| g} nt	          |           } n# t
          $ r | g} Y nw xY w|r|                     |           | S N)iter
isinstancebytesstrlist	TypeErrorextend)r   r   s     H/var/www/html/env/lib/python3.11/site-packages/redis/commands/helpers.pylist_or_argsr   
   s    	T


 dUCL)) 	6DD::D   v DKs   >A AAc                 p    t          | t                    r|                     dd          n| }|dk    rdS |S )zAReturn the decoded binary string, or a string, depending on type.utf-8replacenullN)r   r   decode)xrs     r   	nativestrr      s<    (21e(<(<C)$$$!AF{{H    c                 "    | | S d | D             S )z9Given a list of binaries, return the stringified version.Nc                 ,    g | ]}t          |          S  )r   ).0objs     r   
<listcomp>zdelist.<locals>.<listcomp>'   s    (((sIcNN(((r   r    )r   s    r   delistr$   #   s     y((a((((r   c                 n   g }| |S | D ]}	 |                     t          |                     &# t          $ rY 	 |                     t          |                     n2# t          $ r% |                     t	          |                     Y nw xY wY t
          $ r |                     d           Y w xY w|S )z,Optimistically parse the response to a list.N)appendint
ValueErrorfloatr   r   )responseresitems      r   parse_to_listr-   *   s    
C
 	 		JJs4yy!!!! 	, 	, 	,,

5;;'''' , , ,

9T??+++++, 	 	 	JJt	Js8   "/
B2"AB2,B	B2BB2B21B2c                    i }t          dt          |           d          D ]6}t          | |         t                    r|d                             t          | |                              	 t          | |dz            t                    r1|d                             t          | |dz                                 # t          $ r Y w xY wt          | |dz            t                    rt          | |dz                      g|d<   	 t          | |dz                      || |         <   # t          t          f$ r | |dz            || |         <   Y 4w xY w|S )Nr      zChild iterators   )
rangelenr   r   r&   parse_list_to_dict
IndexErrorr)   r   r(   )r*   r+   is      r   r3   r3   >   st   
C1c(mmQ'' 3 3hqk4(( 	3!"))*<Xa[*I*IJJJhq1uot44 W)*112DXaRSe_2U2UVVV   Q.. 	3&8!a%&I&I%JC!""3#(!a%#9#9HQK  z* 3 3 3#+AE?HQK   3Js%   .AB>>
C
C
!D--%EEc                    | i S i }| D ]}t          |t                    r|st          |          dk    rd||d         <   9t          |d         t                    rt          |d                   ||d         <   s	 	 t	          |d                   ||d         <   n(# t
          t          f$ r |d         ||d         <   Y nw xY w# t          $ r Y w xY w|S )Nr0   Tr   )r   r   r2   r3   r)   r   r(   r4   )r*   r+   dets      r   parse_to_dictr8   R   s
   	
C  #t$$ 	C 	s88q==CAKKA%% 		,SV44CAKK)"'A--CAKK!:. ) ) )"%a&CAKKK)   Js0   >BC"C?CCC
CC
   c                 Z    d                     d t          |           D                       S )z3
    Returns a random N character long string.
     c              3   R   K   | ]"}t          j        t          j                  V  #d S r   )randomchoicestringascii_lowercase)r!   r   s     r   	<genexpr>z random_string.<locals>.<genexpr>m   s@        23f,--     r   )joinr1   )lengths    r   random_stringrD   i   s<     77  7<V}}     r   c                    t          | t                    r|                                 } nt          | t                    s| S t	          |           dk    rdS |                     dd          } |                     dd          } d|  dS )zq
    RedisGraph strings must be quoted,
    quote_string wraps given v with quotes incase
    v is a string.
    r   z""\z\\"z\")r   r   r   r   r2   r   )vs    r   quote_stringrI   r   s     !U HHJJ3 
1vv{{t			$A			#uAq888Or   c                     t          j         |           }|                                 D ]J}t          |t                    r3||         ||                    d          <   |                    |           K|S )z3Decode the keys of the given dictionary with utf-8.r   )copyr   r   r   r   pop)r"   newobjks      r   decode_dict_keysrO      sg    Ys^^FXXZZ  a 	(.q	F188G$$%JJqMMMMr   c                    t          | t                    rt          |           S | dS t          | t          t          f          r,dd                    t          t          |                      dS t          | t                    r5dd                    d | 	                                D                        dS t          |           S )	a  
    Turn a parameter value into a string suitable for the params header of
    a Cypher command.
    You may pass any value that would be accepted by `json.dumps()`.

    Ways in which output differs from that of `str()`:
        * Strings are quoted.
        * None --> "null".
        * In dictionaries, keys are _not_ quoted.

    :param value: The parameter value to be turned into a string.
    :return: string
    Nr   [,]{c              3   D   K   | ]\  }}| d t          |           V  dS ):N)stringify_param_value)r!   rN   rH   s      r   rA   z(stringify_param_value.<locals>.<genexpr>   s=      YY41a>>$9!$<$<>>YYYYYYr   })
r   r   rI   r   tuplerB   maprW   dictitems)values    r   rW   rW      s     % 	E"""	v	ED%=	)	) A388C 5u==>>AAAA	E4	 	  ]CHHYY5;;==YYYYY]]]]5zzr   c                 2   t          | t          j                  st          | t          j        j                  r| j        j                            d          S t          | t          j        j                  r| j	        j                            d          S d S )Nprotocol)
r   redisRedisasyncioconnection_poolconnection_kwargsgetclusterAbstractRedisClusternodes_manager)clients    r   get_protocol_versionrj      s    &%+&& F*VU]=P*Q*Q F%7;;JGGG	FEM>	?	? F#599*EEEF Fr   )r9   )rK   r=   r?   typingr   r   r`   redis.typingr   r   r   r   r$   r-   r3   r8   rD   rI   rO   rW   rj   r    r   r   <module>rm      s9               $ $ $ $ $ $ $ $u E$)$4 d    "  ) ) )  (  (  .     (    6F F F F Fr   