HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/rich/__pycache__/prompt.cpython-310.pyc
o

;j�0�@s�ddlmZmZmZmZmZmZmZmZddl	m
Z
ddlmZddl
mZmZed�Zed�ZGdd	�d	e�ZGd
d�de�ZGdd
�d
ee�ZGdd�dee�ZGdd�dee�ZGdd�dee�ZGdd�dee�Zedkr�ddlm Z ej!ddd�r�	ej!ddd�Z"e"dkr�e"dkr�ne d�q�e de"���	ej!d dd!�Z#e$e#�dkr�ne d"�q�e d#e#���ej!d$gd%�d&�Z%e d'e%���ej!d(gd)�d*d+�Z&e d,e&���d.Se d-�d.Sd.S)/�)�Any�Generic�List�Optional�TextIO�TypeVar�Union�overload�)�get_console)�Console)�Text�TextType�
PromptType�DefaultTypec@seZdZdZdS)�PromptErrorz/Exception base class for prompt related errors.N)�__name__�
__module__�__qualname__�__doc__�rr�?/opt/saltstack/salt/lib/python3.10/site-packages/rich/prompt.pyrsrc@s0eZdZdZdeddfdd�Zdefdd�ZdS)	�InvalidResponsez�Exception to indicate a response was invalid. Raise this within process_response() to indicate an error
    and provide an error message.

    Args:
        message (Union[str, Text]): Error message.
    �message�returnNcCs
||_dS�N�r)�selfrrrr�__init__s
zInvalidResponse.__init__cCs|jSrr�rrrr�__rich__szInvalidResponse.__rich__)rrrrrrr rrrrrsrc@s�eZdZUdZeZeed<dZdZ	dZ
dZee
eed<	d4dd	dd
d
d
d�ded
eededee
ededededdfdd�Zee	d4dd	dd
d
d
dd�ded
eededee
edededededeedeeeffdd���Zee	d4dd	dd
d
d
dd�ded
eededee
ededededeedefdd���Ze	d4dd	dd
d
d
ddd�ded
eededee
edededededeedefdd��Zdedefdd�Zdedefd d!�Ze	d5d
edededeedef
d"d#��Zd$edefd%d&�Zd$edefd'd(�Zd$ed)e ddfd*d+�Z!d6d,d-�Z"edd.�deedefd/d0��Z#edd.�dedeedeeeffd1d0��Z#ddd2�dedeedefd3d0�Z#dS)7�
PromptBasea�Ask the user for input until a valid response is received. This is the base class, see one of
    the concrete classes for examples.

    Args:
        prompt (TextType, optional): Prompt text. Defaults to "".
        console (Console, optional): A Console instance or None to use global console. Defaults to None.
        password (bool, optional): Enable password input. Defaults to False.
        choices (List[str], optional): A list of valid choices. Defaults to None.
        case_sensitive (bool, optional): Matching of choices should be case-sensitive. Defaults to True.
        show_default (bool, optional): Show default in prompt. Defaults to True.
        show_choices (bool, optional): Show choices in prompt. Defaults to True.
    �
response_typez*[prompt.invalid]Please enter a valid valuezA[prompt.invalid.choice]Please select one of the available optionsz: N�choices�FT��console�passwordr#�case_sensitive�show_default�show_choices�promptr&r'r(r)r*rcCsT|pt�|_t|t�rtj|dd�n||_||_|dur||_||_	||_
||_dS)Nr+��style)rr&�
isinstance�strr
Zfrom_markupr+r'r#r(r)r*)rr+r&r'r#r(r)r*rrrr6s��
zPromptBase.__init__)r&r'r#r(r)r*�stream�defaultr0c
C�dSrr)
�clsr+r&r'r#r(r)r*r1r0rrr�askNszPromptBase.askc	Cr2rr)	r3r+r&r'r#r(r)r*r0rrrr4_s.)r&r'r#r(r)r*r1r0c	Cs"||||||||d�}
|
||	d�S)a�Shortcut to construct and run a prompt loop and return the result.

        Example:
            >>> filename = Prompt.ask("Enter a filename")

        Args:
            prompt (TextType, optional): Prompt text. Defaults to "".
            console (Console, optional): A Console instance or None to use global console. Defaults to None.
            password (bool, optional): Enable password input. Defaults to False.
            choices (List[str], optional): A list of valid choices. Defaults to None.
            case_sensitive (bool, optional): Matching of choices should be case-sensitive. Defaults to True.
            show_default (bool, optional): Show default in prompt. Defaults to True.
            show_choices (bool, optional): Show choices in prompt. Defaults to True.
            stream (TextIO, optional): Optional text file open for reading to get input. Defaults to None.
        r%�r1r0r)r3r+r&r'r#r(r)r*r1r0Z_promptrrrr4os�	cCstd|�d�d�S)z�Turn the supplied default in to a Text instance.

        Args:
            default (DefaultType): Default value.

        Returns:
            Text: Text containing rendering of default value.
        �(�)�prompt.default)r
)rr1rrr�render_default�s	zPromptBase.render_defaultcCs�|j��}d|_|jr%|jr%d�|j�}d|�d�}|�d�|�|d�|dkrC|jrCt|t	|j
f�rC|�d�|�|�}|�|�|�|j�|S)z�Make prompt text.

        Args:
            default (DefaultType): Default value.

        Returns:
            Text: Text to display in prompt.
        r$�/�[�]� zprompt.choices.)
r+�copy�endr*r#�join�appendr)r.r/r"r9�
prompt_suffix)rr1r+Z_choicesr#�_defaultrrr�make_prompt�s"
	
��


zPromptBase.make_promptcCs|j|||d�S)z�Get input from user.

        Args:
            console (Console): Console instance.
            prompt (TextType): Prompt text.
            password (bool): Enable password entry.

        Returns:
            str: String from user.
        )r'r0)�input)r3r&r+r'r0rrr�	get_input�szPromptBase.get_input�valuecCs>|jdusJ�|jr|��|jvS|����dd�|jD�vS)z�Check value is in the list of valid choices.

        Args:
            value (str): Value entered by user.

        Returns:
            bool: True if choice was valid, otherwise False.
        NcS�g|]}|���qSr��lower��.0�choicerrr�
<listcomp>��z+PromptBase.check_choice.<locals>.<listcomp>)r#r(�striprJ�rrGrrr�check_choice�s	zPromptBase.check_choicecCs~|��}z|�|�}Wntyt|j��w|jdur=|�|�s't|j��|js=|�|jdd�|jD��	|�
���}|S)aProcess response from user, convert to prompt type.

        Args:
            value (str): String typed by user.

        Raises:
            InvalidResponse: If ``value`` is invalid.

        Returns:
            PromptType: The value to be returned from ask method.
        NcSrHrrIrKrrrrN�rOz/PromptBase.process_response.<locals>.<listcomp>)rPr"�
ValueErrorr�validate_error_messager#rR�illegal_choice_messager(�indexrJ)rrG�return_valuerrr�process_response�s 
�


��zPromptBase.process_response�errorcCs|jj|dd�dS)z�Called to handle validation error.

        Args:
            value (str): String entered by user.
            error (InvalidResponse): Exception instance the initiated the error.
        T)ZmarkupN)r&�print)rrGrYrrr�on_validate_errorszPromptBase.on_validate_errorcCsdS)z,Hook to display something before the prompt.Nrrrrr�
pre_promptszPromptBase.pre_prompt�r0cCr2rr)rr0rrr�__call__szPromptBase.__call__cCr2rr)rr1r0rrrr^sr5c
Cs�	|��|�|�}|j|j||j|d�}|dkr|dkr|Sz|�|�}W|Sty?}z|�||�WYd}~qd}~ww)z�Run the prompt loop.

        Args:
            default (Any, optional): Optional default value.

        Returns:
            PromptType: Processed value.
        Tr]r$.N)r\rDrFr&r'rXrr[)rr1r0r+rGrWrYrrrr^s	
���)r$r)rN)$rrrrr/r"�type�__annotations__rTrUrBr#rrrr�boolr�classmethodr	rrrrr4rr
r9rDrFrRrXrr[r\r^rrrrr!s<

������
���	�

������
���	�
��
������
���	�
�������
���	�
���'������
	���
�&r!c@seZdZdZeZdS)�PromptzbA prompt that returns a str.

    Example:
        >>> name = Prompt.ask("Enter your name")


    N)rrrrr/r"rrrrrc0srcc@�eZdZdZeZdZdS)�	IntPromptz�A prompt that returns an integer.

    Example:
        >>> burrito_count = IntPrompt.ask("How many burritos do you want to order")

    z3[prompt.invalid]Please enter a valid integer numberN)rrrr�intr"rTrrrrre<�rec@rd)�FloatPromptzyA prompt that returns a float.

    Example:
        >>> temperature = FloatPrompt.ask("Enter desired temperature")

    z%[prompt.invalid]Please enter a numberN)rrrr�floatr"rTrrrrrhHrgrhc@sReZdZUdZeZdZddgZee	e
d<dedefdd	�Z
d
e	defdd�Zd
S)�ConfirmzuA yes / no confirmation prompt.

    Example:
        >>> if Confirm.ask("Continue"):
                run_job()

    z#[prompt.invalid]Please enter Y or N�y�nr#r1rcCs4|j\}}t|rd|�d�dd�Sd|�d�dd�S)z8Render the default as (y) or (n) rather than True/False.r6r7r8r,)r#r
)rr1Zyes�norrrr9as
*zConfirm.render_defaultrGcCs.|����}||jvrt|j��||jdkS)zConvert choices to a bool.r)rPrJr#rrTrQrrrrXfs

zConfirm.process_responseN)rrrrrar"rTr#rr/r`rr
r9rXrrrrrjTs
rj�__main__)rZzRun [i]prompt[/i] tests?T)r1z6:rocket: Enter a number between [b]1[/b] and [b]10[/b]��
z=:pile_of_poo: [prompt.invalid]Number must be between 1 and 10znumber=z=Please enter a password [cyan](must be at least 5 characters))r'z"[prompt.invalid]password too shortz	password=z
Enter a fruit)ZappleZorangeZpear)r#zfruit=z'What's the best Dog? (Case INSENSITIVE))zBorder TerrierZCollieZLabradoodleF)r#r(zdoggie=z[b]OK :loudly_crying_face:N)'�typingrrrrrrrr	r$rr&r�textr
rrr�	Exceptionrrr!r/rcrfrerirhrarjrZrichrZr4�resultr'�lenZfruitZdoggierrrr�<module>s^(������