Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
prompt.cpython-313.pyc174 linesDownload Raw Back to __pycache__
1�

2�j�0����SSKJrJrJrJrJrJrJrJr SSK	J3r4 SSKJr SSK
JrJr \"S5r\"S5r"SS	\5r"S5S\5r"SS
\\5r"SS\\5r"SS\\5r"SS\\5r"SS\\5r\S:Xa�SSKJ r  \RCSSS9(a�\RCSSS9r"\"S:�a\"S::aO6\ "S5 M'\ "S\"35 \RCS SS!9r#\$"\#5S:�aO7\ "S"5 M'\ "S#\#<35 \RCS$/S%QS&9r%\ "S'\%<35 \RCS(/S)QS*S+9r&\ "S,\&<35 g.\ "S-5 g.g.)/�)�Any�Generic�List�Optional�TextIO�TypeVar�Union�overload�)�get_console)�Console)�Text�TextType�8PromptType�DefaultTypec��\rSrSrSrSrg)�PromptError�z/Exception base class for prompt related errors.�N)�__name__�9__module__�__qualname__�__firstlineno__�__doc__�__static_attributes__r��QD:\code\apps\devtools\python\user_packages\Python313\site-packages\rich/prompt.pyrrs��9rrc�8�\rSrSrSrS\SS4SjrS\4SjrSrg)	�InvalidResponse�z�Exception to indicate a response was invalid. Raise this within process_response() to indicate an error10and provide an error message.11 12Args:13    message (Union[str, Text]): Error message.14�message�returnNc��Xlg�N�r!)�selfr!s  r�__init__�InvalidResponse.__init__s���rc��UR$r$r%�r&s r�__rich__�InvalidResponse.__rich__s���|�|�rr%)	rrrrrrr'r+rrrrrrs&������T���(�rrc�,�\rSrSr%Sr\r\\S'Sr	Sr15SrSr\
\\\S'S+SS	SS16S17S18S.S\S
\
\S\S\
\\S\S\S\SS4Sjjjr\\S+SS	SS19S20S21SS.S\S
\
\S\S\
\\S\S\S\S\S\
\S\\\44Sjjj55r\\S+SS	SS22S23S24SS.S\S
\
\S\S\
\\S\S\S\S\
\S\4Sjjj55r\S+SS	SS25S26S27SSS.S\S
\
\S\S\
\\S\S\S\S\S\
\S\4Sjjj5rS\S\4SjrS\S\4Sjr\S,S
\S\S\S\
\S\428Sjj5rS\S\4S jrS\S\4S!jr S\S"\!SS4S#jr"S-S$jr#\SS%.S\
\S\4S&jj5r$\SS%.S\S\
\S\\\44S'jj5r$SSS(.S\S\
\S\4S)jjr$S*r%g).�29PromptBase�a�Ask the user for input until a valid response is received. This is the base class, see one of30the concrete classes for examples.31 32Args:33    prompt (TextType, optional): Prompt text. Defaults to "".34    console (Console, optional): A Console instance or None to use global console. Defaults to None.35    password (bool, optional): Enable password input. Defaults to False.36    choices (List[str], optional): A list of valid choices. Defaults to None.37    case_sensitive (bool, optional): Matching of choices should be case-sensitive. Defaults to True.38    show_default (bool, optional): Show default in prompt. Defaults to True.39    show_choices (bool, optional): Show choices in prompt. Defaults to True.40�
response_typez*[prompt.invalid]Please enter a valid valuezA[prompt.invalid.choice]Please select one of the available optionsz: N�choicesFT��console�passwordr1�case_sensitive�show_default�show_choices�promptr3r4r5r6r7r"c���U=(d41 [5Ul[U[5(a[R42"USS9OUUlX0lUbX@lXPl	X`l43Xplg)Nr8��style)rr3�44isinstance�strr�from_markupr8r4r1r5r6r7)r&r8r3r4r1r5r6r7s        rr'�PromptBase.__init__6sa���/�+�-����&�#�&�&�
���V�8�4��	
��45!�
���"�L�,��(��(�r)r3r4r1r5r6r7�stream�defaultr@c��gr$r)46�clsr8r3r4r1r5r6r7rAr@s47          r�ask�PromptBase.askNs��	rc��gr$r)	rCr8r3r4r1r5r6r7r@s	         rrDrE_s��	r.)r3r4r1r5r6r7rAr@c48�&�U"UUUUUUUS9n49U50"X�S9$)a"Shortcut to construct and run a prompt loop and return the result.51 52Example:53    >>> filename = Prompt.ask("Enter a filename")54 55Args:56    prompt (TextType, optional): Prompt text. Defaults to "".57    console (Console, optional): A Console instance or None to use global console. Defaults to None.58    password (bool, optional): Enable password input. Defaults to False.59    choices (List[str], optional): A list of valid choices. Defaults to None.60    case_sensitive (bool, optional): Matching of choices should be case-sensitive. Defaults to True.61    show_default (bool, optional): Show default in prompt. Defaults to True.62    show_choices (bool, optional): Show choices in prompt. Defaults to True.63    stream (TextIO, optional): Optional text file open for reading to get input. Defaults to None.64r2�rAr@r)rCr8r3r4r1r5r6r7rAr@�_prompts           rrDrEos0��:�����)�%�%�65���w�6�6rc�"�[SUS3S5$)z�Turn the supplied default in to a Text instance.66 67Args:68    default (DefaultType): Default value.69 70Returns:71    Text: Text containing rendering of default value.72�(�)�prompt.default)r)r&rAs  r�render_default�PromptBase.render_default�s���a��y��N�$4�5�5rc� �URR5nSUlUR(aUUR(aDSRUR5nSUS3nUR
S5 UR
US5 US:waeUR(aT[U[UR45(a3UR
S5 URU5nUR
U5 UR
UR5 U$)zrMake prompt text.73 74Args:75    default (DefaultType): Default value.76 77Returns:78    Text: Text to display in prompt.79��/�[�]� zprompt.choices.)
r8�copy�endr7r1�join�appendr6r<r=r0rN�
prompt_suffix)r&rAr8�_choicesr1�_defaults      r�make_prompt�PromptBase.make_prompt�s������!�!�#����80��������x�x����-�H��(��1�o�G��M�M�#���M�M�'�#3�4�
�s�N��!�!��7�S�$�*<�*<�$=�>�>��M�M�#���*�*�7�3�H��M�M�(�#��
�
�d�(�(�)��
rc�"�URX#US9$)z�Get input from user.81 82Args:83    console (Console): Console instance.84    prompt (TextType): Prompt text.85    password (bool): Enable password entry.86 87Returns:88    str: String from user.89)r4r@)�input)rCr3r8r4r@s     r�	get_input�PromptBase.get_input�s��$�}�}�V�v�}�F�Fr�valuec��URceUR(aUR5UR;$UR5R5URVs/sHo"R5PM sn;$s snf)z�Check value is in the list of valid choices.90 91Args:92    value (str): Value entered by user.93 94Returns:95    bool: True if choice was valid, otherwise False.96)r1r5�strip�lower)r&rc�choices   r�check_choice�PromptBase.check_choice�sf���|�|�'�'�'�����;�;�=�D�L�L�0�0��{�{�}�"�"�$�d�l�l�(S�l�F����l�(S�S�S��(Ss�)Bc���UR5nURU5nUR97b�UR
U5(d[UR5eUR(dcURUR98UR99Vs/sHo3R5PM snRUR555nU$![a [UR5ef=fs snf)z�Process response from user, convert to prompt type.100 101Args:102    value (str): String typed by user.103 104Raises:105    InvalidResponse: If ``value`` is invalid.106 107Returns:108    PromptType: The value to be returned from ask method.109)rer0�110ValueErrorr�validate_error_messager1rh�illegal_choice_messager5rf�index)r&rc�return_valuergs    r�process_response�PromptBase.process_response�s������
��	?�'+�'9�'9�%�'@�L��<�<�#��$�$�U�+�+�%�d�&A�&A�B�B��&�&�#�1�1��L�L�6:�l�l�C�l�F����l�C�I�I�%�+�+�-�X�� ��111����	?�!�$�"=�"=�>�>�	?��Ds�C�C4112� C1�errorc�8�URRUSS9 g)z�Called to handle validation error.113 114Args:115    value (str): String entered by user.116    error (InvalidResponse): Exception instance the initiated the error.117T)�markupN)r3�print)r&rcrrs   r�on_validate_error�PromptBase.on_validate_errors��	
�����5���.rc��g)z,Hook to display something before the prompt.Nrr*s r�118pre_prompt�PromptBase.pre_prompts�r�r@c��gr$r)r&r@s  r�__call__�PromptBase.__call__s��rc��gr$r)r&rAr@s   rr}r~s��	rrHc�&�UR5 URU5nURURX0RUS9nUS:XaUS:waU$URU5nU$![anURXF5 SnAM�SnAff=f)z|Run the prompt loop.119 120Args:121    default (Any, optional): Optional default value.122 123Returns:124    PromptType: Processed value.125r{rQ.N)ryr]rar3r4rprrv)r&rAr@r8rcrorrs       rr}r~s�����O�O���%�%�g�.�F��N�N�4�<�<����v�N�V�E���{�w�#�~���
$�#�4�4�U�;��126$�#��	#�
��&�&�u�4���
�s�A*�*127B�4B�B)r5r1r3r4r8r7r6)rQr$)r"N)&rrrrrr=r0�type�__annotations__rlrmrZr1rrrr
�boolr'�classmethodr128rrr	rrDrrrNr]rarhrprrvryr}rrrrr.r.s#����M�4��I��K���M�#'�G�X�d�3�i�
 �'��)�&*��'+�#�!�!�)��)��'�"�	)�129�)��$�s�)�$�
)��)��)��)�130�)�0�
��
�&*��'+�#�!�!�#'�
��
��'�"�	
�131�
��$�s�)�$�

��
��
��
��
��� �
�132�{�J�&�	'�
���
��
���&*��'+�#�!�!�#'�����'�"�	�133���$�s�)�$�
��������� ��134�������%7�&*��'+�#�!�!��#'�%7��%7��'�"�	%7�135�%7��$�s�)�$�
%7��%7��%7��%7��%7��� �%7�136
�%7��%7�N	6�k�	6�d�	6��;��4��>�$(�G��G��G��	G�137�� �G�138
�
G��G�&T�#�T�$�T��c��j��>/�s�/�?�/�t�/�;��59��(�6�"2��j�����BF��%��/7��/?��	�z�;�&�	'����139*-��$�3�$�h�v�6F�$�RU�$�$rr.c��\rSrSrSr\rSrg)�Prompti0zVA prompt that returns a str.140 141Example:142    >>> name = Prompt.ask("Enter your name")143 144 145rN)rrrrrr=r0rrrrr�r�0s����Mrr�c� �\rSrSrSr\rSrSrg)�	IntPrompti<z}A prompt that returns an integer.146 147Example:148    >>> burrito_count = IntPrompt.ask("How many burritos do you want to order")149 150z3[prompt.invalid]Please enter a valid integer numberrN)	rrrrr�intr0rlrrrrr�r�<s����M�R�rr�c� �\rSrSrSr\rSrSrg)�FloatPromptiHzmA prompt that returns a float.151 152Example:153    >>> temperature = FloatPrompt.ask("Enter desired temperature")154 155z%[prompt.invalid]Please enter a numberrN)	rrrrr�floatr0rlrrrrr�r�Hs����M�D�rr�c�^�\rSrSr%Sr\rSrSS/r\	\156\S'S\S\
4S	jrS157\158S\4SjrSrg
)�ConfirmiTzeA yes / no confirmation prompt.159 160Example:161    >>> if Confirm.ask("Continue"):162            run_job()163 164z#[prompt.invalid]Please enter Y or N�y�nr1rAr"c�Z�URup#[U(a	SUS3SS9$SUS3SS9$)z8Render the default as (y) or (n) rather than True/False.rKrLrMr:)r1r)r&rA�yes�nos    rrN�Confirm.render_defaultas8���,�,����'�a��u�A�J�@P�Q�Q��2�$�a�y�@P�Q�Qrrcc��UR5R5nXR;a[UR5eXRS:H$)zConvert choices to a bool.r)rerfr1rrl)r&rcs  rrp�Confirm.process_responsefsB�����
�#�#�%�����$�!�$�"=�"=�>�>����Q��'�'rrN)rrrrrr�r0rlr1rr=r�rrrNrprrrrr�r�TsO����M�B���s��G�T�#�Y�#�R�k�R�d�R�165(�c�(�d�(rr��__main__)ruzRun [i]prompt[/i] tests?T)rAz6:rocket: Enter a number between [b]1[/b] and [b]10[/b]��166z=:pile_of_poo: [prompt.invalid]Number must be between 1 and 10znumber=z=Please enter a password [cyan](must be at least 5 characters))r4z"[prompt.invalid]password too shortz	password=z
Enter a fruit)�apple�orange�pear)r1zfruit=z'What's the best Dog? (Case INSENSITIVE))zBorder Terrier�Collie�LabradoodleF)r1r5zdoggie=z[b]OK :loudly_crying_face:N)'�typingrrrrrrr	r167rQrr3r
�textrrrr�	Exceptionrrr.r=r�r�r�r�r�r�r�r�richrurD�resultr4�len�fruit�doggierrr�<module>r�s���Q�Q�Q��� �
�\�
"�168��m�$��:�)�:��k��O$���$�O$�d	�Z��_�	�	S�169�3��	S�	E�*�U�#�	E�(�j���(�4�z����{�{�-�t�{�<���]�]�H�RS�#��F���{�v��|���Q�R�
�	���x� �!���z�z�O��"��H��8�}��!���6�7��	�	�(��&�'��170�171�?�4O�172�P��
��u�i� �!����5�?� ��173��174	���z�"�#�	�*�+�Er
codekingpro/portable-devtools · Team Ai