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   úU/root/parts/websockify/install/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    "
!	
