
MV]c           @   s  d  d l  Z  d  d l m Z d  d l m Z m Z d  d l m Z d  d l m	 Z	 m
 Z
 m Z d d f Z d d	 d
 d d d d f Z d d d f Z d d d f Z d d d f Z d d d f Z d d d d d d d f Z d d  d! d" d# f Z d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d: f Z e e 7Z d; d< f Z d= d> d? f Z d@ e f dA     YZ dB e f dC     YZ dD e f dE     YZ dF e f dG     YZ dH e f dI     YZ dJ   Z dK e f dL     YZ dM e f dN     YZ dO e f dP     YZ  d S(Q   iN(   t   contextmanager(   t   ErrorFindert   ErrorFinderConfig(   t   Rule(   t   search_ancestort   Flowt   Scopet   import_namet   import_fromt   classdeft   funcdeft   if_stmtt
   while_stmtt   for_stmtt   try_stmtt	   with_stmtt   termt   powert   (t   [t   {t   )t   ]t   }t   +t   -t   ~t   *s   **t   /s   //t   @s   <<s   >>t   |t   &t   ^t   =t   %s   ->t   <t   >s   ==s   >=s   <=s   <>s   !=s   +=s   -=s   *=s   @=s   /=s   %=s   &=s   |=s   ^=s   <<=s   >>=s   **=s   //=t   dictorsetmakert   argumentt	   subscriptt   subscriptlistt   sliceopt   IndentationTypesc           B   s5   e  Z e   Z e   Z e   Z e   Z e   Z RS(    (   t   __name__t
   __module__t   objectt   VERTICAL_BRACKETt   HANGING_BRACKETt	   BACKSLASHt   SUITEt   IMPLICIT(    (    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyR*      s
   				t   IndentationNodec           B   s/   e  Z e j Z d d   Z d   Z d   Z RS(   c         C   s   | |  _  |  _ | |  _ d  S(   N(   t   bracket_indentationt   indentationt   parent(   t   selft   configR5   R6   (    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyt   __init__&   s    c         C   s   d |  j  j S(   Ns   <%s>(   t	   __class__R+   (   R7   (    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyt   __repr__*   s    c         C   s<   |  } x/ | d  k	 r7 | j t j k r+ | S| j } q	 Wd  S(   N(   t   Nonet   typeR*   R1   R6   (   R7   t   n(    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyt   get_latest_suite_node-   s
    N(	   R+   R,   R*   R1   R=   R<   R9   R;   R?   (    (    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyR3   #   s   		t   BracketNodec           B   s   e  Z e d   Z RS(   c   
      C   s  | |  _  | } | } | j t j k r3 | j } n  xj t r t | d  rd | j | j  j k rd Pn  | j   } t	 | t
  s | | j  k r Pn  | j } q6 W| j } | j   } d | j k r | | j |  _ | | j |  _ t j |  _ nM | j d }	 d | j k rd  |  _ n d |	 |  _ |  j |  _ t j |  _ | r| j t j k r|  j | | j k r|  j | j 7_ |  j |  _ n  | |  _ d  S(   Nt   leafs   
i   s   	t    (   RA   R=   R*   R2   R6   t   Truet   hasattrt   linet   get_previous_leaft
   isinstanceR@   R5   t   get_next_leaft   prefixt#   closing_bracket_hanging_indentationR4   R/   t   end_posR<   R.   R1   (
   R7   R8   RA   R6   t   in_suite_introducert   previous_leafR>   t   parent_indentationt	   next_leaft   expected_end_indent(    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyR9   7   s<    		$	(   R+   R,   t   FalseR9   (    (    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyR@   6   s   t   ImplicitNodec           B   s   e  Z d  Z d   Z RS(   sk   
    Implicit indentation after keyword arguments, default arguments,
    annotations and dict values.
    c         C   se   t  t |   j | | |  t j |  _ | j   } | d k ra d | j k ra |  j d 7_ n  d  S(   Nt   :s   
RB   (	   t   superRR   R9   R*   R2   R=   RH   RI   R5   (   R7   R8   RA   R6   RO   (    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyR9   q   s
    (   R+   R,   t   __doc__R9   (    (    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyRR   l   s   t   BackslashNodec           B   s   e  Z e j Z d d   Z RS(   c         C   s   t  | d  } | d  k	 r | j d } d | j k rC d  |  _ q | j | j k rh | | j |  _ q d | j d d |  _ n | | j |  _ |  j |  _ | |  _ d  S(   Nt	   expr_stmtis   	RB   i   (   R   R<   t   childrenR5   RK   t	   start_posR4   R6   (   R7   R8   RN   t   containing_leaft   spacingR6   RW   t   equals(    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyR9   }   s    N(   R+   R,   R*   R0   R=   R<   R9   (    (    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyRV   z   s   	c         C   s"   |  j  j d  o! |  j  j d  S(   Nt   __(   t   valuet
   startswitht   endswith(   t   name(    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyt   _is_magic_name   s    t   PEP8Normalizerc           B   s   e  Z d    Z e d    Z e d    Z d   Z d   Z e d  Z	 d   Z
 d   Z d   Z d	   Z d
   Z d   Z RS(   c         O   s   t  t |   j | |   d  |  _ d  |  _ t |  _ d |  _ d  |  _	 d |  _
 t |  _ t |  _ t |  j d d |  _ |  _ t |  _ d |  j j k r d |  _ d |  _ n d |  _ d |  _ d  S(   Ni    R5   t    RB   t   spacess   	t   tabs(   RT   Rc   R9   R<   t   _previous_partt   _previous_leafRC   t   _on_newlinet   _newline_countt   _wanted_newline_countt   _max_new_lines_in_prefixt   _new_statementRQ   t   _implicit_indentation_possibleR3   t   _configt   _indentation_tost   _last_indentation_tost   _in_suite_introducerR5   t   _indentation_typet   _wrong_indentation_char(   R7   t   argst   kwargs(    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyR9      s     											c      	   c   s>   t  t |   j |    |  j |  
 d  VWd  QXWd  QXd  S(   N(   RT   Rc   t
   visit_nodet   _visit_node(   R7   t   node(    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyRw      s    c         c   s  | j  } | d k ra | j   } t |  d k rDx( | d  D] } |  j | d d  q> WqDn| d k r | j } | j  d k rDt d   | j d  d d	  D  rD|  j | d
 d  qDn| d k rxq| j D]: } | j  d k r | j d k r |  j | d d  q q Wn)| d k rx| j D] } | j  d( k rLq1n  t | j  d	 k rgq1n  | j d } | j d } | j  d k r1| j  d k r1| j d k r1|  j | d d  Pq1q1Wnx | d k rD| j d }	 |	 j   }
 |	 j	 } | j
 d  rD| s+|
 d  k s+|
 j d k rD|  j |	 d d  qDn  | t k ro| j } | j } | j  d k ro| j j |  } x | j |  D] } | g } | j  d k r| j d  } n  t } x | D] } | j  d  k r| rqn  t } | j  d k r%t d!   | j   D  r%qn  | j  t k st | t  rIqn  |  j | d" d#  PqWqPqWqon  | t k } | t k } | rt |  _ nv | d$ k r|  j j  t j k r|  j j |  _ n  t |  j |  j j |  j j d% |  j |  _ n | rt |  _ n  d  V| d$ k rV|  j j  t j k s;t  |  j j |  _ d  |  _ ni | rt |  _ |  j j  t j  k r|  j j |  _ qn0 | rt |  _ | d) k r|  j!   |  _ qn  d  S(*   NR   i   i  s   Multiple imports on one linet   lambdefRW   c         s   s   |  ] } | j  d  k Vq d S(   Ra   N(   R=   (   t   .0R>   (    (    s0   lib/python2.7/site-packages/parso/python/pep8.pys	   <genexpr>   s    ii   i  s,   Do not assign a lambda expression, use a defR   t   keywordt   excepti  s1   Do not use bare except, specify exception insteadt
   comparisont	   atom_exprR   i    t   trailerRa   R=   i  s'   Do not compare types, use 'isinstance()t
   file_inputis   
i$  s   No newline at end of filet   simple_stmtt   stringc         s   s   |  ] } t  |  Vq d  S(   N(   Rb   (   R{   R>   (    (    s0   lib/python2.7/site-packages/parso/python/pep8.pys	   <genexpr>   s    i  s&   Module level import not at top of filet   suiteR6   R	   R
   (   R   R   (   R	   R
   ("   R=   t   get_defined_namest   lent	   add_issueR6   t   anyRX   R^   RF   RI   R`   R<   t   _IMPORT_TYPESt   indexRQ   RC   t   allRG   R   t   _IMPLICIT_INDENTATION_TYPESt   _SUITE_INTRODUCERSRr   Rp   R*   R0   R3   Ro   R5   Rn   R1   t   AssertionErrorRk   R2   t   _get_wanted_blank_lines_count(   R7   Ry   t   typt   namesRa   RW   t   childR   t   atomt	   endmarkert   prevRI   R   t   moduleR   RX   t   found_docstringt   ct   implicit_indentation_possiblet   in_introducer(    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyRx      s    		5	!					c         C   s4   |  j  | j k r0 |  j | d d |  j  t St S(   Nie   s   Indentation contains (   Rt   R^   R   Rs   RC   RQ   (   R7   R[   (    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyt   _check_tabs_spaces  s    c         C   s&   |  j  j   } t | j d  k  d S(   Ni   (   Rp   R?   t   intR6   R<   (   R7   t
   suite_node(    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyR      s    c         C   s  t  |  j |  j  |  _ |  j } | d  k	 r |  j d } | | k r | j d k r | s | d k rm d n d } d | | f } |  j | | |  d  |  _ q q d  |  _ n  | s|  j   } |  j d } | j }	 |	 d k r | j	 j d k pN|	 d	 k s<|	 d
 k r!| j
   d k s<|	 d k oN|  j d
 k oN| j	 j	 j d k }
 |
 r| | k  r| j	 } | j	 } | j d k r| j	 } n  | j t | j d k  | k r| d k rd n d } d | | f } |  j | | |  qn  d |  _ n  d |  _ d  S(   Ni   R   i   i.  i-  s    expected %s blank line, found %sR   t	   decoratort   classt   asynct   deft	   decoratedR   i    (   t   maxRl   Rj   Rk   R<   R=   R   R   R^   R6   RH   Rh   RX   R   (   R7   R[   RA   t
   is_commentt   wantedt   blank_linest   codet   messaget   actualt   valt   needs_linest   func_or_clsR   (    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyt   _reset_newlines$  sB    				"c         C   sJ  t  t |   j |  x@ | j   D]2 } | j d k r< Pn  |  j | | j   |  q# W|  j |  |  j | | |  |  j |  _	 | j d k |  _
 | j d k r |  j j t j k r |  j j |  _ n  | j d k r | j j t k r t |  _ n | j d k rt |  _ n  |  j
 s:|  j | |  d |  _ n  | |  _ | j S(   NR[   t   newlineRS   t   elifi    (   RT   Rc   t
   visit_leaft   _split_prefixR=   t   _visit_partt   create_spacing_partt   _analyse_non_prefixRp   Rq   Rm   R*   R0   R6   R^   R   RQ   Rr   RC   R   t   _max_blank_linesRh   (   R7   RA   t   part(    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyR   W  s*    !		c         C   s  | j  } | j } | d k r" d  S| d k rR | j j d k rR |  j j |  _ n  |  j } | d k r@| j d  r | j d  r'|  j | d d  q'n |  j r t j	 d	 |  r'| d k r'| j d
  o | j
 d? k r'|  j | d d  q'n( t j	 d |  s'|  j | d d  n  |  j | | d t n | d k r|  j |  j   k r~|  j | d d |  j  n7 | d@ k r| j j j d k r|  j | d d  n  |  j d 7_ n  | d k rn| j t j k r| j t j k r|  j | d d  qk| j } |  j rD| j t j k rD| |  j j 7} n  t |  j | | | d |  j |  _ qnD|  j r| j  } | j t j k r|  j j d k r|  j j |  _ n  |  j |  s| j } | d k r=|  j }	 xW t r9t |  t |	 j  k rPn  |	 j } |	 |  _ |	 | k r-Pn  |	 j }	 qWn  |  j r| d k rq| r|  j | d d   qq| | k rd! t |  j j  |  j f }
 |  j | d" d# |
  qq| d$ k r| j } n	 | j } |  j r| | j   j |  j j k r|  j | d% d&  q| | k r|  j |  r| j  d' k r| d$ k r| j t j k rw|  j | d( d)  q|  j | d* d+  qt |  t |  k  r3| j t j k r|  j | d, d-  q| j t j k r|  j | d. d/  q| j t j k r|  j | d0 d1  q|  j | d2 d3  q| j t j k r[|  j | d4 d5  q| j t j k r|  j | d6 d1  q|  j | d7 d8  qqqn |  j  | |  |  j! | |  | rR| d9 k rR| d k rR| j j d: k rR| t" k r(t# |  j | d |  j d; |  j |  _ q| j t j k s@t$  |  j j |  _ nQ | dA k r|  j% r| j j t& k r| j } t' |  j | d |  j |  _ n  | dB k |  _ | |  _ | |  _( d  S(C   Nt
   error_leaft   ,R%   t   comments   ##t   #i
  s'   Too many leading '#' for block comment.s   #:? s   #!i   i    i	  s$   Block comment should start with '# 's   #:? [^ ]i  s%   Inline comment should start with '# 'R   R   i/  s   Too many blank lines (%s)R   R   R   i0  s*   Blank lines found after function decoratort	   backslashi  s+   The backslash is redundant between bracketsR6   i#  s   Trailing whitespaces   %s %sio   s!   Indentation is not a multiple of s   ])}i   s+   Line with same indent as next logical blocks   
i|   s1   Closing bracket does not match visual indentationi{   sC   Losing bracket does not match indentation of opening bracket's linei   s2   Continuation line under-indented for visual indentiz   s2   Continuation line missing indentation or outdentedi   t   xxxiy   s3   Continuation line under-indented for hanging indenti   s1   Continuation line over-indented for visual indenti   i~   s2   Continuation line over-indented for hanging indents   ()[]{}t
   error_nodeRL   R!   RS   t   bom(   i   i    (   R   R   (   R!   RS   (   R   R   R   ()   R^   R=   R6   Rp   R_   t   lstripR   Ri   t   ret   matchRY   R   RC   Rj   R   R*   R0   R1   R5   Rr   Ro   RV   Rg   R   Rq   R   Rm   Rs   R4   R?   R.   R2   t   _check_spacingt   _check_line_lengtht   _OPENING_BRACKETSR@   R   Rn   R   RR   t   _previous_spacing(   R7   R   R[   RA   R^   t   type_Ry   R5   t   should_be_indentationR>   t   s(    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyR   y  s    				 													c         C   s   | j  d k r# | j d d } n | j d } | |  j j k r | j d |  j j k r t } | j  d k r | j d j   } t |  d k r | j d t | d  d k  r t	 } q n  | r |  j
 | d d | |  j j f  q n  d  S(   NR   i   R   i    iH   i  s"   Line too long (%s > %s characters)(   R=   RY   RK   Ro   t   max_charactersRC   R^   t   splitR   RQ   R   (   R7   R   R[   t   last_columnt   reportt   splitted(    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyR   	  s"    !c            s~     f d   }    f d   } | j     j } | d  k	 rQ | j d k s` | j d k rd d  S| j } d  k r   j | d d  n| d k r t     j j k  rz  j | d d	  qzn| d
 k r | | d d  nt   d k r  j | d d  ng| t k r?d | j  } | | d |  n;| t	 k rkd | j  } | | d |  n| d4 k s| d k r| j
 j t k rd | j  } | | d |  n| d k r| j
 j t k rn| d5 k r| | d d  n| d k rnv| d6 k r"| j
 j t k sz| d7 k rC| j
 j t k rCn7| t k rd| j
 j d k rdn| d k r| j
 j d k rn| t k s| t k r| d k r| j
 j d8 k s| d k r8| j
 j d9 k r8| d k r| j
 } n	 | j
 } | j d! k r%| j r%| | d" d#  q| | d$ d%  qz| t k sP| t k rc| | d& d'  qz| d( k s{| d( k r| | d) d*  qzd+ }	 | | d, |	  n | d- k s| j d- k r| | d. d/  n   j }
 | t k r' |
 j  k r'd0   j j k r'd1 }   j | d2 |  n   rz| t k rz| t k rzd+ }	 | t k rzd | j  } | | d3 |  qzn  d  S(:   Nc             s    r   j  |    Sd  S(   N(   R   (   Ru   (   R7   Re   (    s0   lib/python2.7/site-packages/parso/python/pep8.pyt   add_if_spaces!  s    c             s    s   j  |    Sd  S(   N(   R   (   Ru   (   R7   Re   (    s0   lib/python2.7/site-packages/parso/python/pep8.pyt   add_not_spaces%  s    R   s   	i   s   Used tab to separate tokensR   i  s)   At least two spaces before inline commentR   i#  s   Trailing whitespacei   i   s   Multiple spaces useds   Whitespace after '%s'i   s   Whitespace before '%s'i   R   t   ;RS   i   i   s   missing whitespace after '%s'R   s   **t   factorR   R   R!   R&   t   parami   s(   Expected spaces around annotation equalsi   s3   Unexpected spaces around keyword / parameter equalsi   s3   Missing whitespace around bitwise or shift operatorR"   i   s)   Missing whitespace around modulo operators!   Missing whitespace between tokensi   R|   i  s!   Missing whitespace around keywords   
s>   Whitespace before operator doesn't match with whitespace afteri   i   (   R   R   (   R   R   RS   (   R   s   **(   R   s   **(   R&   R   (   R&   R   (   R^   Rg   R<   R=   R   R   Ro   t   spaces_before_commentR   t   _CLOSING_BRACKETSR6   t   _POSSIBLE_SLICE_PARENTSt   _NON_STAR_TYPESt   _FACTORt   _NEEDS_SPACEt
   annotationt   _BITWISE_OPERATORR   t   _ALLOW_SPACERh   RI   (   R7   R   R[   R   R   R   R   R   R   t   message_225t   prev_spacing(    (   R7   Re   s0   lib/python2.7/site-packages/parso/python/pep8.pyR      s    		*			c         C   s  | j  } | d k r | j d4 k r | j   rd } | j j  d k rt | j j | k rt |  j | d | d  q | j j  d	 k r | j j | k r |  j | d
 | d	  q |  j d | d |  qn| j d k rgt | j t t	 f  r| j j  d k r| j
   } | j  d k rd| j j  d k rK|  j | d d  qa|  j | d d  qdqnG| j d k r| j
   j  d5 k r|  j | d d  q|  j | d d  n| j d6 k r| j } | j j |  } | j | d } | j | d } x| | f D] }	 |	 j  d k s4|	 j  d k r|	 j d k r`d  } |  j | d! |  Pq|	 j d7 k rd$ } |  j | d% |  PqqqWn| j d8 k r| j } | j  d( k r| j j  d) k r| j d& k r|  j | d* d+  q
|  j | d, d-  qn | d. k rzx t | j j   d  D]@ \ }
 } t j d/ |  j d0  } | j |
 t |  f } q3Wn4 | d k r|  j d1 k r|  j | d2 d3  qn  d  S(9   NRa   t   lt   Ot   Is0   Do not define %s named 'l', 'O', or 'I' one lineR   i  t   classest   functioni  i  t	   variablesRS   Rz   R   R
   i  s%   Multiple statements on one line (def)i  s'   Multiple statements on one line (colon)R   R   i  s   Statement ends with a semicoloni  s+   Multiple statements on one line (semicolon)s   ==s   !=i   R|   R<   s/   comparison to None should be 'if cond is None:'i  RC   RQ   sC   comparison to False/True should be 'if cond is True:' or 'if cond:'i  t   int   isR~   t   not_testi  s&   test for membership should be 'not in'i  s+   test for object identity should be 'is not'R   s   [ \t]*i    i   i  s   Blank line at end of file(   R   R   R   (   R   R   (   s   ==s   !=(   RC   RQ   (   R   R   (   R=   R^   t   is_definitionR6   Ra   R   t   add_issuadd_issueRG   R   R   RH   RX   R   t	   enumeratet
   splitlinesR   R   t   groupRE   R   Rj   (   R7   RA   R   R   RO   R~   R   t   leftt   rightRy   t   iRE   R5   RY   (    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyR   w  s`    	$$*		!& c         C   s   |  j  d  k	 rD t |  j  d  d  k	 r+ d  S|  j  j d k rD d  Sn  t | d  d  k	 r] d  S| d k r t t |   j | | |  n t t |   j | | |  d  S(   NR   R   i  i  (   i  i  (   Rh   R<   R   R=   RT   Rc   R   R   (   R7   Ry   R   R   (    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyR     s    (   R+   R,   R9   R    Rw   Rx   R   R   RQ   R   R   R   R   R   R   R   (    (    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyRc      s   	f		3	"			W	8t   PEP8NormalizerConfigc           B   s#   e  Z e Z d d d d d  Z RS(   RB   i   iO   i   c         C   sO   | |  _  | d  k r | } n  | |  _ d |  _ t |  _ | |  _ | |  _ d  S(   NRd   (   R5   R<   t   hanging_indentationRJ   RQ   t   break_after_binaryR   R   (   R7   R5   R   R   R   (    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyR9     s    						s       N(   R+   R,   Rc   t   normalizer_classR<   R9   (    (    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyR     s   t   BlankLineAtEndc           B   s   e  Z d  Z d Z d   Z RS(   i  s   Blank line at end of filec         C   s   |  j  d k S(   Ni   (   Rj   (   R7   RA   (    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyt   is_issue  s    (   R+   R,   R   R   R   (    (    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyR     s   (!   R   t
   contextlibR    t   parso.python.errorsR   R   t   parso.normalizerR   t   parso.python.treeR   R   R   R   R   R   R   R   R   R   R   R   R   R   R-   R*   R3   R@   RR   RV   Rb   Rc   R   R   (    (    (    s0   lib/python2.7/site-packages/parso/python/pep8.pyt   <module>   s>   	
6	  *