a }|g4X@s0dZddlZddlZddlmZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd lm Z dd l m Z dd lmZdd lmZddlmZddlmZeeZdZdZdZGdddZeZe dZGdddZGdddZe eefdddZ e eefddddZ!dS) zFThis modules define the actual display implementations used in CertbotN)Any)Iterable)List)Optional)TextIO)Tuple)TypeVar)Union)errors) constants) completer)util)osokcancelzO- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -c@seZdZddddZdS)_DisplayServiceNreturncCs d|_dSNdisplay)selfrA/usr/lib/python3.9/site-packages/certbot/_internal/display/obj.py__init__)sz_DisplayService.__init__)__name__ __module__ __qualname__rrrrrr(srTc seZdZdZeeddfdd Zd*eeeeeddd d Zd+ee e e eefe efe ee ee ee e e eeee ee fd d d Zd,ee ee eeee eefdddZd-eeee ee eeeedddZd.ee ee e ee eeee ee efdddZee ee eee edddZeedddZd/ee ee eeee eefddd Zee ee fe ee ed!d"d#Zee e e eefe efdd$d%d&Ze e ee fd'd(d)ZZS)0 FileDisplayzFile-based display.N)outfileforce_interactivercs t||_||_d|_dS)NF)superrr r!skipped_interaction)rr r! __class__rrr6s zFileDisplay.__init__TF)messagepausewrapr!decoratercCs~|rt|}td||j|r(dndd|r6dndjtjt |d|j |rz| |rpt dn tdd S) aDisplays a notification and waits for user acceptance. :param str message: Message to display :param bool pause: Whether or not the program should pause for the user's confirmation :param bool wrap: Whether or not the application should wrap text :param bool force_interactive: True if it's safe to prompt the user because it won't cause any workflow regressions :param bool decorate: Whether to surround the message with a decorated frame Notifying user: %s{line}{frame}{line} {msg}{line} {frame}{line}lineframemsgzPress Enter to Continuez!Not pausing for user confirmationN) r wrap_linesloggerdebugr writeformatrlinesep SIDE_FRAMEflush _can_interactinput_with_timeout)rr&r'r(r!r)rrr notification<s"       zFileDisplay.notification) r&choicesok_label cancel_label help_labeldefaultcli_flagr! unused_kwargsrc KsJ|||||} | dur t| fS||||t|\} } | | dfS)aCDisplay a menu. .. todo:: This doesn't enable the help label/button (I wasn't sold on any interface I came up with for this). It would be a nice feature :param str message: title of menu :param choices: Menu lines, len must be > 0 :type choices: list of tuples (tag, item) or list of descriptions (tags will be enumerated) :param default: default value to return (if one exists) :param str cli_flag: option used to set this value with the CLI :param bool force_interactive: True if it's safe to prompt the user because it won't cause any workflow regressions :returns: tuple of (`code`, `index`) where `code` - str display exit code `index` - int index of the user's selection :rtype: tuple N)_return_defaultOK _print_menu_get_valid_int_anslen) rr&r>r?r@rArBrCr!rDreturn_defaultcode selectionrrrmenu]s  zFileDisplay.menu)r&rBrCr!rDrcKsT|||||}|dur t|fStd|d}t|}|dvrLtdfSt|fS)aAccept input from the user. :param str message: message to display to the user :param default: default value to return (if one exists) :param str cli_flag: option used to set this value with the CLI :param bool force_interactive: True if it's safe to prompt the user because it won't cause any workflow regressions :returns: tuple of (`code`, `input`) where `code` - str display exit code `input` - str of the user's input :rtype: tuple Nz%s (Enter 'c' to cancel): )cCz-1)rFrGr r3r<CANCEL)rr&rBrCr!rDrKansrrrinputs zFileDisplay.inputYesNo)r& yes_labelno_labelrBrCr!rDrc Ks|||||}|dur|St|}|jdjtjttj|d|j t djt |t |d} | |d s| |drdS| |d s| |drPdSqPdS) aQuery the user with a yes/no question. Yes and No label must begin with different letters, and must contain at least one letter each. :param str message: question for the user :param str yes_label: Label of the "Yes" parameter :param str no_label: Label of the "No" parameter :param default: default value to return (if one exists) :param str cli_flag: option used to set this value with the CLI :param bool force_interactive: True if it's safe to prompt the user because it won't cause any workflow regressions :returns: True for "Yes", False for "No" :rtype: bool Nz{0}{frame}{msg}{0}{frame})r1r2z {yes}/{no}: )ZyesnorTF)rFr r3r r6r7rr8r9r:r<Zparens_around_char startswithlowerupper) rr&rWrXrBrCr!rDrKrSrrryesnos(   zFileDisplay.yesno)r&tagsrBrCr!rDrc Ks|||||}|dur t|fS||||jddd\}} |tkr| spdddtdt|dD} t | } | | |} | r|| fS|j d t j|j q |gfSq dS) aCDisplay a checklist. :param str message: Message to display to user :param list tags: `str` tags to select, len(tags) > 0 :param default: default value to return (if one exists) :param str cli_flag: option used to set this value with the CLI :param bool force_interactive: True if it's safe to prompt the user because it won't cause any workflow regressions :returns: tuple of (`code`, `tags`) where `code` - str display exit code `tags` - list of selected tags :rtype: tuple NzrSelect the appropriate numbers separated by commas and/or spaces, or leave input blank to select all options shownT)r!rOcss|]}t|VqdSr)str).0xrrr z(FileDisplay.checklist..rEz!** Error - Invalid selection **%s)rFrGrHrTstripjoinrangerJr Zseparate_list_input_scrub_checklist_inputr r6rr8r:) rr&r^rBrCr!rDrKrLrSindicesZ selected_tagsrrr checklists&  "   zFileDisplay.checklist)promptrBrCr!rcCsN||rdS|durGrcz6FileDisplay._scrub_checklist_input..rEcsg|]}|dqS)rErrqr^rrrsTrc) ValueErrorlistdictfromkeyskeysrJ)rrhr^Z indices_intrrrrtrrg:s    z"FileDisplay._scrub_checklist_input)r&r>rcCs|r t|dtr dd|D}|jtj|tj|jttjt|dD]6\}}|d|}|jt ||jtjqX|jttj|j dS)zPrint a menu on the screen. :param str message: title of menu :param choices: Menu lines :type choices: list of tuples (tag, item) or list of descriptions (tags will be enumerated) rcSs"g|]}|dd|dqS)rz - rEr)r`rPrrrrsbrcz+FileDisplay._print_menu..rEz: N) isinstancetupler r6rr8r9 enumerater r3r:)rr&r>iZdescr2rrrrHVs zFileDisplay._print_menu)max_rcCsd}|dkrdj|d}nd}|dkrt|}|dsD|drLtdfSz$t|}|dksf||krnd}tWqty|jdt j |j Yq0qt |fS) a5Get a numerical selection. :param int max: The maximum entry (len of choices), must be positive :returns: tuple of the form (`code`, `selection`) where `code` - str display exit code ('ok' or cancel') `selection` - int user's selection :rtype: tuple rEzMSelect the appropriate number [1-{max_}] then [enter] (press 'c' to cancel): )r~z@Press 1 [enter] to confirm the selection (press 'c' to cancel): rPrQz{0}** Invalid input **{0}) r7r r<rZrRrprur r6rr8r:rG)rr~rMZ input_msgrSrrrrIss*    zFileDisplay._get_valid_int_ans)TTFT)NNNNNF)NNF)rUrVNNF)NNF)NNF)rrr__doc__rboolrr_r=r rrrrprrNrTr]rirrFr;rorrgrHrI __classcell__rrr$rr2sf "   $   , +     rc sheZdZdZeeeddfdd Zdeeeee j ddd Z dee e e edd d dZ deeeeeefeefeeeeeeeeeeeeeefd ddZd eeeeeeeeefdddZd!eeeeeee eeee dddZd"eeeeeeeeeeeeefdddZd#eeeeeeeeefdddZZS)$NoninteractiveDisplayzKA display utility implementation that never asks for interactive user inputN)r unused_argsrDrcst||_dSr)r"rr )rr rrDr$rrrs zNoninteractiveDisplay.__init__r,)r&rCextrarcCs8d}||7}|r|d|7}|r.|d|7}t|S)zNReturn error to raise in case of an attempt to interact in noninteractive modezr?r@rArBrCrDrc Ks&|dur|||dt|t|fS)a_Avoid displaying a menu. :param str message: title of menu :param choices: Menu lines, len must be > 0 :type choices: list of tuples (tag, item) or list of descriptions (tags will be enumerated) :param int default: the default choice :param dict kwargs: absorbs various irrelevant labelling arguments :returns: tuple of (`code`, `index`) where `code` - str display exit code `index` - int index of the user's selection :rtype: tuple :raises errors.MissingCommandlineFlag: if there was no default Nz Choices: )rreprrG) rr&r>r?r@rArBrCrDrrrrNszNoninteractiveDisplay.menu)r&rBrCrDrcKs|dur|||t|fS)aKAccept input from the user. :param str message: message to display to the user :returns: tuple of (`code`, `input`) where `code` - str display exit code `input` - str of the user's input :rtype: tuple :raises errors.MissingCommandlineFlag: if there was no default N)rrGrr&rBrCrDrrrrTs  zNoninteractiveDisplay.input)r&rWrXrBrCrDrcKs|dur||||S)a+Decide Yes or No, without asking anybody :param str message: question for the user :param dict kwargs: absorbs yes_label, no_label :raises errors.MissingCommandlineFlag: if there was no default :returns: True for "Yes", False for "No" :rtype: bool N)r)rr&rWrXrBrCrDrrrr]s  zNoninteractiveDisplay.yesno)r&r^rBrCrDrcKs(|dur |||d|dt|fS)ajDisplay a checklist. :param str message: Message to display to user :param list tags: `str` tags to select, len(tags) > 0 :param dict kwargs: absorbs default_status arg :returns: tuple of (`code`, `tags`) where `code` - str display exit code `tags` - list of selected tags :rtype: tuple Nz? ?)rrerG)rr&r^rBrCrDrrrriszNoninteractiveDisplay.checklistcKs||||S)aSimulate prompting the user for a directory. This function returns default if it is not ``None``, otherwise, an exception is raised explaining the problem. If cli_flag is not ``None``, the error message will include the flag that can be used to set this value with the CLI. :param str message: prompt to give the user :param default: default value to return (if one exists) :param str cli_flag: option used to set this value with the CLI :returns: tuple of the form (`code`, `string`) where `code` - int display exit code `string` - input entered by the user )rTrrrrrosz&NoninteractiveDisplay.directory_select)r,)FTT)NNNNN)NN)NNNN)NN)NN)rrrrrrrr_rr rrrr=r rrrprNrTr]rrirorrrr$rrsL           rrcCstjstdtjS)zGet the display utility. :return: the display utility :rtype: Union[FileDisplay, NoninteractiveDisplay] :raise: ValueError if the display utility is not configured yet. zlThis function was called too early in Certbot's execution as the display utility hasn't been configured yet.)_SERVICErrurrrr get_display$sr)rrcCs |t_dS)zqSet the display service. :param Union[FileDisplay, NoninteractiveDisplay] display: the display service N)rrrrrr set_display2sr)"rZloggingrltypingrrrrrrrr Zcertbotr Zcertbot._internalr Zcertbot._internal.displayr r Zcertbot.compatrZ getLoggerrr4rGrRr9rrrrrrrrrrrs:               h