3
^^              
   @   s   d 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 )/zvPlain text reporters:

:text: the default one grouping messages by module
:colorized: an ANSI colorized text reporter
    N)utils)	IReporter)BaseReporter)
TextWriter =-.z[mz[0m0134579)resetboldZitalicZ	underlineZblinkinversestrike3031Z32Z33Z34Z35Z36Z37)	r   ZblackredgreenyellowZbluemagentaZcyanZwhitec             C   s|   g }|r.t j|}x|D ]}|jt|  qW | rb| j rT|jddg |j|  n|jt|   |rxtdj| 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'   7/tmp/pip-build-8app2_gc/pylint/pylint/reporters/text.py_get_ansi_code9   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texttxtz2{path}:{line}:{column}: {msg_id}: {msg} ({symbol})Nc             C   s   t j| | t | _d | _d S )N)r   __init__set_modules	_template)selfoutputr'   r'   r(   r0      s    zTextReporter.__init__c             C   s   t | jjjp| j| _d S )N)strlinterconfigZmsg_templateline_formatr3   )r4   modulefilepathr'   r'   r(   on_set_current_module   s    z"TextReporter.on_set_current_modulec             C   s   | j |j| j dS )zJConvenience method to write a formated message with class default templateN)writelnformatr3   )r4   r+   r'   r'   r(   write_message   s    zTextReporter.write_messagec             C   sJ   |j | jkr<|j r2| jd|j   | jj|j  n
| jd | j| dS )z;manage message of different type and in the context of pathz************* Module %sz************* N)r:   r2   r=   addr?   )r4   r+   r'   r'   r(   handle_message   s    
zTextReporter.handle_messagec             C   s    t | jd t j|| j dS )zlaunch layouts display)fileN)printoutr   r>   )r4   Zlayoutr'   r'   r(   _display   s    zTextReporter._display)N)__name__
__module____qualname____doc__r   Z__implements__name	extensionr9   r0   r<   r?   rA   rE   r'   r'   r'   r(   r-   y   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 jd| j| jf t tj| | d S )NzG%s output format is deprecated. This is equivalent to --msg-template=%s)warningswarnrJ   r9   DeprecationWarningr-   r0   )r4   r5   r'   r'   r(   r0      s
    zParseableTextReporter.__init__)N)rF   rG   rH   rI   rJ   r9   r0   r'   r'   r'   r(   rL      s   rL   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)rF   rG   rH   rI   rJ   r9   r'   r'   r'   r(   rP      s   rP   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	colorizedr   Nr   r   bold, italicr   bold, underliner   r   )ICRWEFSc             C   sX   t j| | |pttj| _ddg}tjjd|krTt	j
dkrTdd l}|j| j| _d S )Nzxterm-16colorzxterm-256colorTERMwin32r   )r-   r0   dictrQ   COLOR_MAPPINGcolor_mappingosenvirongetsysplatformcoloramaAnsiToWin32rD   )r4   r5   r_   Z
ansi_termsre   r'   r'   r(   r0      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   N)NN)r_   KeyError)r4   Zmsg_idr'   r'   r(   _get_decoration   s    z%ColorizedTextReporter._get_decorationc                s   j | jkr^| jd\ j r4tdj   }ntdj   }| j| | jjj  | jj\ jf  fdddD | j d
S )z_manage message of different types, and colorize output
        using ansi escape codes
        rZ   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+   symbolcategoryrU   N)r+   rm   rn   rU   )	r:   r2   rh   r,   r=   r@   rU   _replacer?   )r4   r+   Zmodsepr'   )r%   r+   r&   r(   rA      s    

z$ColorizedTextReporter.handle_message)r   N)Nr   )r   rR   )r   N)r   r   )r   rS   )r   r   )NN)	rF   rG   rH   rI   rJ   r^   r0   rh   rA   r'   r'   r'   r(   rQ      s   
	rQ   c             C   s,   | j t | j t | j t | j t dS )z.Register the reporter classes with the linter.N)Zregister_reporterr-   rL   rP   rQ   )r7   r'   r'   r(   register   s    


rp   )NN)NN)rI   r`   rc   rM   Zpylintr   Zpylint.interfacesr   Zpylint.reportersr   Z%pylint.reporters.ureports.text_writerr   ZTITLE_UNDERLINESr"   r$   r*   r   r!   r)   r,   r-   rL   rP   rQ   rp   r'   r'   r'   r(   <module>   sD   
"
$;