h0ddlmZmZmZmZmZmZmZmZddl m Z ddl m Z ddl mZmZedZedZGdd eZGd d eZGd d eeZGddeeZGddeeZGddeeZGddeeZedkrddlm Z e!ddr e!ddZ"e"dkre"dkrn e d0e de" e!d d!Z#e$e#dkrn e d"3e d#e#e!d$gd%&Z%e d'e%e!d(gd)d*+Z&e d,e&d.Se d-d.Sd.S)/)AnyGenericListOptionalTextIOTypeVarUnionoverload) get_console)Console)TextTextType PromptType DefaultTypeceZdZdZdS) PromptErrorz/Exception base class for prompt related errors.N)__name__ __module__ __qualname____doc__w/builddir/build/BUILD/imunify360-venv-2.5.2/opt/imunify360/venv/lib/python3.11/site-packages/pip/_vendor/rich/prompt.pyrr s9999rrc.eZdZdZdeddfdZdefdZdS)InvalidResponsezException 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. messagereturnNc||_dSNr)selfrs r__init__zInvalidResponse.__init__s  rc|jSr r!r"s r__rich__zInvalidResponse.__rich__s |r)rrrrrr#r&rrrrrs[T(rrceZdZUdZeZeed<dZdZ dZ dZ e e eed< d*dd dd d d d d ed e edede e ededededdfdZee d*dd dd d d ddd ed e edede e ededededede edeeeffdZee d*dd dd d d ddd ed e edede e edededede edefdZe d*dd dd d d dddd ed e edede e ededededede edefdZdedefdZdedefdZe d+d ed edede edef dZdedefd Zdedefd!Zded"e ddfd#Z!d,d$Z"edd%de edefd&Z#edd%dede edeeeffd'Z#ddd(dede edefd)Z#dS)- PromptBaseaAsk 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: NchoicesFTconsolepasswordr*case_sensitive show_default show_choicespromptr-r.r/r0r1rc|p t|_t|trt j|dn||_||_|||_||_ ||_ ||_ dS)Nr2style) r r- isinstancestrr from_markupr2r.r*r/r0r1)r"r2r-r.r*r/r0r1s rr#zPromptBase.__init__6s{/+-- &#&& D V8 4 4 4 4 !  "DL,((r)r-r.r*r/r0r1streamdefaultr9cdSr r) clsr2r-r.r*r/r0r1r:r9s raskzPromptBase.askNs  rcdSr r) r<r2r-r.r*r/r0r1r9s rr=zPromptBase.ask_s  r.)r-r.r*r/r0r1r:r9c @||||||||} | || S)aShortcut 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,r:r9r) r<r2r-r.r*r/r0r1r:r9_prompts rr=zPromptBase.askosF:# )%%   wwv6666rc*td|ddS)zTurn the supplied default in to a Text instance. Args: default (DefaultType): Default value. Returns: Text: Text containing rendering of default value. ()prompt.default)r)r"r:s rrender_defaultzPromptBase.render_defaultsNNNN$4555rc|j}d|_|jrR|jrKd|j}d|d}|d||d|dkrb|jr[t|t|j fr?|d| |}||||j |S)zMake prompt text. Args: default (DefaultType): Default value. Returns: Text: Text to display in prompt. r+/[] zprompt.choices.) r2copyendr1r*joinappendr0r6r7r)rF prompt_suffix)r"r:r2_choicesr*_defaults r make_promptzPromptBase.make_prompts!!##   5 5xx --H%(oooG MM#    MM'#3 4 4 4 sNN! 7S$*<$=>>  MM#   **733H MM( # # # d())) rc2||||S)zGet input from user. Args: console (Console): Console instance. prompt (TextType): Prompt text. password (bool): Enable password entry. Returns: str: String from user. )r.r9)input)r<r-r2r.r9s r get_inputzPromptBase.get_inputs$}}Vhv}FFFrvaluec|jJ|jr||jvS|d|jDvS)zCheck value is in the list of valid choices. Args: value (str): Value entered by user. Returns: bool: True if choice was valid, otherwise False. Nc6g|]}|Srlower.0choices r z+PromptBase.check_choice..s (S(S(SF(S(S(Sr)r*r/stripr[r"rWs r check_choicezPromptBase.check_choicesb|'''   1;;==DL0 0{{}}""$$(S(Sdl(S(S(SSSrc|} ||}n"#t$rt|jwxYw|j||st|j|jsT||jd|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. Nc6g|]}|SrrZr\s rr_z/PromptBase.process_response..s CCCFCCCr) r`r) ValueErrorrvalidate_error_messager*rbillegal_choice_messager/indexr[)r"rW return_values rprocess_responsezPromptBase.process_responses  ?'+'9'9%'@'@LL ? ? ?!$"=>> > ? < #$$U++ C%d&ABBB& #11LCCdlCCCII%++--XX   s ,A errorc:|j|dS)zCalled to handle validation error. Args: value (str): String entered by user. error (InvalidResponse): Exception instance the initiated the error. N)r-print)r"rWrks ron_validate_errorzPromptBase.on_validate_errors  5!!!!!rcdS)z,Hook to display something before the prompt.Nrr%s r pre_promptzPromptBase.pre_prompt srr9cdSr r)r"r9s r__call__zPromptBase.__call__s rcdSr r)r"r:r9s rrszPromptBase.__call__s  rr@cB |||}||j||j|}|dkr|dkr|S ||}|S#t $r }|||Yd}~d}~wwxYw)zRun the prompt loop. Args: default (Any, optional): Optional default value. Returns: PromptType: Processed value. Trqr+.N)rprSrVr-r.rjrrn)r"r:r9r2rWrirks rrszPromptBase.__call__s $ OO   %%g..FNN4<vNVVE{{w#~~ $#44U;; $# #   &&ue444 sA44 B>BB)r+r )rN)$rrrrr7r)type__annotations__rfrgrPr*rrrr boolr# classmethodr rrr rr=rrrFrSrVrbrjrrnrprsrrrr(r(sX  M4IKM#'GXd3i ''')&*'+#!!))))'" )  ) $s)$ )))) ))))0   &*'+#!!#'      '"    $s)$              {J& '    X[     &*'+#!!#'      '"    $s)$                X[  %7&*'+#!!#'%7%7%7%7'" %7  %7 $s)$ %7%7%7%7%7 %7 %7%7%7[%7N 6k 6d 6 6 6 6;4> $( GGGG G  G GGG[G& T# T$ T T T Tcj>"s"?"t"""";;;;59   (6"2 j   X BF   % /7/? z;& '   X *-$$$3$hv6F$RU$$$$$$rr(ceZdZdZeZdS)PromptzbA prompt that returns a str. Example: >>> name = Prompt.ask("Enter your name") N)rrrrr7r)rrrr{r{0sMMMrr{ceZdZdZeZdZdS) IntPromptzA 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)rrrrintr)rfrrrr}r}<s'MRrr}ceZdZdZeZdZdS) FloatPromptzyA prompt that returns a float. Example: >>> temperature = FloatPrompt.ask("Enter desired temperature") z%[prompt.invalid]Please enter a numberN)rrrrfloatr)rfrrrrrHs'MDrrcZeZdZUdZeZdZddgZee e d<de de fdZ d e defd Zd S) ConfirmzuA yes / no confirmation prompt. Example: >>> if Confirm.ask("Continue"): run_job() z#[prompt.invalid]Please enter Y or Nynr*r:rcP|j\}}t|rd|dnd|ddS)z8Render the default as (y) or (n) rather than True/False.rCrDrEr4)r*r)r"r:yesnos rrFzConfirm.render_defaultas:,R'8JJJJJy2yyy@PQQQQrrWc|}||jvrt|j||jdkS)zConvert choices to a bool.r)r`r[r*rrfras rrjzConfirm.process_responsefsJ ##%%  $ $!$"=>> > Q''rN)rrrrrxr)rfr*rr7rwrrrFrjrrrrrTsMBsGT#Y###RkRdRRRR (c(d((((((rr__main__)rmzRun [i]prompt[/i] tests?T)r:z6: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)appleorangepear)r*zfruit=z'What's the best Dog? (Case INSENSITIVE))zBorder TerrierCollie LabradoodleF)r*r/zdoggie=z[b]OK :loudly_crying_face:N)'typingrrrrrrr r r+r r-r textrrrr Exceptionrrr(r7r{r~r}rrrxrrpip._vendor.richrmr=resultr.lenfruitdoggierrrrsQQQQQQQQQQQQQQQQQQQQ W\ " " gm$$ :::::):::     k   O$O$O$O$O$$O$O$O$d     Z_    S S S S S 3 S S S E E E E E*U# E E E(((((j(((4 z&&&&&&{{-t{<<, S]]HRS#F{{v|| EQ R R R  S    !!! 8zzO"Hs8}}!! E6 7 7 7 8 &(&&''' ?4O4O4O PP  u  !!! 5???    """##### *+++++Er