a
    `                     @   s   d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl	Z
ddlmZ ddlmZ eeZe
jejG dd deZdS )	z.Collects and displays information to the user.    )print_functionN)queue)
interfaces)utilc                   @   sB   e Zd ZdZdZdZdZeddZ	dd Z
dd
dZdd ZdS )ReporterzCollects and displays information to the user.

    :ivar `queue.PriorityQueue` messages: Messages to be displayed to
        the user.

    r         ZReporterMsgzpriority text on_crashc                 C   s   t  | _|| _d S N)r   ZPriorityQueuemessagesconfig)selfr    r   </usr/lib/python3/dist-packages/certbot/_internal/reporter.py__init__$   s    
zReporter.__init__Tc                 C   sD   | j |  kr| jksn J | j| ||| td| dS )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.

        zReporting to user: %sN)HIGH_PRIORITYLOW_PRIORITYr
   Zput	_msg_typeloggerdebug)r   msgpriorityon_crashr   r   r   add_message(   s    zReporter.add_messagec                    sD  d}| j  snt d du }tj }| jjsF|r>tt	j
 td tjddddd}tj|j|jddd | j  s"| j  }| jjr|j| jkrn|jsqn|s|jrn|r|j| jkr| jjstjt	j d}|j }t||d  t|dkrntd	 fd
d|dd D  qn|r@| jjs@tjt	j dS )zPrints 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   NzIMPORTANT NOTES:z - z   )Zinitial_indentsubsequent_indentZbreak_long_wordsZbreak_on_hyphensr   
c                 3   s   | ]}  |V  qd S r	   )fill).0lineZnext_wrapperr   r   	<genexpr>`   s   z*Reporter.print_messages.<locals>.<genexpr>)r
   emptysysexc_infostdoutisattyr   quietprintr   ZANSI_SGR_BOLDtextwrapZTextWrapperr   getr   r   r   writeZANSI_SGR_RESETtext
splitlinesr   lenjoin)r   Zbold_onZno_exceptionZfirst_wrapperr   linesr   r   r   print_messages8   sL    






zReporter.print_messagesN)T)__name__
__module____qualname____doc__r   ZMEDIUM_PRIORITYr   collections
namedtupler   r   r   r/   r   r   r   r   r      s   
r   )r3   Z
__future__r   r4   Zloggingr!   r'   Z	six.movesr   Zzope.interfacezopeZcertbotr   r   Z	getLoggerr0   r   Z	interfaceZimplementerZ	IReporterobjectr   r   r   r   r   <module>   s   
