
'![c           @   sb  d  Z  d d l Z d d l Z d d l Z d d l m Z d d l Z d d l m Z m	 Z	 m
 Z
 d d l m Z d d l m Z m Z m Z d d l m Z d d l m Z d d	 l m Z m Z d
 Z d d d d d d d g Z d d d d d d d d d d d d g Z e j d d f k  r4e j d  n  d d d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. g Z d/ d0 d1 g Z d2 d3 d4 g Z d5 Z  e! e j" e j# e j$ g  Z% e j$ e j# f Z& d Z' d6 Z( d7 Z) d8 Z* d9 Z+ d: Z, e+ e* e, g Z- e+ e* g Z. i d; d< d= f d> 6d? d@ dA f dB 6dC dD dE f dF 6dG dH dI f dJ 6dK dL dM f dN 6dO dP dQ f dR 6dS dT dU f dV 6dW dX dY f dZ 6d[ d\ d] f d^ 6d_ d` da i e j/ db 6f dc 6dd de df f dg 6dh di dj i dk dl f dm dn f do dp f g dq 6f dr 6ds dt du i d d f dv 6f dw 6dx dy dz f d{ 6d| d} d~ f d 6Z0 d   Z1 d   Z2 d   Z3 d   Z4 d   Z5 d   Z6 d e7 f d     YZ8 d Z9 d Z: d Z; d Z< d Z= d Z> d Z? i d d f e9 6d d f e: 6d d f e; 6d d f e< 6d d f e= 6Z@ d ZA d   ZB d   ZC d e7 f d     YZD d e7 f d     YZE d e f d     YZF d   ZG d S(   s   Python code format's checker.

By default try to follow Guido's style guide :

http://www.python.org/doc/essays/styleguide.html

Some parts of the process_token method is based from The Tab Nanny std module.
iN(   t   reduce(   t   zipt   mapt   filter(   t   nodes(   t   ITokenCheckert   IAstroidCheckert   IRawChecker(   t   BaseTokenChecker(   t   check_messages(   t   WarningScopet
   OPTION_RGXt   asynct   elift   exceptt   fort   ift   whilet   deft   classt   assertt   delt   int   nott   raiset   returnt   yieldi   i    t   prints   ==t   <t   >s   !=s   <>s   <=s   >=s   +=s   -=s   *=s   **=s   /=s   //=s   &=s   |=s   ^=s   %=s   >>=s   <<=t   (t   [t   {t   )t   ]t   }i   i   i   s   dict-separators   trailing-commas
   empty-lines   Line too long (%s/%s)s   line-too-longs=   Used when a line is longer than a given number of characters.t   C0301s    Too many lines in module (%s/%s)s   too-many-liness@   Used when a module has too much lines, reducing its readability.t   C0302s   Trailing whitespaces   trailing-whitespacesH   Used when there is whitespace between the end of a line and the newline.t   C0303s   Final newline missings   missing-final-newlines7   Used when the last line in a file is missing a newline.t   C0304s   Trailing newliness   trailing-newliness3   Used when there are trailing blank lines in a file.t   C0305s)   Bad indentation. Found %s %s, expected %ss   bad-indentationsU   Used when an unexpected number of indentation's tabulations or spaces has been found.t   W0311s   Wrong %s indentation%s%s.
%s%ss   bad-continuationt   TODOt   C0330s)   Found indentation with %ss instead of %sss   mixed-indentations;   Used when there are some mixed tabs and spaces in a module.t   W0312s   Unnecessary semicolons   unnecessary-semicolonss   Used when a statement is ended by a semi-colon (";"), which               isn't necessary (that's python, not C ;).t   W0301s(   More than one statement on a single lines   multiple-statementss<   Used when more than on statement are found on the same line.t   scopet   C0321s#   Unnecessary parens after %r keywords   superfluous-parenssL   Used when a single item in parentheses follows an if, for, or other keyword.t   C0325s   %s space %s %s %s
%ss   bad-whitespacesW   Used when a wrong number of spaces is used around an operator, bracket or block opener.t   C0323s   no-space-after-operatort   C0324s   no-space-after-commat   C0322s   no-space-before-operatort	   old_namest   C0326s%   Use of "l" as long integer identifiers   lowercase-l-suffixs   Used when a lower case "l" is used to mark a long integer. You should use a upper case "L" since the letter "l" looks too much like the digit "1"t
   maxversiont   W0332s   Mixed line endings LF and CRLFs   mixed-line-endingss@   Used when there are mixed (LF and CRLF) newline signs in a file.t   C0327sE   Unexpected line ending format. There is '%s' while it should be '%s'.s   unexpected-line-ending-formats3   Used when there is different newline than expected.t   C0328c         C   sc   |  d d |  d d } |  d d } |  d } | d d k rO | d 7} n  | d | d | S(	   Ni   i   i   i   is   
t    t   ^(    (   t   tokent   lengtht   offsett   referenced_line(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _underline_token   s    
c         C   sl   |  | k r d S| d |  d k  r4 | |  }  } n  |  d d | d d k rT d  S| d d |  d d S(   Ni    i   i   i   (   t   None(   t   token1t   token2(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _column_distance   s    c         C   sd   | d k r% |  j  | d  | k pc | d k oc |  j  | d  | k oc |  j | d  t j k S(   Ni    i   i   (   R<   t   typet   tokenizet   COMMENT(   t   tokenst   line_endR<   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _last_token_on_line_is   s    %%c         C   sR   |  j  | d  t j k pQ |  j  | d  t j k oQ |  j  | d  t j k S(   Ni   i   (   RE   RF   t   NLRG   (   RH   t   position(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _token_followed_by_eol   s    c         C   sN   d } xA |  D]9 } | d k r, | d 7} q | d k rE | t  7} q Pq W| S(   s?   Return the length of the indentation on the given token's line.i    R:   i   s   	(   t   _TAB_LENGTH(   t   linet   resultt   char(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _get_indent_length   s    c         C   s	  |  s
 d Sd } g  |  D] } | d f ^ q } t  |  d k r | d d } t | |  } | | k rq d n d } t | | | d k r d n d f } n  | j | d f  | j   d	 g | d
 d d } x | D] \ }	 }
 |
 | |	 <q Wd j |  | f S(   sC   Return a line with |s for each of the positions in the given lists.t    t   |i   i    t   addt   removet   sR;   R:   i(   RS   RS   (   t   lent   abst   _CONTINUATION_HINT_MESSAGEt   appendt   sortt   join(   t   bar_positionst   bad_positiont   delta_messaget   post   markerst   expected_positiont   deltat	   directionRO   RL   t   marker(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _get_indent_hint_line   s     %
t   _ContinuedIndentc           B   s   e  Z d Z d   Z RS(   t   valid_outdent_offsetst   valid_continuation_offsetst   context_typeR<   RL   c         C   s1   | |  _  | |  _ | |  _ | |  _ | |  _ d  S(   N(   Ri   Rj   Rk   RL   R<   (   t   selfRk   R<   RL   Ri   Rj   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   __init__   s
    				(   Ri   Rj   Rk   R<   RL   (   t   __name__t
   __module__t	   __slots__Rm   (    (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyRh      s       s
   dict-valuet   hangings   hanging-blockt	   continueds   continued-blockt   singlet   multis    in dict valueRS   s    before blocks    (%s %d space%s)c          G   s   t  d   |  D  S(   s/   Valid indentation offsets for a continued line.c         s   s   |  ] } | d  f Vq d  S(   N(   RA   (   t   .0t   a(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pys	   <genexpr>   s    (   t   dict(   t   args(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _Offsets   s    c         C   s   i t  |  6t | 6S(   sn  Valid alternative indent offsets for continued lines before blocks.

    :param int single: Valid offset for statements on a single logical line.
    :param int with_body: Valid offset 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
    (   t   SINGLE_LINEt	   WITH_BODY(   Rs   t	   with_body(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _BeforeBlockOffsets  s    
t   TokenWrapperc           B   sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s3   A wrapper for readable access to token information.c         C   s   | |  _  d  S(   N(   t   _tokens(   Rl   RH   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyRm     s    c         C   s   |  j  | d S(   Ni   (   R   (   Rl   t   idx(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyR<     s    c         C   s   |  j  | d S(   Ni    (   R   (   Rl   R   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyRE     s    c         C   s   |  j  | d d S(   Ni   i    (   R   (   Rl   R   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt
   start_line  s    c         C   s   |  j  | d d S(   Ni   i   (   R   (   Rl   R   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt	   start_col  s    c         C   s   |  j  | d S(   Ni   (   R   (   Rl   R   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyRO   !  s    (	   Rn   Ro   t   __doc__Rm   R<   RE   R   R   RO   (    (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyR~     s   					t   ContinuedLineStatec           B   s   e  Z d  Z d   Z e d    Z e d    Z e d    Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z d   Z d   Z RS(   s8   Tracker for continued indentation inside a logical line.c         C   s@   d |  _  g  |  _ t |  _ g  |  _ | |  _ t |  |  _ d  S(   Ni(   t   _line_startt   _cont_stackt   Falset   _is_block_openert   retained_warningst   _configR~   R   (   Rl   RH   t   config(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyRm   (  s    					c         C   s   t  |  j  S(   N(   t   boolR   (   Rl   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   has_content0  s    c         C   s    t  |  j j j d d t   S(   Ns   	R:   (   RX   R   t   indent_stringt   replaceRN   (   Rl   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _block_indent_size4  s    c         C   s
   |  j  j S(   N(   R   t   indent_after_paren(   Rl   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _continuation_size8  s    c         C   sf   |  j  d k r d S| } |  j j |  t k r> | d 7} n  |  j j |  t k |  _ | |  _  d S(   s7   Record the first non-junk token at the start of a line.iNi   (   R   R   R<   t   _ASYNC_TOKENt   _CONTINUATION_BLOCK_OPENERSR   (   Rl   Ra   t   check_token_position(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   handle_line_start<  s    	c         C   s   d |  _  t |  _ d S(   s2   Prepares the tracker for a new physical line (NL).iN(   R   R   R   (   Rl   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   next_physical_lineI  s    	c         C   s    |  j    g  |  _ g  |  _ d S(   s   Prepares the tracker for a new logical line (NEWLINE).

        A new logical line only starts with block indentation.
        N(   R   R   R   (   Rl   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   next_logical_lineN  s    
	c         C   s   |  j  j | | | f  d  S(   N(   R   R[   (   Rl   t   token_positiont   statet   valid_offsets(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   add_block_warningW  s    c         C   s   d } |  j  j |  d k r= |  j d j d k r= d } n  |  j | } |  j  j |  t k rn | j } n	 | j } | | j   f S(   s>   Returns the valid offsets for the token at the given position.iR#   R   t   :i(   R#   R   (   R   R<   R   t   _CLOSING_BRACKETSRi   Rj   t   copy(   Rl   R   t	   stack_topt   indentR   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   get_valid_offsetsZ  s    .		c      
   C   s  t  |  j j |   } |  j rt |  j |  j k rt t t | | t | |  j |  t	 | |  j | |  j d   S| d k r |  j
 d j } |  j
 d j j   } t | j    } t | | d |  j <t t | | | |  St t | | t | | |  j  t | |  j   S(   s6   Extracts indentation information for a hanging indent.i   R   ii    (   RR   R   RO   R   R   R   Rh   t   HANGING_BLOCKRy   R}   R   Ri   Rj   R   t   listt   keyst   Truet   HANGING_DICT_VALUEt   HANGING(   Rl   t   bracketRL   t   indentationt   paren_alignt
   next_alignt   next_align_keys(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _hanging_indent_after_bracketh  s*    c      	   C   s   t  |  j j |   } |  j j |  } |  j j | d  } |  j r | | |  j k r t t | | t |  t	 | | |  j
   St t | | t |  t |   S(   s8   Extracts indentation information for a continued indent.i   (   RR   R   RO   R   R   R   Rh   t   CONTINUED_BLOCKRy   R}   R   t	   CONTINUED(   Rl   R   Ra   R   t   token_startt   next_token_start(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _continuation_inside_bracket  s     		c         C   s   |  j  j   d  S(   N(   R   t   pop(   Rl   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt	   pop_token  s    c         C   sQ   t  |  j |  r1 |  j j |  j | |   n |  j j |  j | |   d S(   s  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(   RM   R   R   R[   R   R   (   Rl   R<   RL   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt
   push_token  s
    		(   Rn   Ro   R   Rm   t   propertyR   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyR   %  s   								!		t   FormatCheckerc           B   s  e  Z d  Z e e e f Z d Z e Z	 d i d d 6d d 6d d 6d	 d
 6f d i d d 6d d 6d d 6d d
 6f d i e
 d 6d d 6d d 6d d
 6f d i e
 d 6d d 6d d 6d d
 6f d i d j e  d 6d j e  d 6d d 6e d 6d e d e d e d d
 6f d i d d 6d d 6d d 6d  d
 6f d! i d" d 6d# d 6d$ d 6d% d
 6f d& i d d 6d d 6d' d 6d( d
 6f d) i d* d 6d+ d 6d, d 6d, d- d. g d 6d/ d
 6f f	 Z dK d0  Z d1   Z d2   Z d3   Z d4   Z d5   Z d6   Z d7   Z d8   Z d9   Z d:   Z d;   Z d<   Z d=   Z  d>   Z! d?   Z" d@   Z# dA   Z$ dB   Z% dC   Z& dD   Z' dE   Z( e) dF  dG    Z* dH   Z+ dI   Z, dJ   Z- RS(L   s]   checks for :
    * unauthorized constructions
    * strict indentation
    * line length
    t   formats   max-line-lengthid   t   defaultt   intRE   s   <int>t   metavars.   Maximum number of characters on a single line.t   helps   ignore-long-linest   regexps   <regexp>s   ^\s*(# )?<?https?://\S+>?$s>   Regexp for a line that is allowed to be longer than the limit.s   single-line-if-stmtt   yns   <y_or_n>sO   Allow the body of an if to be on the same line as the test if there is no else.s   single-line-class-stmtsf   Allow the body of a class to be on the same line as the declaration if body contains single statement.s   no-space-checkt   ,t   multiple_choicet   choicessH   List of optional constructs for which whitespace checking is disabled. `sB   ` is used to allow tabulation in dicts, etc.: {1  : 1,\n222: 2}. `s<   ` allows a space between comma and closing bracket: (a, ). `s   ` allows space-only lines.s   max-module-linesi  s#   Maximum number of lines in a modules   indent-strings       t   non_empty_strings   <string>sS   String used as indentation unit. This is usually "    " (4 spaces) or "\t" (1 tab).s   indent-after-pareni   sH   Number of spaces of indent required inside a hanging  or continued line.s   expected-line-ending-formatt   choices   <empty or LF or CRLF>RS   t   LFt   CRLFsI   Expected format of line ending, e.g. empty (any line ending), LF or CRLF.c         C   s2   t  j |  |  d  |  _ d  |  _ d  g |  _ d  S(   N(   R   Rm   RA   t   _linest   _visited_linest   _bracket_stack(   Rl   t   linter(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyRm     s    		c         C   s   |  j  j   |  j j   d  S(   N(   R   R   t   _current_lineR   (   Rl   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt
   _pop_token  s    c         C   s'   |  j  j |  |  j j | |  d  S(   N(   R   R[   R   R   (   Rl   R<   R   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _push_token  s    c         C   s   t  | | d  r1 |  j d d | j |  n  | j |  } | j |  } | j |  t k r | j d  d |  j | <n  |  j | |  d S(   s8   a new line has been encountered, process it if necessaryt   ;s   unnecessary-semicolonRO   s   
i    N(	   RJ   t   add_messageR   RO   RE   t   _JUNK_TOKENSt   splitR   t   check_lines(   Rl   RH   RI   t
   line_startt   line_numRO   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   new_line  s    c         C   s2   t    |  _ d | j k r. |  j j d  n  d  S(   Nt   print_functionR   (   t   sett   _keywords_with_parenst   future_importsRU   (   Rl   t   module(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   process_module  s    c   	      C   sX  |  j  d  r0 | | d d k r0 |  j   n  | | d d d k rL d St } d } t | | d  } | | d d } xt | t |  d  D]} | | } | d t j k r d S| d d k r | d 7} q | d d k r| d 8} | rq n  | | d d d k sD| | d d t j t j	 t j
 f k r| | d k rXd S| d k r| s|  j d d | d | qq| d k r|  j d d | d | q| |  j k r| s|  j d d | d | qqn  d S| d k r | d d k rd S| d d k r%t } qP| d d k r9d S| d d k rPd Sq q Wd S(   s  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   i   R   R   Ni    i   R!   R"   R#   R   R   s   superfluous-parensRO   Rx   R   R   R   t   andt   or(   R   R!   R"   R#   R   (   R   R   (   R   R   (   t   _inside_bracketsR   R   t   strt   rangeRX   RF   RK   t   NEWLINEt	   ENDMARKERRG   R   R   R   (	   Rl   RH   t   startt   found_and_ort   deptht   keyword_tokenR   t   iR<   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _check_keyword_parentheses  sZ    # 


	c         C   s   |  j  | | d |  | | d d k rH | | d d d k rH d  S| d k r | | d d t j k r t j | | d d  s | | d d t k r |  j | | t t f  n |  j | | t t f  d  S(   Ni   R   R   i    (	   R   RF   t   NAMEt   keywordt	   iskeywordR   t   _check_spacet	   _MUST_NOTt   _IGNORE(   Rl   RH   R   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _opening_bracket\  s    ,'c         C   s   |  j  d  r |  j   n  |  j   | | d d d k rV | | d d k rV d  St } | | d t k r | | d d d k r t |  j j k r t } q n  |  j | | | t f  d  S(   NR   i   R"   R   (	   R   R   R   R   t   _TRAILING_COMMAR   t   no_space_checkR   R   (   Rl   RH   R   t   policy_before(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _closing_bracketi  s    
,,c         C   s   |  j  d  s t Sd } x | | d d d  D] } | d d k rK t S| d d k r_ t S| d d k r| | d 7} q1 | d d k r | d 8} q1 | d d	 k r | s t Sq1 | d d
 k r q1 q1 | d t j t j f k r1 t Sq1 Wt S(   s,   Extended check of PEP-484 type hint presenceR   i    i   NiR   R"   R   R   t   .(   R   R   R   RF   R   t   STRING(   Rl   RH   R   t   bracket_levelR<   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _has_valid_type_annotationw  s(    c         C   s   |  j  | |  r. |  j | | t t f  nS |  j d  sL |  j d  rh |  j | | t t f  n |  j | | t t f  d S(   s*   Check the spacing of a single equals sign.R   t   lambdaN(   R   R   t   _MUSTR   R   (   Rl   RH   R   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _check_equals_spacing  s
    c         C   s   |  j  d |  d  S(   NR   (   R   (   Rl   RH   R   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _open_lambda  s    c         C   s   |  j  d  r d  S|  j  d  rC t |  j j k rC t t f } n t t f } |  j | | |  |  j  d  r~ |  j   n" |  j  d  r |  j	 d |  n  d  S(   NR   R    R   R   (
   R   t   _DICT_SEPARATORR   R   R   R   R   R   R   R   (   Rl   RH   R   t   policy(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _handle_colon  s    c         C   sm   | | d d t  k r4 |  j | | t t f  n |  j | | t t f  |  j d  ri |  j   n  d  S(   Ni   R   (   R   R   R   R   R   R   R   (   Rl   RH   R   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _handle_comma  s
    c         C   s   |  j  | | t t f  d S(   s@   Check that a binary operator is surrounded by exactly one space.N(   R   R   (   Rl   RH   R   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _check_surrounded_by_space  s    c            s  d   }   f d   } t  t  g } | | } | | d | f | | | d f g } x t t | |   D] \ }	 \ }
 } | |	 d t k sl |
 t k r ql n  t |   } | d  k r ql n  |
 t k r | d k p |
 t k o | d k | |	 <ql Wg  } t	 |  r;| d | d k r;| j
 | d d f  nB x? t | | d  D]+ \ } }
 } | sN| j
 |
 | f  qNqNWxh | D]` \ }
 } | |  } | |
  \ } }   j d d	 | d
 d d | | | | t |  f qWd  S(   Nc         S   s   |  t  k r d Sd S(   Ns   Exactly onet   requiredt   Not   allowed(   s   Exactly oneR  (   R  R  (   R   (   R   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _policy_string  s    c            sg   |  d d k r d S|  d d k r( d S|  d d k r< d S|  d d k rP d S  j  d  rc d Sd S(   Ni   R   t   commaR   s   ()[]{}R   R   R   s   <=s   >=s   !=s   ==t
   comparisonR   s   keyword argument assignmentt
   assignment(   R   R   s   <=s   >=s   !=s   ==(   R   (   R<   (   Rl   (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _name_construct  s    i   i    t   aroundt   beforet   afters   bad-whitespaceRO   i   Rx   (   R
  R  (   R   t	   enumerateR   t   _EOLR   RD   RA   R   R   t   anyR[   R   R@   (   Rl   RH   R   t   policiesR  R  t
   good_spaceR<   t   pairst	   other_idxR   t
   token_pairt   distancet   warningst   okRL   t	   constructt   countR   (    (   Rl   s5   lib/python2.7/site-packages/pylint/checkers/format.pyR     s2    	
((  !"c         C   s   |  j  d | k S(   Ni(   R   (   Rl   t   left(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyR     s    c      	   C   s   t  |  j f t |  j f t |  j f d g |  j f t |  j f d g |  j	 f d g |  j
 f d g |  j f g } i  } x/ | D]' \ } } x | D] } | | | <q Wq W| S(   Nt   =R   R   R   (   t   _KEYWORD_TOKENSR   t   _OPENING_BRACKETSR   R   R   R   t   _SPACED_OPERATORSR   R   R   R   (   Rl   t   rawt   dispatchRH   t   handlerR<   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   _prepare_token_dispatcher  s    	c         C   s  d g |  _ d g } t } d } i  |  _ i  |  _ |  j   } d |  _ d } t | |  j  |  _	 xYt
 |  D]K\ } \ } }	 }
 } } |
 d | k r |
 d } | t j k r |  j t |  | d | d  q |  j t |  | d |  n  | t j k rCt } |  j t |  |  |  j	 j   |  j |	 |  n| t j k rt } |  j |	 | d d |  | j | d d  n | t j k rt } t |  d k rX| d =qXn | t j k r| j d  s| } n  |  j t |  | d  |  j	 j   nH | t j k rX|  j	 j |  | rXt } |  j | | d |  qXn  | t j k r|	 j d  r|  j  d d | n  y | |	 } Wn t! k
 rqp X| | |  qp W| d 8} | |  j j" k rQ|  j# j$ j% d  } | j& d f } t' t( d t) |  j# j* j+ |   d  } |  j  d d	 | |  j j" f d | n  | | k r| d k r|  j  d
 d | n  d S(   s=  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).
        i    i   is   
t   ls   lowercase-l-suffixRO   s   too-many-linesRx   s   trailing-newlinesN(,   RA   R   R   R   R   R!  t   _last_line_endingR   R   R   R  RF   t   INDENTR   R~   R   R   t   _process_retained_warningsR   t   _check_line_endingt   check_indent_levelR[   t   DEDENTRX   RK   t   stript   _check_continued_indentationR   RG   R   t   NUMBERt   endswithR   t   KeyErrort   max_module_linesR   t
   msgs_storet   check_message_idt   msgidt   nextR   R   t   _pragma_linenot   get(   Rl   RH   t   indentst   check_equalR   t   token_handlerst   last_blank_line_numR   t   tok_typeR<   R   t   _RO   R   t   symbolt   names(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   process_tokens  sr    					(
$ 	
	!
c         C   s   |  j  d  k	 r7 | |  j  k r7 |  j d d | q7 n  | |  _  |  j j } | r t d   | d  } | d k ry d n d } | | k r |  j d d	 | | f d | q n  d  S(
   Ns   mixed-line-endingsRO   c         S   s   |  | k r |  | S|  S(   N(    (   t   xt   y(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   <lambda>s  s    RS   s   
R   R   s   unexpected-line-ending-formatRx   (   R#  RA   R   R   t   expected_line_ending_formatR    (   Rl   t   line_endingR   t   expected(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyR&  g  s    	c            s   t  | | d  } x |  j j D] \ } } } | | j |    t   f d   t j |  D  } | r   t k r |  j | | | |  q  | r    t	 k r  |  j | | | |  q  q  Wd  S(   NR   c         3   s-   |  ]# \ } } |   k r | | f Vq d  S(   N(    (   Ru   t   kt   v(   t
   block_type(    s5   lib/python2.7/site-packages/pylint/checkers/format.pys	   <genexpr>~  s    	(
   RJ   R   R   R   Rw   t   sixt	   iteritemsR{   t   _add_continuation_messageRz   (   Rl   RH   t   current_post   single_line_block_stmtt
   indent_posR   t   offsetst   hints(    (   RF  s5   lib/python2.7/site-packages/pylint/checkers/format.pyR%  y  s    %c            s      f d   } |  j  j s7  j    t j k r; d  S|  j  j    \ } } | t j  sq | t j  r t |  j	   d  <n  | j
 t t f k r  j	    | k r |  j  j   | |  n.  j	    | k r |  j | |     n  d  S(   Nc            s,    j     |  k o+  j    d  |  k S(   Ni   (   RE   (   t
   token_type(   t   next_idxRH   (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   same_token_around_nl  s    i   (   R   R   RE   RF   RK   R   RG   R   R   R   Rk   R   R   R   RI  (   Rl   RH   RP  RQ  R   R   (    (   RP  RH   s5   lib/python2.7/site-packages/pylint/checkers/format.pyR*    s    %c   	   
   C   so   t  | j \ } } t | | j |   \ } } |  j d d | j |  d | | | | j |  | f d  S(   Ns   bad-continuationRO   Rx   (   t   _CONTINUATION_MSG_PARTSRk   Rg   R   R   R   RO   (	   Rl   R   RM  RH   RL   t   readable_typet   readable_positiont	   hint_lineR`   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyRI    s    	s   multiple-statementsc         C   s  | j  s d S| j   j s  d S| j   } | d k	 rD | j } nS t | j t j	  r | | j j
 k r | j j d j d } n | j j   j } | j } | s t |   | | k r |  j j |  d k r |  j | |  d S| |  j k r d Sy | j } Wn t k
 r&| j } n X| s9t |   g  } xg t | | d  D]R } d |  j | <y | j |  j | j    WqSt k
 r| j d  qSXqSWd S(   s7   check the node line number and check it if not yet doneNi    i   i   RS   (   t   is_statementt   roott   pure_pythont   previous_siblingRA   t
   fromlinenot
   isinstancet   parentR   t
   TryFinallyt	   finalbodyt   bodyt   tolinenot	   statementt   AssertionErrorR   R4  t   _check_multi_statement_linet   blockstart_tolinenot   AttributeErrorR   R[   R   t   rstripR-  (   Rl   t   nodet	   prev_siblt	   prev_lineRO   R`  t   lines(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   visit_default  s<    		$c         C   s   t  | t j  r d St  | t j  rA t  | j t j  rA d St  | j t j  rs | j j rs |  j j	 rs d St  | j t j
  r t | j j  d k r |  j j r d S|  j d d | d |  j | <d S(   s/   Check for lines containing multiple statements.Ni   s   multiple-statementsRg  i   (   R[  R   t   Witht	   TryExceptR\  R]  t   Ift   orelseR   t   single_line_if_stmtt   ClassDefRX   R_  t   single_line_class_stmtR   R   (   Rl   Rg  RO   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyRc    s    "-c      
      s   j  j   j  j       f d   } d d d d d d d d d d	 h
 } g  } x | j t  D]s } | d
 | k r | j |  qg n  | r | j |  d j |  } g  } n  | | |  } | d k rg Pqg qg W| r | d j |  |  n  d S(   sB   check lines have less than a maximum number of characters
        c            s|  |  j  d  s%  j d d | n] |  j d  } | rP t  j j k rP n, |  t |  d k r|  j d d | n  | }  t j |   } | r*d |  k r*| j	 d  j
 d  \ } } } | j   d	 k r*d
 g  | j d  D] } | j   ^ q k rd  S|  j d d  d j   }  q*n  t |    k rt  j |   rt j d
 d | d t |    f n  | d S(   Ns   
s   missing-final-newlineRO   s   	
 s   
s   trailing-whitespaceR  i   t   disables   line-too-longR   t   #i    Rx   (   s   
s   
(   R,  R   Rf  t   _EMPTY_LINER   R   RX   R   t   searcht   groupt	   partitionR)  R   RA   t   rsplit(   RO   R   t   stripped_linet   mobjt   front_of_equalR:  t   back_of_equalt   _msg_id(   t   ignore_long_linet	   max_charsRl   (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt
   check_line  s$    !.""(u   u   u   u   u   u   u    u    iRS   N(   R   t   max_line_lengtht   ignore_long_linest
   splitlinesR   R[   R]   RA   (   Rl   Rj  R   R  t   unsplit_endst   unsplitRO   (    (   R  R  Rl   s5   lib/python2.7/site-packages/pylint/checkers/format.pyR     s6    		c   
   	   C   sU  |  j  j } | d k r! d } n  d } t |  } x( | |  | k r] | | } | d 7} q6 Wd } x | r | d d k r | d | d k r | d d k r d } n d } |  j d	 d
 | d | | S| | d 7} | d } qg W| | k s | rQd }	 | d d k rd }	 n  |  j d d | d
 | | t |  |	 | | f n  d S(   s.   return the indent level of the string
        s   \ts   	i    i   RS   s    	t   tabt   spaces   mixed-indentationRx   RO   t   spacest   tabss   bad-indentation(   R  R  (   R  R  N(   R   R   RX   R   RA   (
   Rl   t   stringRC  R   R   t   levelt	   unit_sizet   supplRx   t   i_type(    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyR'  "  s4    	
		N(.   Rn   Ro   R   R   R   R   t   __implements__t   namet   MSGSt   msgsR   R]   t   _DEFAULT_NO_SPACE_CHECK_CHOICESt   _NO_SPACE_CHECK_CHOICESR   R   Ru  t   optionsRA   Rm   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R!  R=  R&  R%  R*  RI  R	   Rk  Rc  R   R'  (    (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyR     s|   



"


					J								
		0			a					(		=c         C   s   |  j  t |    d S(   s.   required method to auto register this checker N(   t   register_checkerR   (   R   (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   registerB  s    (H   R   R   t   sysRF   t	   functoolsR    RG  t	   six.movesR   R   R   t   astroidR   t   pylint.interfacesR   R   R   t   pylint.checkersR   t   pylint.checkers.utilsR	   t   pylint.utilsR
   R   R   R   R  t   version_infoR[   R  R  R   RN   t	   frozensetR   RK   RG   R  R   R   R   R   R   R   Ru  R  R  t   NODER  R@   RD   RJ   RM   RR   Rg   t   objectRh   R   R   R   R   R   Rz   R{   RR  RZ   Ry   R}   R~   R   R   R  (    (    (    s5   lib/python2.7/site-packages/pylint/checkers/format.pyt   <module>#   s   









	
			
						  