3
tûœ]ú  ã            
   @   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-fn42xldr/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 )ÚParseableTextReporterz’a 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   
"
$;