a
    =ad                   
   @   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lmZ g d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)Message)BaseReporter)
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   sx   g }|r*t |}|D ]}|t|  q| r^|  rP|ddg ||  n|t|   |rtt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.9/site-packages/pylint/reporters/text.py_get_ansi_code>   s    
r'   c                 C   s6   |du r|du r| S t ||}|r2| |  t 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
    N)r'   
ANSI_RESET)msgr#   r$   Zescape_coder%   r%   r&   colorize_ansi`   s    
r*   c                   @   sR   e Zd ZdZeZdZdZdZdddZ	dd	 Z
d
d Zedd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 | _| j| _d S N)r   __init__set_modulesline_format	_templateselfoutputr%   r%   r&   r.      s    zTextReporter.__init__c                 C   s   t | jjjp| j| _d S r-   )strlinterZconfigZmsg_templater2   )r4   modulefilepathr%   r%   r&   on_set_current_module   s    z"TextReporter.on_set_current_modulec                 C   s   |  || j dS )zKConvenience method to write a formatted message with class default templateN)writelnformatr2   r4   r)   r%   r%   r&   write_message   s    zTextReporter.write_messager)   returnc                 C   sJ   |j | jvr<|j r2| d|j   | j|j  n
| d | | dS )z;manage message of different type and in the context of path************* Module %sz************* N)r8   r0   r;   addr>   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<   )r4   Zlayoutr%   r%   r&   _display   s    zTextReporter._display)N)__name__
__module____qualname____doc__r   Z__implements__name	extensionr1   r.   r:   r>   r   rC   rG   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warnrL   r1   DeprecationWarningr+   r.   r3   r%   r%   r&   r.      s    
zParseableTextReporter.__init__)N)rH   rI   rJ   rK   rL   r1   r.   r%   r%   r%   r&   rN      s   rN   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)rH   rI   rJ   rK   rL   r1   r%   r%   r%   r&   rR      s   rR   c                   @   sJ   e Zd ZdZdZddddddd	d
ZdddZdd Zedd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|vrTt	j
dkrTdd l}|| j| _d S )Nzxterm-16colorzxterm-256colorZTERMZwin32r   )r+   r.   dictrS   COLOR_MAPPINGcolor_mappingosenvirongetsysplatformcoloramaZAnsiToWin32rF   )r4   r5   r]   Z
ansi_termsrc   r%   r%   r&   r.      s    
zColorizedTextReporter.__init__c                 C   s*   z| j |d  W S  ty$   Y dS 0 dS )zgReturns the tuple color, style associated with msg_id as defined
        in self.color_mapping
        r   )NNN)r]   KeyError)r4   Zmsg_idr%   r%   r&   _get_decoration   s    z%ColorizedTextReporter._get_decorationr?   c                    s   j | jvr^| d\ j r4tdj   }ntdj   }| | | jj  | j\ jf i  fdddD |  dS )z_manage message of different types, and colorize output
        using ansi escape codes
        rZ   rA   z************* %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categoryrU   N)	r8   r0   re   r*   r;   rB   rU   _replacer>   )r4   r)   Zmodsepr%   ri   r&   rC      s     
z$ColorizedTextReporter.handle_message)NN)
rH   rI   rJ   rK   rL   r\   r.   re   r   rC   r%   r%   r%   r&   rS      s   

	rS   c                 C   s,   |  t |  t |  t |  t dS )z.Register the reporter classes with the linter.N)Zregister_reporterr+   rN   rR   rS   )r7   r%   r%   r&   register   s    


rm   )NN)NN)rK   r^   ra   rO   Zpylintr   Zpylint.interfacesr   Zpylint.messager   Zpylint.reportersr   Z%pylint.reporters.ureports.text_writerr   ZTITLE_UNDERLINESr    r"   r(   r   r   r'   r*   r+   rN   rR   rS   rm   r%   r%   r%   r&   <module>   sJ   

"
$;