Your IP : 216.73.217.32


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

B

A!p\E��@sVdZddlZddlZddlZddlmZddlmZddlm	Z	m
Z
mZddlm
Z
ddlmZddlmZmZd	Zd
ddd
ddddgZddd
ddd
dddddddg
Zejdkr�e�d�dddddd d!d"d#d$d%d&d'd(d)d*d+d,d-gZd.d/d0gZd1d2d3gZd4Zeejejejg�Z ejejfZ!dZ"d5Z#d6Z$d7Z%d8Z&d9Z'e&e%e'gZ(e&e%gZ)d:d;d<d=d>d?d@dAdBdCdDdEdFej*ifdGdHdIdJdKdLdMdNgifdOdPdQ�Z+dRdS�Z,dTdU�Z-dVdW�Z.dXdY�Z/dZd[�Z0d\d]�Z1d^d_�Z2Gd`da�da�Z3dbZ4dcZ5ddZ6deZ7dfZ8dgZ9dhZ:e4die5dje6dke7dle8dmiZ;dnZ<dodp�Z=dqdr�Z>Gdsdt�dt�Z?Gdudv�dv�Z@Gdwdx�dxe
�ZAdydz�ZBd{d|�ZCdS)}z�Python code format's checker.

By default try to follow Guido's style guide :

https://www.python.org/doc/essays/styleguide/

Some parts of the process_token method is based from The Tab Nanny std module.
�N)�reduce)�nodes)�
ITokenChecker�IAstroidChecker�IRawChecker)�BaseTokenChecker)�check_messages)�WarningScope�
OPTION_RGX�async�elif�except�for�if�while�def�class�with�assert�del�in�not�raise�return�yield)�r�printz==�<�>z!=z<>z<=z>=z+=z-=z*=z**=z/=z//=z&=z|=z^=z%=z>>=z<<=�(�[�{�)�]�}���zdict-separatorztrailing-commaz
empty-line)zLine too long (%s/%s)z
line-too-longz=Used when a line is longer than a given number of characters.)z Too many lines in module (%s/%s)ztoo-many-linesz@Used when a module has too many lines, reducing its readability.)zTrailing whitespaceztrailing-whitespacezHUsed when there is whitespace between the end of a line and the newline.)zFinal newline missingzmissing-final-newlinez7Used when the last line in a file is missing a newline.)zTrailing newlinesztrailing-newlinesz3Used when there are trailing blank lines in a file.)z)Bad indentation. Found %s %s, expected %szbad-indentationzUUsed when an unexpected number of indentation's tabulations or spaces has been found.)zWrong %s indentation%s%s.
%s%szbad-continuationZTODO)z)Found indentation with %ss instead of %sszmixed-indentationz;Used when there are some mixed tabs and spaces in a module.)zUnnecessary semicolonzunnecessary-semicolonzeUsed when a statement is ended by a semi-colon (";"), which isn't necessary (that's python, not C ;).z(More than one statement on a single linezmultiple-statementsz<Used when more than on statement are found on the same line.Zscope)z#Unnecessary parens after %r keywordzsuperfluous-parenszLUsed when a single item in parentheses follows an if, for, or other keyword.z%s space %s %s %s
%szbad-whitespacezWUsed when a wrong number of spaces is used around an operator, bracket or block opener.Z	old_names)ZC0323zno-space-after-operator)ZC0324zno-space-after-comma)ZC0322zno-space-before-operator)zMixed line endings LF and CRLFzmixed-line-endingsz@Used when there are mixed (LF and CRLF) newline signs in a file.)zEUnexpected line ending format. There is '%s' while it should be '%s'.zunexpected-line-ending-formatz3Used when there is different newline than expected.)ZC0301ZC0302ZC0303ZC0304ZC0305ZW0311ZC0330ZW0312ZW0301ZC0321ZC0325ZC0326ZC0327ZC0328cCsT|dd|dd}|dd}|d}|ddkr@|d7}|d|d|S)	Nrr&r'�����
� �^�)�token�length�offsetZreferenced_liner-r-�G/opt/alt/python37/lib/python3.7/site-packages/pylint/checkers/format.py�_underline_token�sr2cCsZ||krdS|d|dkr&||}}|dd|ddkrBdS|dd|ddS)Nrrr'r&r-)Ztoken1Ztoken2r-r-r1�_column_distance�s
r3cCsH|dkr|�|d�|kpF|dkoF|�|d�|koF|�|d�tjkS)Nrr&r')r.�type�tokenize�COMMENT)�tokens�line_endr.r-r-r1�_last_token_on_line_is�s
r9cCs<|�|d�tjkp:|�|d�tjko:|�|d�tjkS)Nr&r')r4r5�NLr6)r7�positionr-r-r1�_token_followed_by_eol�sr<cCs*d}x |D]}|dkr ||7}q
Pq
W|S)z.Return the indention string of the given line.�z 	r-)�line�result�charr-r-r1�_get_indent_string�s

rAcCs<d}x2|D]*}|dkr |d7}q
|dkr2|t7}q
Pq
W|S)z?Return the length of the indentation on the given token's line.rr+r&�	)�_TAB_LENGTH)r>r?r@r-r-r1�_get_indent_lengths


rDc
Cs�|sdSdd�|D�}t|�}d}dd�|D�}t|�dkr~|dd}t||�}||kr`dnd	}t|||dkrvd
ndf}|�|df�|��dg|d
dd}x|D]\}}	|	||<q�Wd�|�|fS)zCReturn a line with |s for each of the positions in the given lists.)r=r=cSsg|]}t|��qSr-)rD)�.0�indentr-r-r1�
<listcomp>sz)_get_indent_hint_line.<locals>.<listcomp>r=cSsg|]}|df�qS)�|r-)rE�posr-r-r1rGsr&r�add�remove�sr,r+r))rD�len�abs�_CONTINUATION_HINT_MESSAGE�append�sort�join)
Z
bar_positionsZbad_position�
delta_message�markersZexpected_position�delta�	directionr>r;�markerr-r-r1�_get_indent_hint_lines(rXc@seZdZdZdd�ZdS)�_ContinuedIndent)�valid_outdent_strings�valid_continuation_strings�context_typer.r;cCs"||_||_||_||_||_dS)N)rZr[r\r;r.)�selfr\r.r;rZr[r-r-r1�__init__5s
z_ContinuedIndent.__init__N)�__name__�
__module__�__qualname__�	__slots__r^r-r-r-r1rY,srYz
dict-value�hangingz
hanging-block�	continuedzcontinued-block�singleZmulti)rcz in dict value)rcr=)rcz
 before block)rdr=)rdz
 before blockz (%s %d space%s)cGsdd�|D�S)z/Valid indentation strings for a continued line.cSsi|]
}d|�qS)Nr-)rE�ar-r-r1�
<dictcomp>`sz!_Indentations.<locals>.<dictcomp>r-)�argsr-r-r1�
_Indentations^sricCs|t|tiS)a�Valid alternative indentation strings for continued lines before blocks.

    :param int single: Valid indentation string for statements on a single logical line.
    :param int with_body: Valid indentation string for statements on several lines.

    :returns: A dictionary mapping indent offsets to a string representing
        whether the indent if for a line or block.
    :rtype: dict
    )�SINGLE_LINE�	WITH_BODY)reZ	with_bodyr-r-r1�_BeforeBlockIndentationscs
rlc@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�TokenWrapperz3A wrapper for readable access to token information.cCs
||_dS)N)�_tokens)r]r7r-r-r1r^sszTokenWrapper.__init__cCs|j|dS)Nr&)rn)r]�idxr-r-r1r.vszTokenWrapper.tokencCs|j|dS)Nr)rn)r]ror-r-r1r4yszTokenWrapper.typecCs|j|ddS)Nr'r)rn)r]ror-r-r1�
start_line|szTokenWrapper.start_linecCs|j|ddS)Nr'r&)rn)r]ror-r-r1�	start_colszTokenWrapper.start_colcCs|j|dS)Nr()rn)r]ror-r-r1r>�szTokenWrapper.linecCst|�|��S)zPGet the string of TABs and Spaces used for indentation of the line of this token)rAr>)r]ror-r-r1�line_indent�szTokenWrapper.line_indentcCs$|�|�}|d|�|�t|�S)aGet an indentation string for hanging indentation, consisting of the line-indent plus
        a number of spaces to fill up to the column of this token.

        e.g. the token indent for foo
        in "<TAB><TAB>print(foo)"
        is "<TAB><TAB>      "
        r+)rrrqrM)r]rorrr-r-r1�token_indent�s
zTokenWrapper.token_indentN)r_r`ra�__doc__r^r.r4rprqr>rrrsr-r-r-r1rmpsrmc@s�eZdZdZdd�Zedd��Zedd��Zedd	��Zed
d��Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS)�ContinuedLineStatez8Tracker for continued indentation inside a logical line.cCs,d|_g|_d|_g|_||_t|�|_dS)Nr)F)�_line_start�_cont_stack�_is_block_opener�retained_warnings�_configrmrn)r]r7�configr-r-r1r^�szContinuedLineState.__init__cCs
t|j�S)N)�boolrw)r]r-r-r1�has_content�szContinuedLineState.has_contentcCs|jj�dd�S)Nz\trB)rz�
indent_string�replace)r]r-r-r1�_block_indent_string�sz'ContinuedLineState._block_indent_stringcCs|jd|jjS)Nr)r�rz�indent_after_paren)r]r-r-r1�_continuation_string�sz'ContinuedLineState._continuation_stringcCs|jjS)N)rzr�)r]r-r-r1�_continuation_size�sz%ContinuedLineState._continuation_sizecCsF|jdkrdS|}|j�|�tkr*|d7}|j�|�tk|_||_dS)z7Record the first non-junk token at the start of a line.r)Nr&)rvrnr.�_ASYNC_TOKEN�_CONTINUATION_BLOCK_OPENERSrx)r]rIZcheck_token_positionr-r-r1�handle_line_start�s
z$ContinuedLineState.handle_line_startcCsd|_d|_dS)z2Prepares the tracker for a new physical line (NL).r)FN)rvrx)r]r-r-r1�next_physical_line�sz%ContinuedLineState.next_physical_linecCs|��g|_g|_dS)zPrepares the tracker for a new logical line (NEWLINE).

        A new logical line only starts with block indentation.
        N)r�ryrw)r]r-r-r1�next_logical_line�sz$ContinuedLineState.next_logical_linecCs|j�|||f�dS)N)ryrP)r]Ztoken_position�state�valid_indentationsr-r-r1�add_block_warning�sz$ContinuedLineState.add_block_warningcCs\d}|j�|�dkr(|jdjdkr(d}|j|}|j�|�tkrJ|j}n|j}||��fS)z>Returns the valid offsets for the token at the given position.r))r$r�:���)rnr.rw�_CLOSING_BRACKETSrZr[�copy)r]roZ	stack_toprFr�r-r-r1�get_valid_indentations�s
z)ContinuedLineState.get_valid_indentationsc
Cs�|j�|�}|jrP|j|jkrPtt||t||j|�t||j||jd��S|dkr�|j	dj
}|j	dj��}t
|���}d||d|j<tt||||�Stt||t|||j�t||j��S)abExtracts indentation information for a hanging indent

        Case of hanging indent after a bracket (including parenthesis)

        :param str bracket: bracket in question
        :param int position: Position of bracket in self._tokens

        :returns: the state and valid positions for hanging indentation
        :rtype: _ContinuedIndent
        r'r�r)Tr)rnrrrxr�r�rY�
HANGING_BLOCKrirlrwrZr[r��list�keys�HANGING_DICT_VALUE�HANGING)r]�bracketr;�indentationZparen_alignZ
next_alignZnext_align_keysr-r-r1�_hanging_indent_after_bracket�s0z0ContinuedLineState._hanging_indent_after_bracketc	Csv|j�|�}|j�|�}|j�|d�}|jr\|||jkr\tt||t|�t|||j	��Stt
||t||�t|��S)z8Extracts indentation information for a continued indent.r&)rnrrrsrxr�rY�CONTINUED_BLOCKrirlr��	CONTINUED)r]r�r;r�rsZnext_token_indentr-r-r1�_continuation_inside_brackets$z/ContinuedLineState._continuation_inside_bracketcCs|j��dS)N)rw�pop)r]r-r-r1�	pop_token,szContinuedLineState.pop_tokencCs:t|j|�r"|j�|�||��n|j�|�||��dS)a�Pushes a new token for continued indentation on the stack.

        Tokens that can modify continued indentation offsets are:
          * opening brackets
          * 'lambda'
          * : inside dictionaries

        push_token relies on the caller to filter out those
        interesting tokens.

        :param int token: The concrete token
        :param int position: The position of the token in the stream.
        N)r<rnrwrPr�r�)r]r.r;r-r-r1�
push_token/szContinuedLineState.push_tokenN)r_r`rartr^�propertyr}r�r�r�r�r�r�r�r�r�r�r�r�r-r-r-r1ru�s
	3ruc@s�eZdZdZeeefZdZe	Z
dddddd�fd	d
ddd
d�fdddddd�fdddddd�fdd�e�d�e
�de
dedededd�fddddd d�fd!d"d#d$d%d�fd&ddd'd(d�fd)d*d+d,d,d-d.gd/d0�ff	Zdgd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Zd>d?�Zd@dA�ZdBdC�ZdDdE�ZdFdG�ZdHdI�ZdJdK�ZdLdM�ZdNdO�Z dPdQ�Z!dRdS�Z"dTdU�Z#dVdW�Z$dXdY�Z%dZd[�Z&d\d]�Z'e(d^�d_d`��Z)dadb�Z*dcdd�Z+dedf�Z,d1S)h�
FormatCheckerz]checks for :
    * unauthorized constructions
    * strict indentation
    * line length
    �formatzmax-line-length�d�intz<int>z.Maximum number of characters on a single line.)�defaultr4�metavar�helpzignore-long-linesZregexpz<regexp>z^\s*(# )?<?https?://\S+>?$z>Regexp for a line that is allowed to be longer than the limit.)r4r�r�r�zsingle-line-if-stmtFZynz<y_or_n>zOAllow the body of an if to be on the same line as the test if there is no else.zsingle-line-class-stmtzfAllow the body of a class to be on the same line as the declaration if body contains single statement.zno-space-check�,Zmultiple_choicezHList of optional constructs for which whitespace checking is disabled. `zB` is used to allow tabulation in dicts, etc.: {1  : 1,\n222: 2}. `z<` allows a space between comma and closing bracket: (a, ). `z` allows space-only lines.)r�r�r4�choicesr�zmax-module-linesi�z$Maximum number of lines in a module.z
indent-stringz    Znon_empty_stringz<string>zSString used as indentation unit. This is usually "    " (4 spaces) or "\t" (1 tab).zindent-after-parenr(zGNumber of spaces of indent required inside a hanging or continued line.zexpected-line-ending-format�choicez<empty or LF or CRLF>r=�LF�CRLFzIExpected format of line ending, e.g. empty (any line ending), LF or CRLF.)r4r�r�r�r�NcCs$t�||�d|_d|_dg|_dS)N)rr^�_lines�_visited_lines�_bracket_stack)r]�linterr-r-r1r^�szFormatChecker.__init__cCs|j��|j��dS)N)r�r��
_current_liner�)r]r-r-r1�
_pop_token�s
zFormatChecker._pop_tokencCs|j�|�|j�||�dS)N)r�rPr�r�)r]r.ror-r-r1�_push_token�szFormatChecker._push_tokencCsft||d�r |jd|�|�d�|�|�}|�|�}|�|�tkrV|�d�d|j|<|�||�dS)z8a new line has been encountered, process it if necessary�;zunnecessary-semicolon)r>r*rN)	r9�add_messagerpr>r4�_JUNK_TOKENS�splitr��check_lines)r]r7r8Z
line_start�line_numr>r-r-r1�new_line�s

zFormatChecker.new_linecCs"t�|_d|jkr|j�d�dS)N�print_functionr)�set�_keywords_with_parensZfuture_importsrJ)r]�moduler-r-r1�process_module�s
zFormatChecker.process_modulec	Cs�|�d�r"||ddkr"|��||dddkr:dSd}d}t||d�}||dd}�xft|t|�d�D�]N}||}|dtjkr�dS|ddkr�|d7}qx|dd	k�rx|d8}|r�qx||ddd
k�s||ddtjtjtj	fk�rt||dk�rdS|dk�r6|�st|j
d||d
�n>|dk�rR|j
d||d
�n"||jk�rt|�st|j
d||d
�dS|dkrx|ddk�r�dS|ddk�r�d}qx|ddk�r�dS|ddkrxdSqxWdS)a�Check that there are not unnecessary parens after a keyword.

        Parens are unnecessary if there is exactly one balanced outer pair on a
        line, and it is followed by a colon, and contains no commas (i.e. is not a
        tuple).

        Args:
        tokens: list of Tokens; the entire list of Tokens.
        start: int; the position of the keyword in the token list.
        r�r&rrNFrr'r")r�r"r#r$rrzsuperfluous-parens)r>rh)rrr�)�and�orTr)�_inside_bracketsr��str�rangerMr5r:�NEWLINE�	ENDMARKERr6r�r�)	r]r7�startZfound_and_or�depthZ
keyword_tokenr��ir.r-r-r1�_check_keyword_parentheses�sX
 

z(FormatChecker._check_keyword_parenthesescCs�|�||d|�||ddkr<||dddkr<dS|dkr�||ddtjkrpt�||dd�r�||ddtkr�|�||ttf�n|�||ttf�dS)Nr&r r�r)	r�r5�NAME�keyword�	iskeywordr��_check_space�	_MUST_NOT�_IGNORE)r]r7r�r-r-r1�_opening_bracket(s$zFormatChecker._opening_bracketcCs�|�d�r|��|��||dddkrB||ddkrBdSt}||dtkrz||dddkrzt|jjkrzt}|�|||tf�dS)Nr�r&r#r�)	r�r�r�r��_TRAILING_COMMAr{�no_space_checkr�r�)r]r7r�Z
policy_beforer-r-r1�_closing_bracket7s
$$zFormatChecker._closing_bracketcCs�|�d�sdSd}x�||ddd�D]�}|ddkr:dS|ddkrJdS|dd	kr`|d7}q&|dd
krv|d8}q&|ddkr�|s�dSq&|ddkr�q&q&|dtjtjtjfkr&dSq&WdS)
z,Extended check of PEP-484 type hint presencerFrr&Nr)r�Tr#r r�)�.z...)r�r5r��STRINGr:)r]r7r�Z
bracket_levelr.r-r-r1�_has_valid_type_annotationEs(


z(FormatChecker._has_valid_type_annotationcCs^|�||�r |�||ttf�n:|�d�s4|�d�rH|�||ttf�n|�||ttf�dS)z*Check the spacing of a single equals sign.r�lambdaN)r�r��_MUSTr�r�)r]r7r�r-r-r1�_check_equals_spacing_s
z#FormatChecker._check_equals_spacingcCs|�d|�dS)Nr�)r�)r]r7r�r-r-r1�_open_lambdahszFormatChecker._open_lambdacCsr|�d�rdS|�d�r.t|jjkr.ttf}nttf}|�|||�|�d�rX|��n|�d�rn|�	d|�dS)Nr r!r�r�)
r��_DICT_SEPARATORr{r�r�r�r�r�r�r�)r]r7r��policyr-r-r1�
_handle_colonks




zFormatChecker._handle_coloncCsP||ddtkr(|�||ttf�n|�||ttf�|�d�rL|��dS)Nr&r�)r�r�r�r�r�r�r�)r]r7r�r-r-r1�
_handle_commazs

zFormatChecker._handle_commacCs|�||ttf�dS)z@Check that a binary operator is surrounded by exactly one space.N)r�r�)r]r7r�r-r-r1�_check_surrounded_by_space�sz(FormatChecker._check_surrounded_by_spacec
sndd�}�fdd�}ddg}||}||d|f|||dfg}xntt||��D]\\}	\}
}||	dtksT|
tkrzqTt|�}|dkr�qT|
tkr�|dkp�|
tko�|dk||	<qTWg}
t|�s�|d|dkr�|
�|ddf�n.x,t||d	�D]\}}
}|s�|
�|
|f�q�WxV|
D]N\}
}||�}||
�\}}�j	d
|dd||||t
|�f|ddd��qWdS)
NcSs|tkrdSdS)N)zExactly one�required)ZNoZallowed)r�)r�r-r-r1�_policy_string�sz2FormatChecker._check_space.<locals>._policy_stringcsR|ddkrdS|ddkr dS|ddkr0dS|ddkr@dS��d	�rNd
SdS)Nr&r�Zcommar�z()[]{}r�)rrz<=z>=z!=z==Z
comparisonrzkeyword argument assignmentZ
assignment)r�)r.)r]r-r1�_name_construct�s
z3FormatChecker._check_space.<locals>._name_constructTr&rZaround)�before�afterzbad-whitespacer')r>rh�
col_offset)�	enumerate�zip�_EOLr�r3r�r��anyrPr�r2)r]r7r�Zpoliciesr�r�Z
good_spacer.�pairsZ	other_idxr�Z
token_pairZdistance�warnings�okr;Z	construct�countr�r-)r]r1r��s6
 
zFormatChecker._check_spacecCs|jd|kS)Nr))r�)r]�leftr-r-r1r��szFormatChecker._inside_bracketsc	Cs|t|jft|jft|jfdg|jft|jfdg|j	fdg|j
fdg|jfg}i}x&|D]\}}x|D]}|||<qdWqVW|S)N�=r�r�r�)�_KEYWORD_TOKENSr��_OPENING_BRACKETSr�r�r�r��_SPACED_OPERATORSr�r�r�r�)r]�raw�dispatchr7�handlerr.r-r-r1�_prepare_token_dispatcher�s



z'FormatChecker._prepare_token_dispatcherc	Cs�dg|_dg}d}d}i|_i|_|��}d|_d}t||j�|_�x�t|�D�]�\}\}}	}
}}|
d|kr�|
d}|t	j
kr�|�t|�|d|d�n|�t|�|d|�|t	j
kr�d}|�t|�|�|j��|�|	|�n�|t	j
k�r"d}|�|	|dd|�|�|dd�n�|t	jk�rHd}t|�dk�r�|d=nv|t	jk�r�|�d��sd|}|�t|�|d�|j��n:|t	jt	jfk�r�|j�|�|�r�d}|�||d|�|t	jk�r�|	�d��r�|jd	|d
�y||	}
Wntk
�rYqNX|
||�qNW|d8}||jj k�r||j!j"�#d�d}|j$df}t%t&dt'|j!j(j)|��d�}|jd||jj f|d�||k�r�|dk�r�|jd
|d
�dS)a=process tokens and search for :

         _ non strict indentation (i.e. not always using the <indent> parameter as
           indent unit)
         _ too long lines (i.e. longer than <max_chars>)
         _ optionally bad construct (if given, bad_construct must be a compiled
           regular expression).
        NrFr&Tr)z
�lzlowercase-l-suffix)r>ztoo-many-lines)rhr>ztrailing-newlines)*r�r�r�r��_last_line_endingrur{r�r�r5�INDENTr�rmr��_process_retained_warningsr��_check_line_ending�check_indent_levelrP�DEDENTrMr:�strip�_check_continued_indentationr�r6�ENCODINGr��NUMBER�endswithr��KeyErrorZmax_module_linesr�Z
msgs_storeZget_message_definitions�msgid�next�filter�mapZ_pragma_lineno�get)r]r7�indentsZcheck_equalr�Ztoken_handlersZlast_blank_line_numro�tok_typer.r��_r>r�Zmessage_definition�namesr-r-r1�process_tokens�sv	 




zFormatChecker.process_tokenscCsx|jdk	r&|r&||jkr&|jd|d�||_|jj}|rttdd�|d�}|dkrTdnd}||krt|jd	||f|d
�dS)Nzmixed-line-endings)r>cSs||kr||S|S)Nr-)�x�yr-r-r1�<lambda>C�z2FormatChecker._check_line_ending.<locals>.<lambda>r=r*r�r�zunexpected-line-ending-format)rhr>)r�r�r{Zexpected_line_ending_formatr)r]Zline_endingr��expectedr-r-r1r�4s
z FormatChecker._check_line_endingcs�t||d�}xt|jjD]h\}}}||�|���fdd�|��D�}|rd�tkrd|�||||�q|s�tkr|�||||�qWdS)Nr�csi|]\}}|�kr||�qSr-r-)rE�k�v)�
block_typer-r1rgQsz<FormatChecker._process_retained_warnings.<locals>.<dictcomp>)r9r�ryrs�itemsrk�_add_continuation_messagerj)r]r7Zcurrent_posZsingle_line_block_stmtZ
indent_posr��indentationsZhintsr-)rr1r�Lsz(FormatChecker._process_retained_warningscs���fdd�}|jjr&����tjkr*dS|j���\}}|tj�sN|tj�r`d|���d�<|j	t
tfkr�����|kr�|j��||�nB����|kr�t
������t�fdd�|D��s�|�||���dS)Ncs ����|ko���d�|kS)Nr')r4)�
token_type)�next_idxr7r-r1�same_token_around_nlXszHFormatChecker._check_continued_indentation.<locals>.same_token_around_nlTr'c3s|]}�dt|�kVqdS)r'N)rM)rEr�)�length_indentationr-r1�	<genexpr>wsz=FormatChecker._check_continued_indentation.<locals>.<genexpr>)r�r}r4r5r:r�r6r�rsr\r�r�r�rMr�r)r]r7rrr�r�r-)rrr7r1r�Ws"

z*FormatChecker._check_continued_indentationc		CsLt|j\}}t||�|��\}}|jd|�|�||||�|�|fd�dS)Nzbad-continuation)r>rh)�_CONTINUATION_MSG_PARTSr\rXrsr�rpr>)	r]r�rr7r;Z
readable_typeZreadable_positionZ	hint_linerSr-r-r1r~sz'FormatChecker._add_continuation_messagezmultiple-statementsc	CsH|js
dS|��jsdS|��}|dk	r0|j}n:t|jtj�r^||jj	kr^|jj
djd}n|j��j}|j}|s|t
|��||kr�|j�|�dkr�|�||�dS||jkr�dSy
|j}Wntk
r�|j}YnX|s�t
|��g}xZt||d�D]H}d|j|<y|�|j|���Wq�tk
�r>|�d�Yq�Xq�WdS)z7check the node line number and check it if not yet doneNrr&r'r=)Zis_statement�rootZpure_pythonZprevious_siblingZ
fromlineno�
isinstance�parentr�
TryFinallyZ	finalbody�body�tolinenoZ	statement�AssertionErrorr�r�_check_multi_statement_lineZblockstart_tolineno�AttributeErrorr�rPr��rstripr)r]�nodeZ	prev_sibl�	prev_liner>r$�linesr-r-r1�
visit_default�s<



zFormatChecker.visit_defaultcCs�t|tj�rdSt|tj�r.t|jtj�r.dSt|jtj�rP|jjsP|jj	rPdSt|jtj
�rzt|jj�dkrz|jj
rzdS|jd|d�d|j|<dS)z/Check for lines containing multiple statements.Nr&zmultiple-statements)r)r')r rZWithZ	TryExceptr!r"ZIfZorelser{Zsingle_line_if_stmtZClassDefrMr#Zsingle_line_class_stmtr�r�)r]r)r>r-r-r1r&�sz)FormatChecker._check_multi_statement_linec
s��jj��jj����fdd�}ddddddddd	d
h
}g}xZ|�d�D]L}|d|krd|�|�qH|r�|�|�d
�|�}g}|||�}|dkrHPqHW|r�|d
�|�|�dS)zBcheck lines have less than a maximum number of characters
        cs|�d�s�jd|d�nH|�d�}|s6t�jjkr6n(|t|�d�dkr^�jd|t|�d�|}t�|�}|r�d|kr�|�	d	��
d�\}}}|��d
kr�ddd
�|�d�D�kr�dS|�
dd	�d��}t|��kr���|�s��jd|t|��fd�|d	S)Nr*zmissing-final-newline)r>z	

 )r*z
ztrailing-whitespace)r>r�r�r&�disablez
line-too-longcSsh|]}|���qSr-)r�)rEZ_msg_idr-r-r1�	<setcomp>�sz@FormatChecker.check_lines.<locals>.check_line.<locals>.<setcomp>r��#r)r>rh)rr�r(�_EMPTY_LINEr{r�rMr
�search�group�	partitionr�r��rsplit)r>r�Z
stripped_lineZmobjZfront_of_equalrZ
back_of_equal)�ignore_long_line�	max_charsr]r-r1�
check_line�s(


z-FormatChecker.check_lines.<locals>.check_line������…u
u
Tr)r=N)r{�max_line_lengthZignore_long_lines�
splitlinesrPrR)r]r+r�r7Zunsplit_endsZunsplitr>r-)r5r6r]r1r��s6



zFormatChecker.check_linesc
Cs|jj}|dkrd}d}t|�}x(|d|�|krH||d�}|d7}q"Wd}xf|r�|ddkr�|d|dkr�|ddkr�d}nd	}|jd
||d�|S||d7}|dd�}qPW||ks�|r�d}	|ddkr�d
}	|jd|||t|�|	||fd�dS)z.return the indent level of the string
        z\trBrNr&r=z 	)�tab�space)rAr@zmixed-indentation)rhr>Zspaces�tabszbad-indentation)r>rh)r{r~rMr�)
r]�stringrr�rF�levelZ	unit_sizeZsupplrhZi_typer-r-r1r�s6z FormatChecker.check_indent_level)N)-r_r`rartrrrZ__implements__�name�MSGSZmsgsrR�_DEFAULT_NO_SPACE_CHECK_CHOICES�_NO_SPACE_CHECK_CHOICESr�r�r0�optionsr^r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r
r�r�r�rrr,r&r�r�r-r-r-r1r�Cs�
 
L	
3d'*Ar�cCs|�t|��dS)z.required method to auto register this checker N)Zregister_checkerr�)r�r-r-r1�register7srJcCsxtd�D]}q
Wt|�dS)Nr)r�r)�valr-r-r1�funkier<srL)Drtr��sysr5�	functoolsrZastroidrZpylint.interfacesrrrZpylint.checkersrZpylint.checkers.utilsrZpylint.utilsr	r
r�r�r��version_inforPr�r�r�rC�	frozensetr�r:r6r�r�r�r�r�r�r�r0rHrGZNODErFr2r3r9r<rArDrXrYr�r�r�r�r�rjrkrrOrirlrmrur�rJrLr-r-r-r1�<module>,s�










%/y