3 گa� � @ s` d Z ddlZddlZddlZddlZddlZddlmZ ddlmZ ej e �ZG dd� d�ZdS )z.Collects and displays information to the user.� N)� configuration)�utilc @ s^ e Zd ZdZdZdZdZejdd�Z e jdd�d d �Zde eedd�d d�Zdd�dd�ZdS )�Reporterz�Collects and displays information to the user. :ivar `queue.PriorityQueue` messages: Messages to be displayed to the user. r � � � _msg_typezpriority text on_crashN)�config�returnc C s t j� | _|| _d S )N)�queueZ PriorityQueue�messagesr )�selfr � r �/usr/lib/python3.6/reporter.py�__init__ s zReporter.__init__T)�msg�priority�on_crashr c C sF | j | ko| jkn s t�| jj| j|||�� tjd|� 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 Zputr �logger�debug)r r r r r r r �add_message# s zReporter.add_message)r c sJ d}| j j� sntj� d dk}tjj� }| jjsF|r>tt j � td� tjdd ddd�}tj|j |j ddd�� x�| j j� �s$| j j� }| jjr�|j| jko�|js�qp|s�|jrp|r�|j| jkr�| jjs�tjjt j� d}|jj� }t|j|d �� t|�d krptd j� fdd�|d d� D ��� qpW |�rF| jj �rFtjjt 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 - � � )Zinitial_indent�subsequent_indentZbreak_long_wordsZbreak_on_hyphensr � c 3 s | ]}� j |�V qd S )N)�fill)�.0�line)�next_wrapperr r � <genexpr>\ s z*Reporter.print_messages.<locals>.<genexpr>z )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_messages3 sF "zReporter.print_messages)T)�__name__� __module__�__qualname__�__doc__r ZMEDIUM_PRIORITYr �collections� namedtupler r ZNamespaceConfigr �str�int�boolr r1 r r r r r s r ) r5 r6 Zloggingr r# r) Zcertbotr r Z getLoggerr2 r r r r r r �<module> s