← Back
Editing: reporter.cpython-38.pyc
U �]� � @ s� d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl Z ddlmZ ddlm Z e�e�Ze j�ej�G dd� de��ZdS ) z.Collects and displays information to the user.� )�print_functionN)�queue)� interfaces)�utilc @ sB e Zd ZdZdZdZdZe�dd�Z dd� Z dd d�Zdd � ZdS )�Reporterz�Collects and displays information to the user. :ivar `queue.PriorityQueue` messages: Messages to be displayed to the user. r � � ZReporterMsgzpriority text on_crashc C s t �� | _|| _d S �N)r Z PriorityQueue�messages�config)�selfr � r �2/usr/lib/python3/dist-packages/certbot/reporter.py�__init__% s zReporter.__init__Tc C sD | j | kr| jksn t�| j�| �|||�� t�d|� dS )aX Adds msg to the list of messages to be printed. :param str msg: Message to be displayed to the user. :param int priority: One of `HIGH_PRIORITY`, `MEDIUM_PRIORITY`, or `LOW_PRIORITY`. :param bool on_crash: Whether or not the message should be printed if the program exits abnormally. zReporting to user: %sN)� HIGH_PRIORITY�LOW_PRIORITY�AssertionErrorr Zput� _msg_type�logger�debug)r �msg�priority�on_crashr r r �add_message) s zReporter.add_messagec sD d}| j �� snt�� d dk}tj�� }| jjsF|r>tt j � td� tjddddd�}tj|j |j ddd�� | j �� �s"| j �� }| jjr�|j| jkrn|js�qn|s�|jrn|r�|j| jkr�| jjs�tj�t j� d}|j�� }t|�|d �� t|�dkrntd �� fd d�|dd� D ��� qn|�r@| jj�s@tj�t j� dS )z�Prints messages to the user and clears the message queue. If there is an unhandled exception, only messages for which ``on_crash`` is ``True`` are printed. Fr NzIMPORTANT NOTES:z - z )Zinitial_indent�subsequent_indentZbreak_long_wordsZbreak_on_hyphensr � c 3 s | ]}� � |�V qd S r )�fill)�.0�line�Znext_wrapperr r � <genexpr>a s z*Reporter.print_messages.<locals>.<genexpr>)r �empty�sys�exc_info�stdout�isattyr �quiet�printr Z ANSI_SGR_BOLD�textwrapZTextWrapperr �getr r r �writeZANSI_SGR_RESET�text� splitlinesr �len�join)r Zbold_onZno_exceptionZ first_wrapperr �linesr r r �print_messages9 sL �� �zReporter.print_messagesN)T) �__name__� __module__�__qualname__�__doc__r ZMEDIUM_PRIORITYr �collections� namedtupler r r r0 r r r r r s r )r4 Z __future__r r5 Zloggingr"