
    AHj                        d dl Z d dlZd dlZd dlmZmZmZmZmZm	Z	m
Z
 d dlZd dlmZmZmZ dedee   dz  dee   fdZdeedf   d	e	eef   deeedz  f   fd
Zde	eedz  f   deeez     fdZd Zd Zd Zd dZd Zd Zd Zddddde
e   dedeeedef   f   deeedef   f   deeedef   f   de
eeedef   f      de
eeedef   f      de
eeedef   f      deeedef   f   fdZ dee   fdZ!y)!    N)AnyCallableDictIterableListMappingOptional)ChannelTPubSubHandlerSubscriptionkeysargsreturnc                     	 t        |        t        | t        t        t        t
        f      r| g} nt        |       } |r| j                  |       | S # t        $ r | g} Y #w xY wN)	iter
isinstancebytesstr	bytearray
memoryviewlist	TypeErrorextend)r   r   s     N/root/tools/cai/cai_env/lib/python3.12/site-packages/redis/commands/helpers.pylist_or_argsr      sa    	T
 dUCJ?@6D:D DK	  vs   :A A A .kwargsc                     | rt        | d   | dd        ng }i }|D ]1  }t        |t              r|j                  ||j                  <   -d ||<   3 |j                  |       |S )Nr      )r   r   r   handlernameupdate)r   r   parsed_argssubscriptionsargs        r   parse_pubsub_subscriptionsr&   #   sn     6:,tAwQR1rK:<M &c<(&)kkM#((#!%M#	&
      r$   c                 p    | j                         D cg c]  \  }}||nt        ||       c}}S c c}}w r   )itemsr   )r$   channelr    s      r   pubsub_subscription_argsr+   1   sA    
 !. 3 3 5GW ?Wg(FF  s   2c                 Z    t        | t              r| j                  dd      n| }|dk(  ry|S )zAReturn the decoded binary string, or a string, depending on type.utf-8replacenullN)r   r   decode)xrs     r   	nativestrr3   :   s,    (21e(<)$!AF{Hr'   c                 F    | | S | D cg c]  }t        |       c}S c c}w )z9Given a list of binaries, return the stringified version.)r3   )r1   objs     r   delistr6   B   s$    y&'(sIcN(((s   c                 D   g }h d}| |S | D ]  }||j                  d       t        |t              r|j                  |       9	 t        |      }t        |t
              r$|j                         |v r|j                  |       y	 |j                  t        |              |S # t        $ r |j                  d       Y w xY w# t        t        t        f$ rF 	 |j                  t        |             n&# t        t        f$ r |j                  |       Y nw xY wY w xY w)z,Optimistically parse the response to a list.>   	-infinitynaninfinityN)
appendr   floatr3   r   r   lowerint
ValueErrorOverflowError)responseresspecial_valuesitemitem_strs        r   parse_to_listrF   I   s   
C5N
 )<JJtdE"JJt	 H
 h$)9^)KJJx )

3t9%#)0 J  	JJt	 y9 ))JJuT{+"I. )JJx())sH   B%C%CCDC54D5 DDDDDc                 D    dj                  d t        |       D              S )z3
    Returns a random N character long string.
     c              3   b   K   | ]'  }t        j                  t        j                         ) y wr   )randomchoicestringascii_lowercase.0r1   s     r   	<genexpr>z random_string.<locals>.<genexpr>q   s$      23f,,-s   -/)joinrange)lengths    r   random_stringrT   m   s&     77 7<V}  r'   c                     t        j                   |       }| j                         D ];  }t        |t              s||   ||j	                  d      <   |j                  |       = |S )z3Decode the keys of the given dictionary with utf-8.r-   )copyr   r   r   r0   pop)r5   newobjks      r   decode_dict_keysrZ   v   sW    YYs^FXXZ a(.q	F188G$%JJqM Mr'   c                 \   t        | t        j                        s$t        | t        j                  j                        r%| j                  j
                  j                  d      S t        | t        j                  j                        r%| j                  j
                  j                  d      S y )Nprotocol
r   redisRedisasyncioconnection_poolconnection_kwargsgetclusterAbstractRedisClusternodes_managerclients    r   get_protocol_versionri      sw    &%++&*VU]]=P=P*Q%%77;;JGG	FEMM>>	?##5599*EE 
@r'   c                 `   t        | t        j                        s$t        | t        j                  j                        r&| j                  j
                  j                  dd      S t        | t        j                  j                        r&| j                  j
                  j                  dd      S y)a?  Return the user-supplied ``legacy_responses`` flag for ``client``.

    Defaults to ``True`` when the flag is not present in the client's
    ``connection_kwargs``. Mirrors :func:`get_protocol_version` so module
    command bases can read both the protocol and the response-shape
    selection from the same place.
    legacy_responsesTr]   rg   s    r   get_legacy_responsesrl      s}     &%++&*VU]]=P=P*Q%%77;;<NPTUU	FEMM>>	?##5599:LdSSr'   )resp2_unifiedresp3_unifiedresp3_to_resp2_legacyuser_protocolrk   commonresp2resp3rm   rn   ro   c                   t        |      }|rC| |j                  |xs i        |S | dv r|j                  |       |S |j                  |       |S | | dv r|j                  ||       |S |       |S |j                  ||n|       |S )a  Return the merged module-callback dict for the given (protocol,
    legacy_responses) combination.

    Mirrors the selection used by
    :func:`redis._parsers.response_callbacks.get_response_callbacks` for
    the core callbacks: ``common`` is overlaid with the protocol-specific
    dict matching ``user_protocol`` and ``legacy_responses``.
    ``resp2_unified`` defaults to ``resp2``, ``resp3_unified`` to ``resp3``,
    and ``resp3_to_resp2_legacy`` to an empty dict.
    )   3)dictr"   )	rp   rk   rq   rr   rs   rm   rn   ro   	callbackss	            r   apply_module_callbacksry      s    * 04F|I 28b9  h&U#  U# 	  MX$=m.G]S  NSS  m.G]USr'   iterablec                 0    d | D        }t        |      dk  S )a  
    Checks that at most one of the values in the iterable is truthy.

    Args:
        iterable: An iterable of values to check.

    Returns:
        True if at most one value is truthy, False otherwise.

    Raises:
        Might raise an error if the values in iterable are not boolean-compatible.
        For example if the type of the values implement
        __len__ or __bool__ methods and they raise an error.
    c              3   2   K   | ]  }t        |        y wr   )boolrN   s     r   rP   z(at_most_one_value_set.<locals>.<genexpr>   s     (!d1g(s   r   )sum)rz   valuess     r   at_most_one_value_setr      s     )x(Fv;!r'   )
   )"rV   rJ   rL   typingr   r   r   r   r   r   r	   r^   redis.typingr
   r   r   r   tupler   rw   r&   r   r+   r3   r6   rF   rT   rZ   ri   rl   r>   r}   ry   r    r'   r   <module>r      s         > >s (3-$"6 49 "
S/#*3+=#>	(MD(
()8]T%99:	(\
!")!HF, >B=AEI"C="" hsCx(()	"
 Xc3h''(" Xc3h''(" DhsCx&8!89:" DhsCx&8!89:" $DhsCx.@)@$AB" 
#xS!
!""JHSM r'   