U
    ÓZjÛ  ã                   @   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 )ÚReporterz�Collects 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   ÚPriorityQueueÚmessagesÚconfig)Úselfr   © r   úS/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/certbot/reporter.pyÚ__init__%   s    
zReporter.__init__Tc                 C   sD   | j |  kr| jksn t‚| 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_PRIORITYÚAssertionErrorr   Ú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k}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s qn|sª|jrn|rÔ|j| jkrÔ| jjsÔt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 )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   NzIMPORTANT NOTES:z - z   )Úinitial_indentÚsubsequent_indentÚbreak_long_wordsÚbreak_on_hyphensr   Ú
c                 3   s   | ]}ˆ   |¡V  qd S r	   )Úfill)Ú.0Úline©Znext_wrapperr   r   Ú	<genexpr>a   s    z*Reporter.print_messages.<locals>.<genexpr>)r   ÚemptyÚsysÚexc_infoÚstdoutÚisattyr   ÚquietÚprintr   ZANSI_SGR_BOLDÚtextwrapÚTextWrapperr   Úgetr   r   r   ÚwriteZANSI_SGR_RESETÚtextÚ
splitlinesr!   ÚlenÚjoin)r   Zbold_onZno_exceptionZfirst_wrapperr   Úlinesr   r$   r   Úprint_messages9   sL    


üü



ÿzReporter.print_messagesN)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ZMEDIUM_PRIORITYr   ÚcollectionsÚ
namedtupler   r   r   r6   r   r   r   r   r      s   
r   )r:   Ú
__future__r   r;   Úloggingr'   r-   Z	six.movesr   Zzope.interfaceZzopeZcertbotr   r   Ú	getLoggerr7   r   Z	interfaceZimplementerZ	IReporterÚobjectr   r   r   r   r   Ú<module>   s   
