o
    iP                     @   s   d dl Z d dlZd dlZd dlmZmZ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d	Zd
d Zdd Zdd ZdddZdd Zdd Zdee fddZdS )    N)AnyIterableListTuple)KeysTKeyTkeysargs.returnc                 C   sV   zt |  t| ttfr| g} nt| } W n ty!   | g} Y nw |r)| | | S N)iter
isinstancebytesstrlist	TypeErrorextend)r   r	    r   J/home/ubuntu/.local/lib/python3.10/site-packages/redis/commands/helpers.pylist_or_args
   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   r   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   )r   ).0objr   r   r   
<listcomp>'   s    zdelist.<locals>.<listcomp>r   )r   r   r   r   delist#   s   r    c                 C   s   g }h d}| du r|S | D ]\}|du r| d qzt|}W n ty.   | d Y qw t|tr@| |v r@| | qz	| t| W q tyj   z	| t| W n tyg   | | Y nw Y qw |S )z,Optimistically parse the response to a list.>   	-infinitynaninfinityN)	appendr   r   r   r   lowerint
ValueErrorfloat)responseresspecial_valuesitemitem_strr   r   r   parse_to_list*   s6   

r.   
   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>O   s    
z random_string.<locals>.<genexpr>)joinrange)lengthr   r   r   random_stringK   s   
r:   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)r   newobjkr   r   r   decode_dict_keysT   s   


r?   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
   rK   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   )boolr5   r   r   r   r6   t   s    z(at_most_one_value_set.<locals>.<genexpr>   )sum)rL   valuesr   r   r   at_most_one_value_sete   s   rQ   )r/   )r;   r1   r3   typingr   r   r   r   rA   redis.typingr   r   r   r   r    r.   r:   r?   rK   rQ   r   r   r   r   <module>   s    "
!	
