B
    A!p\
              
   @   s   d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	d
dgZdZdZdZddddddddZdddddddddd	Zd.d d!Zd/d"d#ZG d$d% d%e	ZG d&d' d'eZG d(d) d)eZG d*d+ d+eZd,d- ZdS )0zvPlain text reporters:

:text: the default one grouping messages by module
:colorized: an ANSI colorized text reporter
    )print_functionN)	IReporter)BaseReporter)utils)
TextWriter =-.z[mz[0m0134579)resetboldZitalicZ	underlineZblinkinverseZstrikeZ30Z31Z32Z33Z34Z35Z36Z37)	r   ZblackredgreenyellowZbluemagentaZcyanZwhitec             C   s|   g }|r.t |}x|D ]}|t|  qW | rb|  rT|ddg ||  n|t|   |rxtd| t	 S dS )a  return ansi escape code corresponding to color and style

    :type color: str or None
    :param color:
      the color name (see `ANSI_COLORS` for available values)
      or the color number when 256 colors are available

    :type style: str or None
    :param style:
      style string (see `ANSI_COLORS` for available values). To get
      several style effects at the same time, use a coma as separator.

    :raise KeyError: if an unexistent color or style identifier is given

    :rtype: str
    :return: the built escape code
    Z38r   ;r   )
r   Z_splitstripappendANSI_STYLESisdigitextendANSI_COLORSANSI_PREFIXjoinANSI_END)colorstyleZ	ansi_codeZstyle_attrsZeffect r%   4lib/python3.7/site-packages/pylint/reporters/text.py_get_ansi_code<   s    

r'   c             C   s4   |dkr|dkr| S t ||}|r0d|| tf S | S )aC  colorize message by wrapping it with ansi escape codes

    :type msg: str or unicode
    :param msg: the message string to colorize

    :type color: str or None
    :param color:
      the color identifier (see `ANSI_COLORS` for available values)

    :type style: str or None
    :param style:
      style string (see `ANSI_COLORS` for available values). To get
      several style effects at the same time, use a coma as separator.

    :raise KeyError: if an unexistent color or style identifier is given

    :rtype: str or unicode
    :return: the ansi escaped string
    Nz%s%s%s)r'   
ANSI_RESET)msgr#   r$   Zescape_coder%   r%   r&   colorize_ansi^   s    
r*   c               @   sJ   e Zd ZdZeZdZdZdZdddZ	dd	 Z
d
d Zdd Zdd ZdS )TextReporterz*reports messages and layouts in plain texttextZtxtz2{path}:{line}:{column}: {msg_id}: {msg} ({symbol})Nc             C   s   t | | t | _d | _d S )N)r   __init__set_modules	_template)selfoutputr%   r%   r&   r-      s    zTextReporter.__init__c             C   s   t | jjjp| j| _d S )N)strlinterZconfigZmsg_templateline_formatr0   )r1   modulefilepathr%   r%   r&   on_set_current_module   s    z"TextReporter.on_set_current_modulec             C   s   |  || j dS )zJConvenience method to write a formated message with class default templateN)writelnformatr0   )r1   r)   r%   r%   r&   write_message   s    zTextReporter.write_messagec             C   sJ   |j | jkr<|j r2| d|j   | j|j  n
| d | | dS )z;manage message of different type and in the context of pathz************* Module %sz************* N)r6   r/   r9   addr;   )r1   r)   r%   r%   r&   handle_message   s    
zTextReporter.handle_messagec             C   s    t | jd t || j dS )zlaunch layouts display)fileN)printoutr   r:   )r1   Zlayoutr%   r%   r&   _display   s    zTextReporter._display)N)__name__
__module____qualname____doc__r   Z__implements__name	extensionr5   r-   r8   r;   r=   rA   r%   r%   r%   r&   r+   |   s   

r+   c               @   s"   e Zd ZdZdZdZdddZdS )ParseableTextReporterza reporter very similar to TextReporter, but display messages in a form
    recognized by most text editors :

    <filename>:<linenum>:<msg>
    Z	parseablez0{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}Nc             C   s(   t d| j| jf t t| | d S )NzG%s output format is deprecated. This is equivalent to --msg-template=%s)warningswarnrF   r5   DeprecationWarningr+   r-   )r1   r2   r%   r%   r&   r-      s
    zParseableTextReporter.__init__)N)rB   rC   rD   rE   rF   r5   r-   r%   r%   r%   r&   rH      s   rH   c               @   s   e Zd ZdZdZdZdS )VSTextReporterzVisual studio text reporterZmsvsz/{path}({line}): [{msg_id}({symbol}){obj}] {msg}N)rB   rC   rD   rE   rF   r5   r%   r%   r%   r&   rL      s   rL   c               @   sB   e Zd ZdZdZddddddd	d
ZdddZdd Zdd ZdS )ColorizedTextReporterz.Simple TextReporter that colorizes text outputZ	colorized)r   N)Nr   )r   zbold, italic)r   N)r   r   )r   zbold, underline)r   r   )ICRWEFSNc             C   sX   t | | |pttj| _ddg}tjd|krTt	j
dkrTdd l}|| j| _d S )Nzxterm-16colorzxterm-256colorZTERMZwin32r   )r+   r-   dictrM   COLOR_MAPPINGcolor_mappingosenvirongetsysplatformcoloramaZAnsiToWin32r@   )r1   r2   rW   Z
ansi_termsr]   r%   r%   r&   r-      s    
zColorizedTextReporter.__init__c             C   s(   y| j |d  S  tk
r"   dS X dS )zgReturns the tuple color, style associated with msg_id as defined
        in self.color_mapping
        r   )NNN)rW   KeyError)r1   Zmsg_idr%   r%   r&   _get_decoration   s    z%ColorizedTextReporter._get_decorationc                s   j | jkr^| d\ j r4tdj   }ntdj   }| | | jj  | j\ jf  fdddD |  dS )z_manage message of different types, and colorize output
        using ansi escape codes
        rT   z************* Module %sz************* %sc                s    i | ]}t t| |qS r%   )r*   getattr).0attr)r#   r)   r$   r%   r&   
<dictcomp>   s   z8ColorizedTextReporter.handle_message.<locals>.<dictcomp>)r)   ZsymbolcategoryrO   N)	r6   r/   r_   r*   r9   r<   rO   _replacer;   )r1   r)   Zmodsepr%   )r#   r)   r$   r&   r=      s    

z$ColorizedTextReporter.handle_message)NN)	rB   rC   rD   rE   rF   rV   r-   r_   r=   r%   r%   r%   r&   rM      s   
	rM   c             C   s,   |  t |  t |  t |  t dS )z.Register the reporter classes with the linter.N)Zregister_reporterr+   rH   rL   rM   )r4   r%   r%   r&   register   s    


rf   )NN)NN)rE   Z
__future__r   rX   rI   r[   Zpylint.interfacesr   Zpylint.reportersr   Zpylintr   Z%pylint.reporters.ureports.text_writerr   ZTITLE_UNDERLINESr    r"   r(   r   r   r'   r*   r+   rH   rL   rM   rf   r%   r%   r%   r&   <module>   sF   
"
$;