o
    Lj                     @   s  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B dee fddZdeed	f d
e	eef deeedB f fddZde	eedB f deeeB  fddZdd Zdd Zdd Zd-ddZdd Zdd Zd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(d)Z d*ee fd+d,Z!dS ).    N)AnyCallableDictIterableListMappingOptional)ChannelTPubSubHandlerSubscriptionkeysargsreturnc                 C   sZ   zt |  t| ttttfr| g} nt| } W n ty#   | g} Y nw |r+| | | S N)	iter
isinstancebytesstr	bytearray
memoryviewlist	TypeErrorextend)r   r    r   T/home/djax/ivt_ai_plugin/venv/lib/python3.10/site-packages/redis/commands/helpers.pylist_or_args   s   

r   .kwargsc                 C   sZ   | rt | d | dd  ng }i }|D ]}t|tr!|j||j< qd ||< q|| |S )Nr      )r   r   r   handlernameupdate)r   r   parsed_argssubscriptionsargr   r   r   parse_pubsub_subscriptions#   s   


r$   r"   c                 C   s   dd |   D S )Nc                 S   s&   g | ]\}}|d u r|nt ||qS r   )r   ).0channelr   r   r   r   
<listcomp>4   s    z,pubsub_subscription_args.<locals>.<listcomp>)items)r"   r   r   r   pubsub_subscription_args1   s   r)   c                 C   s*   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rr   r   r   	nativestr:   s   r0   c                 C   s   | du r| S dd | D S )z9Given a list of binaries, return the stringified version.Nc                 S   s   g | ]}t |qS r   )r0   )r%   objr   r   r   r'   F   s    zdelist.<locals>.<listcomp>r   )r.   r   r   r   delistB   s   r2   c                 C   s   g }h d}| du r|S | D ]l}|du r| d qt|tr%| | qzt|}W n ty9   | d Y qw t|trK| |v rK| | qz	| t| W q tt	tfyz   z	| t| W n ttfyw   | | Y nw Y qw |S )z,Optimistically parse the response to a list.>   	-infinitynaninfinityN)
appendr   floatr0   r   r   lowerint
ValueErrorOverflowError)responseresspecial_valuesitemitem_strr   r   r   parse_to_listI   s<   



rA   
   c                 C   s   d dd t| D S )z3
    Returns a random N character long string.
     c                 s   s    | ]	}t tjV  qd S r   )randomchoicestringascii_lowercaser%   r.   r   r   r   	<genexpr>q   s    
z random_string.<locals>.<genexpr>)joinrange)lengthr   r   r   random_stringm   s   
rM   c                 C   sB   t  | }|  D ]}t|tr|| ||d< || q	|S )z3Decode the keys of the given dictionary with utf-8.r*   )copyr   r   r   r-   pop)r1   newobjkr   r   r   decode_dict_keysv   s   


rR   c                 C   sH   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clientr   r   r   get_protocol_version   s
   r`   c                 C   sL   t | tjst | tjjr| jjddS t | tjjr$| j	jddS dS )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_responsesTrT   r^   r   r   r   get_legacy_responses   s
   rb   )resp2_unifiedresp3_unifiedresp3_to_resp2_legacyuser_protocolra   commonresp2resp3rc   rd   re   c          	      C   s   t |}|r%| du r||pi  |S | dv r|| |S || |S | du s-| dv r=||dur8| |S | |S ||durE|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.
    N)   3)dictr    )	rf   ra   rg   rh   ri   rc   rd   re   	callbacksr   r   r   apply_module_callbacks   s"   


rn   iterablec                 C   s   d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                 s   s    | ]}t |V  qd S r   )boolrH   r   r   r   rI      s    z(at_most_one_value_set.<locals>.<genexpr>r   )sum)ro   valuesr   r   r   at_most_one_value_set   s   rs   )rB   )"rN   rD   rF   typingr   r   r   r   r   r   r   rU   redis.typingr	   r
   r   r   tupler   rl   r$   r   r)   r0   r2   rA   rM   rR   r`   rb   r9   rp   rn   rs   r   r   r   r   <module>   sb    $
"




	
$	
	

%