a ‚oeÅWã@s0dZddlZddlZddlmZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd lm Z dd l m Z dd lmZdd lmZddlmZddlmZe e¡ZdZdZdZGdd„dƒZeƒZe dƒZGdd„dƒZGdd„dƒZe eefdœdd„Z e eefddœdd„Z!dS) zFThis modules define the actual display implementations used in CertbotéN)ÚAny)ÚIterable)ÚList)ÚOptional)ÚTextIO)ÚTuple)ÚTypeVar)ÚUnion)Úerrors)Ú constants)Ú completer)Úutil)ÚosÚokÚcancelzO- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -c@seZdZddœdd„ZdS)Ú_DisplayServiceN©ÚreturncCs d|_dS©N©Údisplay)Úself©rú>C:\Program Files\Certbot\pkgs\certbot\_internal\display\obj.pyÚ__init__)sz_DisplayService.__init__)Ú__name__Ú __module__Ú __qualname__rrrrrr(srÚTc sæeZdZdZeeddœ‡fdd„ Zd*eeeeeddœd d „Zd+ee e e eefe efe ee ee ee e e eeee ee fd œ d d „Zd,ee ee eeee eefdœdd„Zd-eeee ee eeeedœdd„Zd.ee ee e ee eeee ee efdœdd„Zee ee eee edœdd„Zeedœdd„Zd/ee ee eeee eefdœdd „Zee ee fe ee ed!œd"d#„Zee e e eefe efdd$œd%d&„Ze e ee fd'œd(d)„Z‡ZS)0Ú FileDisplayzFile-based display.N)ÚoutfileÚforce_interactivercs tƒ ¡||_||_d|_dS)NF)Úsuperrr r!Úskipped_interaction)rr r!©Ú __class__rrr6s zFileDisplay.__init__TF)ÚmessageÚpauseÚwrapr!ÚdecoratercCs~|rt |¡}t d|¡|j |r(dndd|r6dndjtjt |d�¡|j  ¡|rz|  |¡rpt  d¡n t d¡d 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}©ÚlineÚframeÚmsgzPress Enter to Continuez!Not pausing for user confirmationN) r Ú wrap_linesÚloggerÚdebugr ÚwriteÚformatrÚlinesepÚ SIDE_FRAMEÚflushÚ _can_interactÚinput_with_timeout)rr&r'r(r!r)rrrÚ notification<s"   ÿ þýÿ   zFileDisplay.notification) r&ÚchoicesÚok_labelÚ cancel_labelÚ help_labelÚdefaultÚcli_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_defaultÚOKÚ _print_menuÚ_get_valid_int_ansÚlen) rr&r>r?r@rArBrCr!rDÚreturn_defaultÚcodeÚ selectionrrrÚmenu]s  zFileDisplay.menu)r&rBrCr!rDrcKsT| ||||¡}|dur t|fSt d|¡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):ú )ÚcÚCz-1)rFrGr r3r<ÚCANCEL)rr&rBrCr!rDrKÚansrrrÚinput�s zFileDisplay.inputÚYesÚNo)r&Ú yes_labelÚno_labelrBrCr!rDrc KsÆ| ||||¡}|dur|St |¡}|j djtjttj|d�¡|j  ¡t  djt  |¡t  |¡d�¡} |   |d  ¡¡s”|   |d ¡¡r˜dS|   |d  ¡¡s¼|   |d ¡¡rPdSqPdS) ažQuery 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}: )ZyesÚnorTF)rFr r3r r6r7rr8r9r:r<Zparens_around_charÚ startswithÚlowerÚupper) rr&rWrXrBrCr!rDrKrSrrrÚyesnožs(  ÿ þÿÿzFileDisplay.yesno)r&ÚtagsrBrCr!rDrc Ks¾| ||||¡}|dur t|fS| ||¡|jddd�\}} |tkr°|  ¡spd dd„tdt|ƒdƒDƒ¡} 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)Ú.0ÚxrrrÚ êóz(FileDisplay.checklist..rEz!** Error - Invalid selection **%s)rFrGrHrTÚstripÚjoinÚrangerJr Zseparate_list_inputÚ_scrub_checklist_inputr r6rr8r:) rr&r^rBrCr!rDrKrLrSÚindicesZ selected_tagsrrrÚ checklistÊs& ý "  ÿ zFileDisplay.checklist)ÚpromptrBrCr!rcCsN| |¡rdS|durGrcz6FileDisplay._scrub_checklist_input..rEcsg|]}ˆ|d‘qS)rErrq©r^rrrsSrc)Ú ValueErrorÚlistÚsetrJ)rrhr^Z indices_intrrrrtrrg:s     z"FileDisplay._scrub_checklist_input)r&r>rcCs°|r t|dtƒr dd„|Dƒ}|j tj›|›tj›�¡|j ttj¡t|dƒD]6\}}|›d|›�}|j t  |¡¡|j tj¡qX|j ttj¡|j  ¡dS)zãPrint 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|]}|d›d|d›�‘qS)rz - rEr)r`rPrrrrsarcz+FileDisplay._print_menu..rEz: N) Ú isinstanceÚtupler r6rr8r9Ú enumerater r3r:)rr&r>ÚiZdescr2rrrrHUs zFileDisplay._print_menu)Úmax_rcCs¬d}|dkrdj|d�}nd}|dkr¤t |¡}| d¡sD| d¡rLtdfSz$t|ƒ}|dksf||krnd}t‚Wqty |j d t 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_msgrSrrrrIrs* þ   ÿzFileDisplay._get_valid_int_ans)TTFT)NNNNNF)NNF)rUrVNNF)NNF)NNF)rrrÚ__doc__rÚboolrr_r=r rrrrprrNrTr]rirrFr;rorrgrHrIÚ __classcell__rrr$rr2sfÿÿ "ý   ü $ÿÿ þ þ ,ÿþ +ÿ ÿ  þ  ÿ ÿ rc sheZdZdZeeeddœ‡fdd„ Zdeeeee j dœdd „Z dee e e edd œd d„Z deeeeeefeefeeeeeeeeeeeeeefdœ dd„Zd eeeeeeeeefdœdd„Zd!eeeeeee eeee dœdd„Zd"eeeeeeeeeeeeefdœdd„Zd#eeeeeeeeefdœdd„Z‡ZS)$ÚNoninteractiveDisplayzKA display utility implementation that never asks for interactive user inputN)r Ú unused_argsrDrcstƒ ¡||_dSr)r"rr )rr r‚rDr$rrršs zNoninteractiveDisplay.__init__r,)r&rCÚextrarcCs8d}||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: )r†ÚreprrG) rr&r>r?r@rArBrCrDrrrrNÀszNoninteractiveDisplay.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)r†rG©rr&rBrCrDrrrrTÚs  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 |¡d¡‚t|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? ú?)r†rerG)rr&r^rBrCrDrrrriüszNoninteractiveDisplay.checklistcKs| |||¡S)a“Simulate 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 )rTrˆrrrrosz&NoninteractiveDisplay.directory_select)r,)FTT)NNNNN)NN)NNNN)NN)NN)rrrr~rrrr_rr r…r†rr=r rrrprNrTr]rriror€rrr$rr�—sLÿ ÿ ÿÿ ý  ý  ÿ ÿ þ ÿÿ ÿ ÿr�rcCstjstdƒ‚tjS)z»Get 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)rŠrrrrrÚ set_display1srŒ)"r~ZloggingrlÚtypingrrrrrrrr Zcertbotr Zcertbot._internalr Zcertbot._internal.displayr r Zcertbot.compatrZ getLoggerrr4rGrRr9rrŠrrr�r‹rŒrrrrÚs:               g