Your IP : 216.73.216.196


Current Path : /opt/alt/python37/lib/python3.7/site-packages/pylint/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/pylint/__pycache__/utils.cpython-37.pyc

B

r�w\���@s�dZddlmZddlZddlZddlmZddlZddlm	Z	m
Z
mZmZm
Z
mZmZddlZddlZddlZddlZddlZddlmZmZddlmZddlmZmZmZmZdd	lmZdd
l m!Z!m"Z"m#Z#ddd
dddd�Z$dd�e$�%�D�Z&ddddddd�Z'dZ(dZ)dZ*dZ+e�,d�Z-dZ.Gdd�d�Z/e�0ddd d!d"d#d$d%d&d'd(d)d*g�Z1Gd+d,�d,e1�Z2d-d.�Z3d/d0�Z4d1d2�Z5dhd4d5�Z6d6d7�Z7d8d9�Z8Gd:d;�d;�Z9Gd<d=�d=�Z:Gd>d?�d?�Z;Gd@dA�dA�Z<GdBdC�dC�Z=dDdE�Z>dFdG�Z?dHdI�Z@GdJdK�dK�ZAdLZBdMdN�ZCdidOdP�ZDdjdQdR�ZEdkdTdU�ZFdVdW�ZGdldZd[�ZHd\d]�ZId^d_�ZJd`da�ZKdmdbdc�ZLddde�ZMeLZNdndfdg�ZOdS)ozVsome various utilities and helper classes, most of them used in the
main pylint class
�)�print_functionN)�cleandoc)�dirname�basename�splitext�exists�isdir�join�normpath)�nodes�Module)�modutils)�IRawChecker�
ITokenChecker�	UNDEFINED�
implements)�Section)�InvalidMessageError�UnknownMessageError�EmptyReportError�infoZ
convention�refactor�warning�error�fatal)�I�C�R�W�E�FcCsi|]\}}||�qS�r!)�.0�k�vr!r!�=/opt/alt/python37/lib/python3.7/site-packages/pylint/utils.py�
<dictcomp>Hsr&�����ZEWRCIFz#\s*#.*\bpylint:\s*([^;#]+)[;#]{0,1}ZFRc@seZdZdZdZdS)�WarningScopezline-based-msgznode-based-msgN)�__name__�
__module__�__qualname__�LINE�NODEr!r!r!r%r,Zsr,�_MsgBase�msg_id�symbol�msgr�category�
confidence�abspath�path�module�obj�line�columnc@s eZdZdZdd�Zdd�ZdS)�Messagez<This class represent a message to be issued by the reportersc	Cs(tj|||||dt|d|f|��S)Nr)r2�__new__�	MSG_TYPES)�clsr3r4�locationr5r7r!r!r%r?us
zMessage.__new__cCs|jftt|j|���S)z�Format the message according to the given template.

        The template format is the one of the format method :
        cf. http://docs.python.org/2/library/string.html#formatstrings
        )�format�dict�zip�_fields)�self�templater!r!r%rC�szMessage.formatN)r-r.r/�__doc__r?rCr!r!r!r%r>rsr>cCs~|��}dg}}xT|rft|t�r*|j}n|�t|dd��y|j��}Wqtk
rbd}YqXqW|��|d�	|�fS)z5return the module name and the frame id in the module��namez<lambda>N�.)
�frame�
isinstancerrK�append�getattr�parent�AttributeError�reverser	)�noderMr:r;r!r!r%�get_module_and_frameid�s

rUcCs|��}|tkr|St�|�S)N)�upperr@�MSG_TYPES_LONG�get)�cidr!r!r%�category_id�srZcOsFy|j|pt��f|�|�Stk
r@|jt��f|�|�SXdS)zAreturn decoded line from encoding or decode with default encodingN)�decode�sys�getdefaultencoding�LookupError)r<�encoding�args�kwargsr!r!r%�safe_decode�srb�strictcCsDyt�|pt���}Wn"tk
r8t�t���}YnX|||�S)N)�codecs�	getreaderr\r]r^)�streamr_�errorsZ
reader_clsr!r!r%�decoding_stream�s
rhc	Cs(|���}|j}tt�|��SQRXdS)N)rf�readline�list�tokenize)r:rfrir!r!r%�tokenize_module�s
rlcCs�t|ttf�rtj}ntj}i}t|�dkr:|\}}}}n4t|�dkrR|\}}}n|\}}t�d|t	�d}|�
d|�t|||||f|�S)N�r*zG[pylint 0.26] description of message %s doesn't include a symbolic name�scope)rrrr,r0r1�len�warnings�warn�DeprecationWarning�
setdefault�MessageDefinition)�checker�msgid�	msg_tupleZ
default_scope�optionsr5r4�descrr!r!r%�build_message_def�s rzc@s0eZdZddd�Zdd�Zdd�Zdd	d
�ZdS)
rtNc

Csv||_t|�dkrtd|��|dtkr>td|d|f��||_||_||_||_||_||_	||_
|	png|_dS)N�zInvalid message id %rrzBad message type %s in %r)rurorr@rvr5ryr4rn�
minversion�
maxversion�	old_names)
rGrurvr5ryr4rnr|r}r~r!r!r%�__init__�szMessageDefinition.__init__cCsd�|j�S)NzMessageDefinition:{})rC�__dict__)rGr!r!r%�__repr__�szMessageDefinition.__repr__cCs8|jdk	r|jtjkrdS|jdk	r4|jtjkr4dSdS)zCreturn True if message may be emitted using the current interpreterNFT)r|r\�version_infor})rGr!r!r%�may_be_emitted�s
z MessageDefinition.may_be_emittedFcCs|j}|r|d|jj7}|j}|jr8d|j|jf}n|j}|jsJ|jr�g}|jrt|�dd�	dd�|jD���|jr�|�dd�	dd�|jD���d	�	|�}|r�|d
|7}n|d|7}t
d�	|���d
d�}|dk�r|��d}d||�
d�|fSd||fS)z/return the help string for the given message idz( This message belongs to the %s checker.z%s (%s)z< %srLcSsg|]}t|��qSr!)�str)r"�nr!r!r%�
<listcomp>sz1MessageDefinition.format_help.<locals>.<listcomp>z>= %scSsg|]}t|��qSr!)r�)r"r�r!r!r%r�sz or z* It can't be emitted when using Python %s.z4 This message can't be emitted when using Python %s.� z  )�indentz%srz:%s: *%s*
%sz:%s:
%s)ryrurKr5r4rvr|r}rOr	�_normalize_text�split�
splitlines�rstrip)rG�
checkerref�desc�titlervZrestrr!r!r%�format_help�s,  

zMessageDefinition.format_help)NNN)F)r-r.r/rr�r�r�r!r!r!r%rt�s	
rtc@s�eZdZdZgZdd�Zdd�Zedd��Zedd	��Z	d(dd�Z
d)dd�Zd*dd�Zd+dd�Z
dd�Zdd�Zdefdd�Zd,dd�Zdd�Zdddedfd d!�Zd"d#�Zd-d$d%�Zed.d&d'��ZdS)/�MessagesHandlerMixInz[a mix-in class containing all the messages related methods for the main
    lint class
    cCsi|_d|_dS)Nr)�_msgs_state�
msg_status)rGr!r!r%rszMessagesHandlerMixIn.__init__ccs2x,|j|��D]}x|jD]
}|VqWqWdS)N)�	_checkers�lower�msgs)rGruZ
known_checkerrvr!r!r%�_checker_messages sz&MessagesHandlerMixIn._checker_messagescCs|j��dS)N)�)_MessagesHandlerMixIn__by_id_managed_msgs�clear)rAr!r!r%�clear_by_id_managed_msgs%sz-MessagesHandlerMixIn.clear_by_id_managed_msgscCs|jS)N)r�)rAr!r!r%�get_by_id_managed_msgs)sz+MessagesHandlerMixIn.get_by_id_managed_msgsTcCs^yD|j�|�}x2|D]*}||jkrtj�|j|j|j||f�qWWntk
rXYnXdS)zuIf the msgid is a numeric one, then register it to inform the user
        it could furnish instead a symbolic msgid.N)	�
msgs_store�get_message_definitionsrvr�r�rO�current_namer4r)rGrvr<�is_disabled�message_definitions�message_definitionr!r!r%�_register_by_id_managed_msg-s

z0MessagesHandlerMixIn._register_by_id_managed_msg�packageNFcCs$|j|d|||d�|�||�dS)z$don't output message of the given idF)�enablernr<�ignore_unknownN)�_set_msg_statusr�)rGrvrnr<r�r!r!r%�disable@szMessagesHandlerMixIn.disablecCs(|j|d|||d�|j||dd�dS)z reenable message of the given idT)r�rnr<r�F)r�N)r�r�)rGrvrnr<r�r!r!r%r�GszMessagesHandlerMixIn.enablecCsj|dkst�|dkrLxtD]}|�|||||�qW|rH|jsH|�d�dSt|�}|dk	r�x&|jj�|�D]}|�||||�qlWdS|�	�|j
kr�|j}x@|j
|�	�D].}	x(|	jD]}||jkr�|�||||�q�Wq�WdS|�	��
d��r|�r|�|�n
|�|�dSy|j�|�}
Wn"tk
�rD|�r>dS�YnXx|
D]}|�||||��qLWdS)N)r�r:�all�python3Zrp)�AssertionErrorr@r�Z_python3_porting_moder�rZr��_msgs_by_categoryrXr�r�r��_alternative_names�
startswith�
enable_report�disable_reportr�r�_set_one_msg_status)rGrvr�rnr<r�Z_msgidZcatidr�rur�r�r!r!r%r�Ns@





z$MessagesHandlerMixIn._set_msg_statuscs�|dkr@�j�|||�|s�|jdkr��jd||j|jfd�nL�j}|||j<�fdd�t|���D��j_	�fdd�t|���D��j_
dS)Nr:zlocally-disabled)r<r`csg|]\}}|r��|��qSr!)�_message_symbol)r"�mid�val)rGr!r%r��sz<MessagesHandlerMixIn._set_one_msg_status.<locals>.<listcomp>csg|]\}}|s��|��qSr!)r�)r"r�r�)rGr!r%r��s)�
file_state�set_msg_statusr4�add_messagervr��sorted�items�configr�r�)rGrnr5r<r�r�r!)rGr%r�}s

z(MessagesHandlerMixIn._set_one_msg_statuscCs0ydd�|j�|�D�Stk
r*|SXdS)z�Get the message symbol of the given message id

        Return the original message id if the message does not
        exist.
        cSsg|]
}|j�qSr!)r4)r"�mdr!r!r%r��sz8MessagesHandlerMixIn._message_symbol.<locals>.<listcomp>N)r�r�r)rGrvr!r!r%r��sz$MessagesHandlerMixIn._message_symbolc	CsP|jjr|j|jjkrtSy||jj|kr0tSWnttfk
rJt	SXdS)z:Returns the scope at which a message was enabled/disabled.N)
r�r7rK�MSG_STATE_CONFIDENCEr��_module_msgs_state�MSG_STATE_SCOPE_MODULE�KeyError�	TypeError�MSG_STATE_SCOPE_CONFIG)rGrvr<r7r!r!r%�get_message_state_scope�sz,MessagesHandlerMixIn.get_message_state_scopecCsz|jjr|r|j|jjkrdSy|j�|�}dd�|D�}Wntk
rV|g}YnXx|D]}|�||�r^dSq^WdS)z�return true if the message associated to the given message id is
        enabled

        msgid may be either a numeric or symbolic message id.
        FcSsg|]
}|j�qSr!)rv)r"r�r!r!r%r��sz;MessagesHandlerMixIn.is_message_enabled.<locals>.<listcomp>T)r�r7rKr�r�r�is_one_message_enabled)rG�	msg_descrr<r7r��msgidsrvr!r!r%�is_message_enabled�s
z'MessagesHandlerMixIn.is_message_enabledc	s��dkr|j�|d�Sy|jj|�Stk
r�|j��}|r��|kr�d}|jj�|i�}t�fdd�|��D��}t	|d�\}}|dk	r�|}|j�||�S|j�|d�SXdS)NTcs g|]\}}|�kr||f�qSr!r!)r"Zmessage_liner�)r<r!r%r��sz?MessagesHandlerMixIn.is_one_message_enabled.<locals>.<listcomp>)NN)
r�rXr�r�r��get_effective_max_line_number�_raw_module_msgs_state�reversedr��next)	rGrvr<Zmax_line_number�fallback�linesZ
closest_lines�	last_lineZ
is_enabledr!)r<r%r��s"

z+MessagesHandlerMixIn.is_one_message_enabledc		Cs2|j�|�}x |D]}|�||||||�qWdS)a,Adds a message given by ID or name.

        If provided, the message string is expanded using args.

        AST checkers must provide the node argument (but may optionally
        provide line if the line number is different), raw and token checkers
        must provide the line argument.
        N)r�r��add_one_message)	rGr�r<rTr`r7�
col_offsetr�r�r!r!r%r��s
z MessagesHandlerMixIn.add_messagecCs�|j}|jp|}|dtkrx|jtjkrX|dkr<td|��|dk	rxtd|||f��n |jtjkrx|dkrxtd|��|dkr�|dk	r�|j}|dkr�t	|d�r�|j
}|�|||�s�|j�
|�|||�|||||�dSt|d}	|jt|dO_|j|	d7<|jd|j|	d7<y|jd|d7<Wn$tk
�rfd|jd|<YnX|j}
|�r||
|;}
|dk�r�|jd	}}|j}
nt|�\}}|��j}
|
�|jjd	d�}|j�t|||
||||�p�d|�p�df|
|��dS)
Nrz&Message %s must provide line, got Nonez7Message %s must only provide line, got line=%s, node=%sz&Message %s must provide Node, got Noner�r+Z	by_moduleZby_msgrJ)rvr4�
_SCOPE_EXEMPTrnr,r0rr1�
fromlineno�hasattrr�r�r��handle_ignored_messager�r@r��MSG_TYPES_STATUS�statsr�r�r5Zcurrent_filerU�root�file�replace�reporterZpath_strip_prefixZhandle_messager>)rGr�r<rTr`r7r�rvr4Zmsg_catr5r:r;r8r9r!r!r%r��sh




z$MessagesHandlerMixIn.add_one_messagec		Cs|s
tj}td|d�td|d�td|d�td|d�td|d�i}�x|��D�]}|jdkr�|jr�x�|��D]Z\}}|dkr�d}nd	|��}t||d�td
t|�|d�t	|d|�td|d�qvWqV|j}yF||d|�
�7<||d�|j�||d
|j
7<WqVtk
�r\t|�
��t|j�t|j
�d�||<YqVXqVWtd|d�td|d�td|d�td|d�td|d�td|d�td|d�td|d�td|d�td|d�td|d�x*t|���D]\}}|j|||d��q�WdS)z*output a full documentation in ReST formatz"Pylint global options and switches)r�z"----------------------------------rJz,Pylint provides global options and switches.ZmasterNzGeneral optionsz
%s options�~rxr��reports)rxr�r�z%Pylint checkers' options and switchesz%-------------------------------------z2Pylint checkers can provide three set of features:z'* options that control their execution,z* messages that they can raise,z!* reports that they can generate.z3Below is a list of all checkers and their features.)rf)r\�stdout�printZget_checkersrKrxZoptions_by_section�
capitalizero�_rest_format_sectionZoptions_and_values�updater�r�r�rjrDr�r��_print_checker_doc)	rGrfZ
by_checkerru�sectionrxr�rKrr!r!r%�print_full_documentation?sR

z-MessagesHandlerMixIn.print_full_documentationc
CsH|s
tj}|�d�}|�d�}|�d�}|�d�}|�d�}d|�dd���}|rdtd	||d
�t||d
�tdt|�|d
�td|d
�|r�td
||d
�td||d
�td|d
�|�rd�|�}	t|	|d
�tdt|	�|d
�tt|�|d
�td|d
�|�rTd�|�}	t|	|d
�tdt|	�|d
�t	|d|�td|d
�|�r�d�|�}	t|	|d
�tdt|	�|d
�xBt
|��dd�d�D]*\}
}t||
|�}t|j
dd�|d
��q�Wtd|d
�|�r8d�|�}	t|	|d
�tdt|	�|d
�x&|D]}td|dd�|d
��q
Wtd|d
�td|d
�dS)ziHelper method for print_full_documentation.

        Also used by doc/exts/pylint_extensions.py.
        �docr:r�rxr�z
%s checker�_r�z.. _%s:
)r�r�rJz#This checker is provided by ``%s``.z'Verbatim name of the checker is ``%s``.z{} Documentation�^z
{} OptionsNz{} MessagescSst�|dd�|dfS)Nrr+)�
_MSG_ORDER�index)Zkvr!r!r%�<lambda>��z9MessagesHandlerMixIn._print_checker_doc.<locals>.<lambda>)�keyF)r�z
{} Reportsz:%s: %sr*)r\r�rXr�r�r�rorCrr�r�r�rzr�)
Zchecker_namerrfr�r:r�rxr�Z
checker_titler�rvr5�reportr!r!r%r�ss\









z'MessagesHandlerMixIn._print_checker_doc)T)r�NF)r�NF)r�NF)NN)N)N)r-r.r/rIr�rr��classmethodr�r�r�r�r�r�r�r�rr�r�r�r�r�r��staticmethodr�r!r!r!r%r�s0



.
"L
4r�c@sJeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�	FileStatez;Hold internal state specific to the currently analyzed fileNcCs.||_i|_i|_t�t�|_i|_d|_dS)N)	�	base_namer�r��collections�defaultdict�set�
_ignored_msgs�_suppression_mapping�_effective_max_line_number)rG�modnamer!r!r%r�szFileState.__init__cCsVx$|j��D]\}}|��|j|<qW|j��}i|_i|_|j|_|�|||�dS)z9Walk the AST to collect block level options line numbers.N)r�r��copyr�r��tolinenor��_collect_block_lines)rGr�Zmodule_noder5r�Z
orig_stater!r!r%�collect_block_lines�s
zFileState.collect_block_linescCs�x|��D]}|�|||�q
W|j}|j}t|tjtjtjf�rV|j	rV|j	dj}n|}�x&|�
�D�]\}}	�xt|	�
��D]�\}
}|
}||
ks�||
kr�q�|�|�}
x<|
D]4}|j
tjkr�|
|kr�d}|�|
�\}}q�|
}|}q�Wx�t||d�D]|}||j�|d�k�rq�||	k�r&|	|}|}|�s:||j||f<y||j||<Wq�tk
�rp||i|j|<Yq�Xq�W|	|
=q�WqfWdS)z`Recursively walk (depth first) AST to collect block level options
        line numbers.
        rTr+r!N)�get_childrenr�r�r�rNrrZClassDefZFunctionDef�bodyr�rjr�rnr,r1Zblock_range�ranger�rXr�r�)rGr�rTZ	msg_state�child�first�lastZfirstchildlinenorvr��lineno�stateZoriginal_linenor�r�Zfirst_Zlast_r<r!r!r%r��sD


zFileState._collect_block_linescCsJ|dkst�y||j|j|<Wn$tk
rD||i|j|j<YnXdS)z@Set status (enabled/disable) for a given message at a given linerN)r�r�rvr�)rGr5r<�statusr!r!r%r�s
zFileState.set_msg_statuscCsH|tkrDy&|j||f}|j||f�|�Wntk
rBYnXdS)aReport an ignored message.

        state_scope is either MSG_STATE_SCOPE_MODULE or MSG_STATE_SCOPE_CONFIG,
        depending on whether the message was disabled locally in the module,
        or globally. The other arguments are the same as for add_message.
        N)r�r�r��addr�)rGZstate_scopervr<rTr`r7Z	orig_liner!r!r%r�	s	z FileState.handle_ignored_messageccs�xR|j��D]D\}}x:|��D].\}}|s||f|jkrd||�|�ffVqWqWxBt|j���D]0\\}}}x"|D]}d||�|�|ffVqvWqdWdS)Nzuseless-suppressionzsuppressed-message)r�r�r��get_msg_display_stringrj)rGr�rr�r<r��from_r!r!r%�"iter_spurious_suppression_messagess
z,FileState.iter_spurious_suppression_messagescCs|jS)N)r�)rGr!r!r%r�(sz'FileState.get_effective_max_line_number)N)r-r.r/rIrr�r�r�r�rr�r!r!r!r%r��s

=r�c@s�eZdZdZdd�Zedd��Zdd�Zedd	��Z	d
d�Z
dd
�Zedd��Zdd�Z
dd�Zdd�Zdd�Zedd��Zedd��Zeed�dd�Zdd �Zd!d"�Zd#d$�Zd%S)&�
MessagesStorezwThe messages store knows information about every possible message but has
    no particular state during analysis.
    cCsi|_i|_t�t�|_dS)N)�_messages_definitionsr�r�r�rjr�)rGr!r!r%r1szMessagesStore.__init__cCs
|j��S)z The list of all active messages.)r	�values)rGr!r!r%�messages?szMessagesStore.messagescCs0|�|�d}|j�||f�|�|||�dS)z�Register the old ID and symbol for a warning that was renamed.

        This allows users to keep using the old ID/symbol in suppressions.
        rN)r�r~rO�_register_alternative_name)rG�old_id�
old_symbolZ
new_symbolr�r!r!r%�add_renamed_messageDsz!MessagesStore.add_renamed_messagecCs:g}x0t|j���D]\}}t|||�}|�|�qW|S)z�Return the list of messages definitions for a checker.

        :param BaseChecker checker:
        :rtype: list
        :return: A list of MessageDefinition.
        )r�r�r�rzrO)rur�rvrw�messager!r!r%�get_checker_message_definitionsMs
z-MessagesStore.get_checker_message_definitionscCs0|�|�}|�|�x|D]}|�|�qWdS)zSRegister all messages from a checker.

        :param BaseChecker checker:
        N)r�_check_checker_consistency�register_message)rGruZchecker_message_definitionsr�r!r!r%�register_messages_from_checker[s


z,MessagesStore.register_messages_from_checkercCs�|�|j|j�|�|j|j�|�|j|j�x |jD]}|�|j|d�q8W||j|j<|�||j|j�x |jD]\}}|�|||�qxW|j|jd�	|j�dS)z�Register a MessageDefinition with consistency in mind.

        :param MessageDefinition message: The message definition being added.
        r+rN)
� _check_id_and_symbol_consistencyrvr4�
_check_symbol�_check_msgidr~r	rr�rO)rGrZold_namer
rr!r!r%reszMessagesStore.register_messagecCs~d}g}xp|D]h}|dk	r\||jdd�kr\d}|dj|j|d�7}|dj|d�7}t|��|jdd�}|�|j�qWdS)	a�Check the msgid consistency in a list of messages definitions.

        msg ids for a checker should be a string of len 4, where the two first
        characters are the checker id and the two last the msg id in this
        checker.

        :param list messages: List of MessageDefinition.
        :raises InvalidMessageError: If the checker id in the messages are not
        always the same
        Nr+rmz(Inconsistent checker part in message id z!'{}' (expected 'x{checker_id}xx' )�
checker_idz'because we already had {existing_ids}).)�existing_ids)rvrCrrO)rrrr�	error_msgr!r!r%rus

z(MessagesStore._check_checker_consistencycCs$|�||�||j|<||j|<dS)zhelper for register_message()N)rr�)rGr5rvr4r!r!r%r�s
z(MessagesStore._register_alternative_namecCs�|j�|�}|r"|�|||j�nd}|j�|�}|r�|j|krH|j}n"x |jD]\}}||krP|}PqPW||kr�|�|||�dS)z)Check that a symbol is not already used. N)r	rX�_raise_duplicate_msg_idrvr�r4r~)rGrvr4Z
other_messageZalternative_msgidZalternative_messageZ	old_msgidrr!r!r%r�s
zMessagesStore._check_symbolcCs2x,|j��D]}|j|kr|�|||j�qWdS)N)r	r
rv�_raise_duplicate_symbolr4)rGrvr4rr!r!r%r�s
zMessagesStore._check_msgidcCs�y|j|}Wntk
r&d}YnXy|s8|j|}Wntk
rNdSXd}d}x*|jD] \}}||ksx||kr`|}|}q`W||j|fkr�||kr�|�|||�n|�|||j�dS)NF)r�r�r~r4r)rGrvr4�alternativeZold_symbolic_nameZold_symbolic_idZalternate_msgidZalternate_symbolr!r!r%r�s(
z.MessagesStore._check_id_and_symbol_consistencycCsB||g}|��dj|d�}|dj|d|dd�7}t|��dS)aRaise an error when a symbol is duplicated.

        :param str msgid: The msgid corresponding to the symbols
        :param str symbol: Offending symbol
        :param str other_symbol: Other offending symbol
        :raises InvalidMessageError: when a symbol is duplicated.
        z&Message id '{msgid}' cannot have both )rvz1'{other_symbol}' and '{symbol}' as symbolic name.rr+)�other_symbolr4N)�sortrCr)rvr4r�symbols�
error_messager!r!r%r�s	z%MessagesStore._raise_duplicate_symbolcCsB||g}|��dj|d�}|dj|d|dd�7}t|��dS)aRaise an error when a msgid is duplicated.

        :param str symbol: The symbol corresponding to the msgids
        :param str msgid: Offending msgid
        :param str other_msgid: Other offending msgid
        :raises InvalidMessageError: when a msgid is duplicated.
        z-Message symbol '{symbol}' cannot be used for )r4z/'{other_msgid}' and '{msgid}' at the same time.rr+)�other_msgidrvN)rrCr)r4rvr"r�r!r!r!r%r�s	z%MessagesStore._raise_duplicate_msg_id)�msgid_or_symbol�returnc	Csf|dd���r|��}x4|j|jfD]$}y
||gStk
rHYq&Xq&Wdj|d�}t|��dS)aJReturns the Message object for this message.

        :param str msgid_or_symbol: msgid_or_symbol may be either a numeric or symbolic id.
        :raises UnknownMessageError: if the message id is not defined.
        :rtype: List of MessageDefinition
        :return: A message definition corresponding to msgid_or_symbol
        r+Nz1No such message id or symbol '{msgid_or_symbol}'.)r#)�isdigitrVr�r	r�rCr)rGr#�sourcerr!r!r%r��s

z%MessagesStore.get_message_definitionscCs6|�|�}t|�dkr$t|dj�Stdd�|D��S)zGenerates a user-consumable representation of a message.

        Can be just the message ID or the ID and the symbol.
        r+rcSsg|]
}|j�qSr!)r4)r"r�r!r!r%r�sz8MessagesStore.get_msg_display_string.<locals>.<listcomp>)r�ro�reprr4)rGrvr�r!r!r%r�s
z$MessagesStore.get_msg_display_stringcCsxxr|D]j}y0x*|�|�D]}t|jdd��td�qWWqtk
rn}zt|�td�wWdd}~XYqXqWdS)z7Display help messages for the given message identifiersT)r�rJN)r�r�r�r)rGr�rvr��exr!r!r%�help_message	s
zMessagesStore.help_messagecCsJt|j��dd�d�}x&|D]}|��s*qt|jdd��qWtd�dS)z8Output full messages list documentation in ReST format. cSs|jS)N)rv)�mr!r!r%r�r�z-MessagesStore.list_messages.<locals>.<lambda>)r�F)r�rJN)r�r	r
r�r�r�)rGrrr!r!r%�
list_messagess
zMessagesStore.list_messagesN)r-r.r/rIr�propertyrrr�rrrrrrrrrrr�rjr�rr)r+r!r!r!r%r,s$	

rc@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�ReportsHandlerMixInzqa mix-in class containing all the reports and stats manipulation
    related methods for the main lint class
    cCst�t�|_i|_dS)N)r�r�rj�_reports�_reports_state)rGr!r!r%r$szReportsHandlerMixIn.__init__cCs
t|j�S)z] Return a list of reports, sorted in the order
        in which they must be called.
        )rjr.)rGr!r!r%�report_order(sz ReportsHandlerMixIn.report_ordercCs"|��}|j|�|||f�dS)z�register a report

        reportid is the unique identifier for the report
        r_title the report's title
        r_cb the method to call to make the report
        checker is the checker defining the report
        N)rVr.rO)rG�reportid�r_title�r_cbrur!r!r%�register_report.sz#ReportsHandlerMixIn.register_reportcCs|��}d|j|<dS)z"disable the report of the given idTN)rVr/)rGr1r!r!r%r�9sz!ReportsHandlerMixIn.enable_reportcCs|��}d|j|<dS)z"disable the report of the given idFN)rVr/)rGr1r!r!r%r�>sz"ReportsHandlerMixIn.disable_reportcCs|j�|d�S)zXreturn true if the report associated to the given identifier is
        enabled
        T)r/rX)rGr1r!r!r%�report_is_enabledCsz%ReportsHandlerMixIn.report_is_enabledc	
Cs�tdd|jd�}xv|��D]j}xd|j|D]V\}}}|�|�sDq.t|�}y||||�Wntk
rrw.YnX||_|�|�q.WqW|S)zrender registered reportsZReportz%s statements analysed.Z	statement)rr�r0r.r5rZ	report_idrO)	rGr�Z	old_stats�sectrur1r2r3Zreport_sectr!r!r%�make_reportsIs
z ReportsHandlerMixIn.make_reportscKsLxD|��D]8\}}|ddkr*|dd�}||jks8t�||j|<q
W|jS)zvadd some stats entries to the statistic dictionary
        raise an AssertionError if there is a key conflict
        ���r�N)r�r�r�)rGrar��valuer!r!r%�	add_statsYszReportsHandlerMixIn.add_statsN)r-r.r/rIrr0r4r�r�r5r7r:r!r!r!r%r-sr-cCs x|D]}|�|�rdSqWdS)aIDetermines if the basename is matched in a regex blacklist

    :param str base_name: The basename of the file
    :param list black_list_re: A collection of regex patterns to match against.
        Successful matches are blacklisted.

    :returns: `True` if the basename is blacklisted, `False` otherwise.
    :rtype: bool
    TF)�match)r��
black_list_reZfile_patternr!r!r%�_basename_in_blacklist_rees


r=cs�fdd�}tj||d�S)Ncst�||�p�S)N)r
Zcheck_modpath_has_init)r9�parts)�is_namespacer!r%�_is_package_cbvsz*_modpath_from_file.<locals>._is_package_cb)Z
is_package_cb)r
Zmodpath_from_file_with_callback)�filenamer?r@r!)r?r%�_modpath_from_fileusrBcCs"g}g}�x|D�]}tj�|�|kr(qttj�|�|�r<qt|�r�yd�t�|��}Wn$tk
r|t	t|��d}YnXt
|�r�t|d�}q�|}n^|}yt�|�d��}|dkr�wWn:tt
fk
r�}z|�d||d��wWdd}~XYnXt|�}|�p|�d�}	ytj|	tjd�}
Wn"tk
�rDd}t
|�}YnXt�|
�}t�|
�}|�sv|�||d	||d
��|�d��p�|dk�o�t|�dk}
|
�s�|�s�|rxjtjt|�||d
�D]R}||k�rҐq�tt|�|��r�q�t||�}d�|�}|�||d||d
���q�WqW||fS)z�take a list of files/modules/packages and return the list of tuple
    (file, module name) which have to be actually checked
    rLrz__init__.pyNr)r��modr()r9FT)r9rKZisargZbasepathrz	.__init__r)Zlist_all)�osr9rr=rr	r
Zmodpath_from_file�ImportErrorrrZfile_from_modpathr��SyntaxErrorrOr
Zfile_info_from_modpathr\r?�is_directory�endswithZget_module_filesrrB)Zfiles_or_modulesZ
black_listr<�resultrgZ	somethingr��filepathr(Zmodparts�specr?rGZhas_initZsubfilepathZmodpathZ
submodnamer!r!r%�expand_modules~sr





rLc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�PyLintASTWalkercCs(d|_t�t�|_t�t�|_||_dS)Nr)�nbstatementsr�r�rj�visit_events�leave_events�linter)rGrQr!r!r%r�szPyLintASTWalker.__init__cCs2t|d�sdSx|jD]}|j�|�rdSqWdS)N�checks_msgsTF)r�rRrQr�)rG�methodZmsg_descr!r!r%�_is_method_enabled�s
z"PyLintASTWalker._is_method_enabledcCs�t�}t�}|j}|j}x�t|�D]�}|dd�}|dkr<q"|�d�rtt||�}|�|�r�||�|�|�|�q"|�d�r"t||�}	|�|	�r"||�|	�|�|�q"Wt|dd�}
|
r�x.t	j
D]$}|j��}||kr�||�|
�q�WdS)z=walk to the checker's dir and collect visit and leave methods�N�defaultZvisit_Zleave_�
visit_default)
r�rOrP�dirr�rPrTrOrrZALL_NODE_CLASSESr-r�)rGruZvcidsZlcidsZvisitsZleaves�memberrYZv_methZl_methrWrAr!r!r%�add_checker�s0






zPyLintASTWalker.add_checkercCs�|jj��}|j�|d�}|j�|d�}|jr<|jd7_x|pDdD]}||�qFWx|��D]}|�	|�q`Wx|pzdD]}||�q|WdS)zvcall visit events of astroid checkers for the given node, recurse on
        its children, then leave events.
        r!r+N)
�	__class__r-r�rOrXrPZis_statementrNr��walk)rG�astroidrYrOrP�cbr�r!r!r%r\szPyLintASTWalker.walkN)r-r.r/rrTrZr\r!r!r!r%rM�srM)z.pyz.pycz.pyoz.pywz.soz.dllcCs�i}x�t�|�D]�}t|�\}}||ks|dkr2q|tkrB|dksT|stt||��ryt�t||��}WnLtk
r~wYqt	k
r�}zt
d||ftjd�Wdd}~XYqXt
|d�r|�|�d||<qWdS)z�load all module and package in the given directory, looking for a
    'register' function in each one, used to register pylint checkers
    �__pycache__rzProblem importing module %s: %s)r�N�registerr+)rD�listdirr�PY_EXTSrr	r
Zload_module_from_file�
ValueErrorrEr�r\�stderrr�r`)rQ�	directoryZimportedrA�base�	extensionr:�excr!r!r%�register_pluginss$&

ricCspyt|j|�dd��Stk
r(YnXx@|jjD]4}x.|jD]$}|d|kr@t|j|�dd��Sq@Wq4W|S)a Retrieve an option defined by the given *checker* or
    by all known option providers.

    It will look in the list of all options providers
    until the given *option* will be found.
    If the option wasn't found, the *default* value will be returned.
    �-r�r)rPr�r�rRrQZoptions_providersrx)ru�optionrVZproviderrxr!r!r%�get_global_option<srlcs.�fdd�}|d|d|dd�}|r*||d<|S)Ncs�rtj��|f�dS)N)r\rd�write)rk�optnamer`)�deprecation_msgr!r%�_warn_deprecatedUsz+deprecated_option.<locals>._warn_deprecatedT�callback)�helpZhide�type�actionrqZ
deprecated�	shortnamer!)ruZopt_type�help_msgrorprkr!)ror%�deprecated_optionRsrw�,cCsdd�|�|�D�S)a%return a list of stripped string by splitting the string given as
    argument on `sep` (',' by default). Empty string are discarded.

    >>> _splitstrip('a, b, c   ,  4,,')
    ['a', 'b', 'c', '4']
    >>> _splitstrip('a')
    ['a']
    >>> _splitstrip('a,
b,
c,')
    ['a', 'b', 'c']

    :type string: str or unicode
    :param string: a csv line

    :type sep: str or unicode
    :param sep: field separator, default to the comma (',')

    :rtype: str or unicode
    :return: the unquoted string (or the input string if it wasn't quoted)
    cSsg|]}|��r|���qSr!)�strip)r"�wordr!r!r%r�zsz_splitstrip.<locals>.<listcomp>)r�)�string�sepr!r!r%�_splitstripfsr}cCs<|s|S|ddkr |dd�}|ddkr8|dd�}|S)z�remove optional quotes (simple or double) from the string

    :type string: str or unicode
    :param string: an optionally quoted string

    :rtype: str or unicode
    :return: the unquoted string (or the input string if it wasn't quoted)
    rz"'r+Nr8r!)r{r!r!r%�_unquote}s	r~�PrJcCsd�tj||||d��S)z'Wrap the text on the given line length.�
)�width�initial_indent�subsequent_indent)r	�textwrap�wrap)�text�line_lenr�r!r!r%r��sr�cCst|ttf�r|St|�S)N)rNrj�tupler})r9r!r!r%�
_check_csv�sr�cCs&dd�|��D�}ddtj�|�S)zreturn string as a commentcSsg|]}|���qSr!)ry)r"r<r!r!r%r��sz_comment.<locals>.<listcomp>z# z%s# )r�rD�linesepr	)r{r�r!r!r%�_comment�sr�cs�t|ttf�r(d��fdd�|D��}nlt|t�rLd�dd�|��D��}nHt|d�r^|j}n6��d�dkrz|rtdnd	}nt|t	�r�|�
�r�d
|}|S)z5return the user input's value from a 'compiled' valuerxc3s|]}t�|�VqdS)N)�_format_option_value)r"�item)�optdictr!r%�	<genexpr>�sz'_format_option_value.<locals>.<genexpr>css|]\}}d||fVqdS)z%s:%sNr!)r"r#r$r!r!r%r��sr;rsZyn�yes�noz'%s')rNrjr�r	rDr�r��patternrXr��isspace)r�r9r!)r�r%r��s

r�cCs2|rtt|�|d�td||d�t||�dS)z.format an options section using the INI format)r�z[%s]N)r�r��_ini_format)rfr�rxr�r!r!r%�_ini_format_section�sr�cCs�x�|D]�\}}}t||�}|�d�}|rNt|ddd�}t|d�t||d�n
t|d�|dkrrtd||d�qt|���}t�dt|��r�d	d
t|�}|�	dd�t|��
d
�D��}|dd�}td||f|d�qWdS)z#format options using the INI formatrr�Oz# )r�r�)r�Nz#%s=z^([\w-]+,)+[\w-]+$z
 r�css|]}|dVqdS)rxNr!)r"�xr!r!r%r��sz_ini_format.<locals>.<genexpr>rxr8z%s=%s)r�rXr�r�r�ry�rer;ror	r�)rfrxrnr�r9�help_opt�	separatorr!r!r%r��s 



r�cCs�|r td|dt|�f|d�|rDtt|ddd�|d�t|d�x~|D]v\}}}|�d�}td||d�|r�t|dd	d�}t||d�|rJtt||��}t|d�td
|�dd�|d�qJWd
S)z8format an options section using as ReST formatted outputz%s
%s�')r�r�rJ)r�r�rrz:%s:z  z  Default: ``%s``z`` z```` ``N)r�ror�rXr�r�r�)rfr�rxr�rnr�r9r�r!r!r%r��s


r�)rc)N)NNNN)rx)rrJ)N)N)PrI�
__future__rrdr��inspectrrD�os.pathrrrrrr	r
r�r\rkrpr�r]rrr
Zpylint.interfacesrrrrZpylint.reporters.ureports.nodesrZpylint.exceptionsrrrr@r�rWr�r�r�r�r��compileZ
OPTION_RGXr�r,�
namedtupler2r>rUrZrbrhrlrzrtr�r�rr-r=rBrLrMrbrirlrwr}r~r�r�r�r�r�r�Zformat_sectionr�r!r!r!r%�<module>*s�$

C}tF	VH