HEX
Server: LiteSpeed
System: Linux cluster02.load-balancer.x2.network 4.18.0-553.51.1.lve.1.el8.x86_64 #1 SMP Wed May 14 14:34:57 UTC 2025 x86_64
User: kbdhpghp (1098)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/certbot/_internal/display/__pycache__/obj.cpython-36.pyc
3

گa~Z�@spdZddlZddlZddlmZddlmZddlmZddlmZddlmZddlm	Z	dd	lm
Z
dd
lmZddlZ
ddlZ
ddlmZddlmZdd
lmZddlmZddlmZddlmZeje�ZdZdZdddZGdd�d�Ze�Z e
d�Z!e
j"j#ej$�Gdd�d��Z%e
j"j#ej$�Gdd�d��Z&ee%e&fd�dd�Z'ee%e&fdd �d!d"�Z(dS)#zFThis modules define the actual display implementations used in Certbot�N)�Any)�Iterable)�List)�Optional)�TextIO)�Tuple)�TypeVar)�Union)�errors)�
interfaces)�	constants)�	completer)�util)�os�okZcancelz- �'�-c@seZdZdd�dd�ZdS)�_DisplayServiceN)�returncCs
d|_dS)N)�display)�self�r�/usr/lib/python3.6/obj.py�__init__,sz_DisplayService.__init__)�__name__�
__module__�__qualname__rrrrrr+sr�Tc
s�eZdZdZeedd��fdd�Zd*eeeeedd�d	d
�Zd+ee	e
eeefe
efeeeeeeee
eeeeeee
fd�
dd
�Zd,eeeeeeeeeefd�dd�Zd-eeeeeeeeeed�dd�Zd.ee
eee
eeeeeeee
efd�dd�Zeeeeeeeed�dd�Zeed�dd�Zd/eeeeeeeeeefd�dd �Zee	ee
fe
ee
ed!�d"d#�Zee	e
eeefe
efdd$�d%d&�Ze
eee
fd'�d(d)�Z�ZS)0�FileDisplayzFile-based display.N)�outfile�force_interactivercs t�j�||_||_d|_dS)NF)�superrrr �skipped_interaction)rrr )�	__class__rrr<s
zFileDisplay.__init__TF)�message�pause�wrapr �decoratercCs~|rtj|�}tjd|�|jj|r(dndd|r6dndjtjt	|d��|jj
�|rz|j|�rptjd�n
tjd�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

        zNotifying user: %sz{line}{frame}{line}�z{msg}{line}z
{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�notificationBs


zFileDisplay.notification)
r$�choices�ok_label�cancel_label�
help_label�default�cli_flagr �
unused_kwargsrc	
KsJ|j||||�}
|
dk	r t|
fS|j||�|jt|��\}}||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$r7r8r9r:r;r<r r=�return_default�code�	selectionrrr�menucszFileDisplay.menu)r$r;r<r r=rcKsT|j||||�}|dk	r t|fStjd|�d}tj|�}|dkrLtdfSt|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)rIrJ)r?r@rr,r5�CANCEL)rr$r;r<r r=rD�ansrrr�input�s
zFileDisplay.input�Yes�No)r$�	yes_label�no_labelr;r<r r=rc
Ks�|j||||�}|dk	r|Stj|�}|jjdjtjttj|d��|jj	�xttj
djtj|�tj|�d��}	|	j|dj
��s�|	j|dj��r�dS|	j|dj
��s�|	j|dj��rRdSqRWdS)	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})r*r+z{yes}/{no}: )�yes�norTF)r?rr,rr/r0rr1r2r3r5Zparens_around_char�
startswith�lower�upper)
rr$rPrQr;r<r r=rDrLrrr�yesno�s"


zFileDisplay.yesno)r$�tagsr;r<r r=rcKs�|j||||�}|dk	r t|fSx�|j||�|jddd�\}}	|tkr�|	j�srdjdd�tdt|�d�D��}	tj	|	�}
|j
|
|�}|r�||fS|jjd	t
j�|jj�q"|gfSq"WdS)
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 rHcss|]}t|�VqdS)N)�str)�.0�xrrr�	<genexpr>�sz(FileDisplay.checklist.<locals>.<genexpr>r>z!** Error - Invalid selection **%s)r?r@rArM�strip�join�rangerCrZseparate_list_input�_scrub_checklist_inputrr/rr1r3)rr$rXr;r<r r=rDrErL�indicesZ
selected_tagsrrr�	checklist�s$"
zFileDisplay.checklist)�promptr;r<r rcCsN|j|�rdS|dkr<dj|�}|r2|dj|�7}tj|��tjd||�|S)a�Should we return the default instead of prompting the user?

        :param str prompt: prompt for the user
        :param T 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

        :returns: The default value if we should return it else `None`
        :rtype: T or `None`

        Nz-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:
%s)r4r0r
�Errorr-r.)rrcr;r<r r+rrrr?�s


zFileDisplay._return_default)r rcCs@|js|stjj�r"|jj�r"dS|js<tjdtj	�d|_dS)z�Can we safely interact with the user?

        :param bool force_interactive: if interactivity is forced

        :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 �sys�stdin�isattyrr"r-ZwarningrZFORCE_INTERACTIVE_FLAG)rr rrrr4s	
zFileDisplay._can_interactcKs$tj��|j||||�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)r
Z	CompleterrM)rr$r;r<r r=rrr�directory_select-s
zFileDisplay.directory_select)rarXrcslydd�|D�}Wntk
r&gSXtt|��}x$|D]}|dksR|t��kr:gSq:W�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)rZ�indexrrr�
<listcomp>Msz6FileDisplay._scrub_checklist_input.<locals>.<listcomp>r>csg|]}�|d�qS)r>r)rZrj)rXrrrkYs)�
ValueError�list�setrC)rrarXZindices_intrjr)rXrr`@s
z"FileDisplay._scrub_checklist_input)r$r7rcCs�|r t|dt�r dd�|D�}|jjdjtj|d��|jjttj�xDt|d�D]6\}}dj||d�}|jjt	j
|��|jjtj�qVW|jjttj�|jj�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 - %srr>r)rZrIrrrrkgsz+FileDisplay._print_menu.<locals>.<listcomp>z{new}{msg}{new})�newr+r>z
{num}: {desc})Znum�descN)�
isinstance�tuplerr/r0rr1r2�	enumeraterr,r3)rr$r7�irpr+rrrrA[szFileDisplay._print_menu)�max_rcCs�d}|dkrdj|d�}nd}x�|dkr�tj|�}|jd�sF|jd�rNtd	fSy$t|�}|dksh||krpd
}t�Wq tk
r�|jjdjt	j
��|jj�Yq Xq Wt|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

        r>zMSelect the appropriate number [1-{max_}] then [enter] (press 'c' to cancel): )ruz@Press 1 [enter] to confirm the selection (press 'c' to cancel): rIrJz{0}** Invalid input **{0}���rvrv)
r0rr5rTrKrirlrr/rr1r3r@)rrurFZ	input_msgrLrrrrBys&


zFileDisplay._get_valid_int_ans)TTFT)NNNNNF)NNF)rNrONNF)NNF)NNF)rrr�__doc__r�boolrrYr6r	rrrrirrGrMrWrbrr?r4rhrr`rArB�
__classcell__rr)r#rr7s6!> *&*)(rcsheZdZdZeeedd��fdd�Zdeeeee	j
d�dd	�Zdee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_argsr=rcst�j�||_dS)N)r!rr)rrr{r=)r#rrr�s
zNoninteractiveDisplay.__init__r()r$r<�extrarcCs8d}||7}|r|d|7}|r.|dj|�7}tj|�S)zNReturn error to raise in case of an attempt to interact in noninteractive modez<Missing command line flag or config entry for this setting:
�
z&

(You can set this with the {0} flag))r0r
�MissingCommandlineFlag)rr$r<r|r+rrr�_interaction_fail�sz'NoninteractiveDisplay._interaction_failFT)r$r%r&r'r=rcKsZ|rtj|�}tjd|�|jj|r(dndd|r6dndjtjt	|d��|jj
�dS)aeDisplays 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
        :param bool decorate: Whether to apply a decorated frame to the message

        zNotifying user: %sz{line}{frame}{line}r(z{msg}{line}z
{frame}{line})r)r*r+N)rr,r-r.rr/r0rr1r2r3)rr$r%r&r'r=rrrr6�s

z"NoninteractiveDisplay.notification)	r$r7r8r9r:r;r<r=rc	Ks&|dkr|j||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�reprr@)	rr$r7r8r9r:r;r<r=rrrrG�szNoninteractiveDisplay.menu)r$r;r<r=rcKs|dkr|j||��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)rr@)rr$r;r<r=rrrrM�s
zNoninteractiveDisplay.input)r$rPrQr;r<r=rcKs|dkr|j||��|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$rPrQr;r<r=rrrrW�s
zNoninteractiveDisplay.yesno)r$rXr;r<r=rcKs(|dkr |j||dj|�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? �?)rr^r@)rr$rXr;r<r=rrrrbszNoninteractiveDisplay.checklistcKs|j|||�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

        )rM)rr$r;r<r=rrrrhsz&NoninteractiveDisplay.directory_select)r()FTT)NNNNN)NN)NNNN)NN)NN)rrrrwrrrrYrr
r~rrxr6r	rrrirGrMrWrrbrhryrr)r#rrz�s"
T6rz)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.)�_SERVICErrlrrrr�get_display-sr�)rrcCstjj|tj�|t_dS)zqSet the display service.

    :param Union[FileDisplay, NoninteractiveDisplay] display: the display service

    N)�zopeZ	componentZprovideUtilityr�IDisplayr�r)rrrr�set_display;sr�))rwZloggingreZtypingrrrrrrrr	Zzope.componentr�Zzope.interfaceZcertbotr
rZcertbot._internalrZcertbot._internal.displayr
rZcertbot.compatrZ	getLoggerrr-r@rKr2rr�rZ	interfaceZimplementerr�rrzr�r�rrrr�<module>s@

k