HEX
Server: Apache
System: Linux srv1.prosuiteplus.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: prosuiteplus (1001)
PHP: 8.3.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/certbot/display/__pycache__/util.cpython-38.pyc
U

�](U�@s�dZddlZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZddl
mZddl
mZe�e�Zd	Zd
ZdZdZd
ZdZdd�Zddd�Zej�e	j�Gdd�de��Zdd�Zej�e	j�Gdd�de��Z dd�Z!dd�Z"dS)zCertbot display.�N)�	constants)�errors)�
interfaces)�misc)�os)�	completer�H�okZcancel�helpZesczO- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -c	Cs8|��}g}|D]}|�tj|dddd��qd�|�S)z�Format lines nicely to 80 chars.

    :param str msg: Original message

    :returns: Formatted message respecting newlines in message
    :rtype: str

    �PF)Zbreak_long_wordsZbreak_on_hyphens�
)�
splitlines�append�textwrapZfill�join)�msg�linesZfixed_l�line�r�6/usr/lib/python3/dist-packages/certbot/display/util.py�_wrap_lines%s	�
r���@cCs8|rtj�|�tj��t�||�}|s.t�|�d�S)aGet user input with a timeout.

    Behaves the same as six.moves.input, however, an error is raised if
    a user doesn't answer after timeout seconds. The default timeout
    value was chosen to place it just under 12 hours for users following
    our advice and running Certbot twice a day.

    :param str prompt: prompt to provide for input
    :param float timeout: maximum number of seconds to wait for input

    :returns: user response
    :rtype: str

    :raises errors.Error if no answer is given before the timeout

    r)�sys�stdout�write�flushrZreadline_with_timeout�EOFError�rstrip)�promptZtimeoutrrrr�input_with_timeout;s
rcs�eZdZdZ�fdd�Zddd�Zd d	d
�Zd!dd�Zd"dd�Zd#dd�Z	dd�Z
dd�Zd$dd�Zdd�Z
dd�Zdd�Z�ZS)%�FileDisplayzFile-based display.cs$tt|���||_||_d|_dS)NF)�superr �__init__�outfile�force_interactive�skipped_interaction)�selfr#r$��	__class__rrr"_szFileDisplay.__init__TFcCsT|rt|�}|j�djdt|d��|j��|rP|�|�rFtd�n
t�	d�dS)a�Displays 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

        �+{line}{frame}{line}{msg}{line}{frame}{line}r�r�framerzPress Enter to Continuez!Not pausing for user confirmationN)
rr#r�format�
SIDE_FRAMEr�
_can_interactr�logger�debug)r&�message�pause�wrapr$rrr�notificationes��


zFileDisplay.notificationNc	KsB|�||||�rt|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

        �)�_return_default�OK�_print_menu�_get_valid_int_ans�len)r&r1�choices�ok_label�cancel_label�
help_label�default�cli_flagr$�
unused_kwargs�code�	selectionrrr�menu}s
zFileDisplay.menucKsP|�||||�rt|fStd|�d}t|�}|dks@|dkrHtdfSt|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

        z%s (Enter 'c' to cancel):� �c�Cz-1)r6r7rr�CANCEL)r&r1r?r@r$rA�ansrrr�input�szFileDisplay.input�Yes�Noc	Ks�|�||||�r|St|�}|j�djtjttj|d��|j��t	djt
|�t
|�d��}|�|d���s�|�|d�
��r�dS|�|d���s�|�|d�
��rFdSqFdS)	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

        z{0}{frame}{msg}{0}{frame})r+rz{yes}/{no}: )ZyesZnorTFN)r6rr#rr,r�linesepr-rr�_parens_around_char�
startswith�lower�upper)	r&r1�	yes_label�no_labelr?r@r$rArIrrr�yesno�s*
�
���zFileDisplay.yesnocKs�|�||||�rt|fS|�||�|jddd�\}}|tkr�|��shd�dd�tdt|�d�D��}t|�}	|�	|	|�}
|
r�||
fS|j
�dtj
�|j
��q|gfSqd	S)
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

        zrSelect the appropriate numbers separated by commas and/or spaces, or leave input blank to select all options shownT)r$rEcss|]}t|�VqdS�N��str)�.0�xrrr�	<genexpr>sz(FileDisplay.checklist.<locals>.<genexpr>r5z!** Error - Invalid selection **%sN)r6r7r8rJ�stripr�ranger:�separate_list_input�_scrub_checklist_inputr#rrrMr)r&r1�tagsr?r@r$rArBrI�indicesZ
selected_tagsrrr�	checklist�s$�
"�zFileDisplay.checklistcCsT|�|�rdS|dkr>d�|�}|r2|d�|�7}t�|��nt�d||�dSdS)a�Should we return the default instead of prompting the user?

        :param str prompt: prompt for the user
        :param default: default answer to prompt
        :param str cli_flag: command line option for setting an answer
            to this question
        :param bool force_interactive: if interactivity is forced by the
            IDisplay call

        :returns: True if we should return the default without prompting
        :rtype: bool

        FNz-Unable to get an answer for the question:
{0}zA
You can provide an answer on the command line with the {0} flag.z-Falling back to default %s for the prompt:
%sT)r.r,r�Errorr/r0)r&rr?r@r$rrrrr6
s"

���zFileDisplay._return_defaultcCs@|js|stj��r"|j��r"dS|js<t�dtj	�d|_dS)z�Can we safely interact with the user?

        :param bool force_interactive: if interactivity is forced by the
            IDisplay call

        :returns: True if the display can interact with the user
        :rtype: bool

        Tz�Skipped user interaction because Certbot doesn't appear to be running in a terminal. You should probably include --non-interactive or %s on the command line.F)
r$r�stdin�isattyr#r%r/ZwarningrZFORCE_INTERACTIVE_FLAG)r&r$rrrr.+s

���zFileDisplay._can_interactc
Ks0t���|�||||�W5QR�SQRXdS)a
Display a directory selection screen.

        :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
        :param bool force_interactive: True if it's safe to prompt the user
            because it won't cause any workflow regressions

        :returns: tuple of the form (`code`, `string`) where
            `code` - display exit code
            `string` - input entered by the user

        N)rZ	CompleterrJ)r&r1r?r@r$rArrr�directory_selectAs
zFileDisplay.directory_selectcspzdd�|D�}Wntk
r*gYSXtt|��}|D] }|dksT|t��kr<gSq<�fdd�|D�S)z�Validate input and transform indices to appropriate tags.

        :param list indices: input
        :param list tags: Original tags of the checklist

        :returns: valid tags the user selected
        :rtype: :class:`list` of :class:`str`

        cSsg|]}t|��qSr)�int�rX�indexrrr�
<listcomp>`sz6FileDisplay._scrub_checklist_input.<locals>.<listcomp>r5csg|]}�|d�qS)r5rrg�r_rrrils)�
ValueError�list�setr:)r&r`r_rhrrjrr^Ss

z"FileDisplay._scrub_checklist_inputcCs�|r t|dt�r dd�|D�}|j�djtj|d��|j�ttj�t|d�D]4\}}dj||d�}|j�t	|��|j�tj�qT|j�ttj�|j�
�d	S)
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|df�qS)z%s - %srr5r)rXrFrrrriysz+FileDisplay._print_menu.<locals>.<listcomp>z{new}{msg}{new})�newrr5z
{num}: {desc})Znum�descN)�
isinstance�tupler#rr,rrMr-�	enumeraterr)r&r1r;�irorrrrr8ns
�zFileDisplay._print_menucCs�d}|dkrdj|d�}nd}|dkr�t|�}|�d�sB|�d�rJtdfSz$t|�}|dksd||krld}t�Wqtk
r�|j�d�tj	��|j�
�YqXqt|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

        ���r5zMSelect the appropriate number [1-{max_}] then [enter] (press 'c' to cancel): )�max_z@Press 1 [enter] to confirm the selection (press 'c' to cancel): rFrGz{0}** Invalid input **{0})r,rrOrHrfrkr#rrrMrr7)r&rurCZ	input_msgrIrrrr9�s*�
�zFileDisplay._get_valid_int_ans)TTF)NNNNNF)NNF)rKrLNNF)NNF)NNF)�__name__�
__module__�__qualname__�__doc__r"r4rDrJrTrar6r.rer^r8r9�
__classcell__rrr'rr Ys@�
�
!�
�
*�
*�
r cCs4d�|�}|r|d�|�7}|dk	s0|s0t|��dS)aNVerify that provided arguments is a valid IDisplay call.

    :param str prompt: prompt for the user
    :param default: default answer to prompt
    :param str cli_flag: command line option for setting an answer
        to this question
    :param bool force_interactive: if interactivity is forced by the
        IDisplay call

    z*Invalid IDisplay call for this prompt:
{0}z7
You can set an answer to this prompt with the {0} flagN)r,�AssertionError)rr?r@r$rrrr�assert_valid_call�s
�r|csfeZdZdZ�fdd�Zddd�Zdd	d
�Zddd
�Zddd�Zddd�Z	ddd�Z
ddd�Z�ZS)�NoninteractiveDisplayzEAn iDisplay implementation that never asks for interactive user inputcstt|���||_dSrU)r!r}r"r#)r&r#Zunused_argsrAr'rrr"�szNoninteractiveDisplay.__init__�cCs<d}||7}|r|d|7}|r.|d�|�7}t�|��dS)zBError out in case of an attempt to interact in noninteractive modez<Missing command line flag or config entry for this setting:
rz&

(You can set this with the {0} flag)N)r,rZMissingCommandlineFlag)r&r1r@Zextrarrrr�_interaction_fail�sz'NoninteractiveDisplay._interaction_failFTcKs4|rt|�}|j�djtjt|d��|j��dS)aDisplays a notification without waiting for user acceptance.

        :param str message: Message to display to stdout
        :param bool pause: The NoninteractiveDisplay waits for no keyboard
        :param bool wrap: Whether or not the application should wrap text

        r)r*N)rr#rr,rrMr-r)r&r1r2r3rArrrr4�s��z"NoninteractiveDisplay.notificationNc	Ks&|dkr|�||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�reprr7)	r&r1r;r<r=r>r?r@rArrrrD�szNoninteractiveDisplay.menucKs|dkr|�||�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)rr7�r&r1r?r@rArrrrJ�szNoninteractiveDisplay.inputcKs|dkr|�||�|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)r&r1rRrSr?r@rArrrrTszNoninteractiveDisplay.yesnocKs$|dkr|�||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? )rrr7)r&r1r_r?r@rArrrraszNoninteractiveDisplay.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

        )rJr�rrrre-sz&NoninteractiveDisplay.directory_select)r~)FT)NNNNN)NN)NNNN)NN)NN)
rvrwrxryr"rr4rDrJrTrarerzrrr'rr}�s(


�

�
�
�r}cCs|�dd�}dd�|��D�S)z�Separate a comma or space separated list.

    :param str input_: input from the user

    :returns: strings
    :rtype: list

    �,rEcSsg|]}t|��qSrrV)rX�stringrrrriNsz'separate_list_input.<locals>.<listcomp>)�replace�split)Zinput_Z	no_commasrrrr]Bs	r]cCsdj|d|dd�d�S)znPlace parens around first character of label.

    :param str label: Must contain at least one character

    z({first}){rest}rr5N)�first�rest)r,)ZlabelrrrrNQsrN)Nr)#ryZloggingrrZzope.interface�zopeZcertbotrrrZcertbot.compatrrZcertbot.displayrZ	getLoggerrvr/ZWIDTHr7rHZHELPZESCr-rrZ	interfaceZimplementerZIDisplay�objectr r|r}r]rNrrrr�<module>s8

X