
    y`b^                    	   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZ	 ddlmZ ddlmZ n# e$ r dd	lmZ ddlmZ Y nw xY wddlZdd
lm Z  	 e! n# e"$ r e#Z!Y nw xY wdZ$dZ%dZ&dZ' ej(        d          Z) ej(        d          Z* ej(        d          Z+ ej(        d          Z, ej(        d          Z- ej(        d          Z. ej(        d          Z/ ej(        d          Z0 ej(        d          Z1dZ2dZ3dZ4dZ5 e6 e6dg           e6dg           e6g d           e6g d           e6g d           e6g d           g          Z7d!Z8d"Z9d#Z:d$gZ;d%gd&gd'gd(gd)gg d*d+Z<ej=        d,k    rej>        ?                    d-          Z@nCej>        A                     ejB        d.          pej>        ?                    d/          d0          Z@ej>        C                    e@          sYej=        d,k    rej>        ?                    d1          Z@n3ej>        A                    ej>        ?                    d/          d2          Z@d3ZDd4ZEdd7ZFdd8ZGd9 ZHd: ZI ejJ        eI           d; ZKejL        d<         ejK        =  ejJ        eK            G d= d>eM          ZNd? ZOd@ ZP	 	 ddDZQdE ZRdF ZSdG ZTdH ZUdI ZVddJZWdK ZXdL ZYdM ZZddNZ[ddPZ\ddQZ]	 	 ddTZ^ddUZ_dV Z`dW ZadX ZbdY ZcdZ Zd	 dd[Ze	 dd\Zfd] Zg ejh        d^g d_          Zi G d` daeM          Zj G db dceM          Zk G dd deeM          Zl G df dgel          Zm G dh diel          Zn G dj dkel          Zo G dl dmel          Zp G dn doel          ZqddpZrdq Zsdr Ztds Zudt Zvdu Zwdv Zxdw Zydx ZzddyZ{ G dz d{eM          Z|d| Z}d} Z~dd~Zd Zd Zd Zd Zd ZddZd ZddZd Zd Zd ZddZd ZddZddZd Zd Z	 	 ddZd Zd Zd Zd ZddZd Zd Zd Zd Zd Zd Zd Z	 ddZd Zd Zd Zd Z G d deM          Zd Zd Zd ZddZd Zd Zd Zd ZddZ G d deM          Z e            Zej        Zedk    r ej         e                       dS dS )a  Automatically formats Python code to conform to the PEP 8 style guide.

Fixes that only need be done once can be added by adding a function of the form
"fix_<code>(source)" to this module. They should return the fixed source code.
These fixes are picked up by apply_global_fixes().

Fixes that depend on pycodestyle should be added as methods to FixPEP8. See the
class documentation for more information.

    )absolute_import)division)print_function)unicode_literalsN)ConfigParser)Error)SafeConfigParser)!STARTSWITH_INDENT_STATEMENT_REGEXz1.6.0

z^#!.*\bpython[23]?\b\s*$z%([\w.]+)\s=\slambda\s*([)(=\w,\s.]*):z#\b(not)\s+([^][)(}{]+?)\s+(in|is)\sz\b(not\s+in|is\s+not)\sz
except\s*:z^(async\s+def|def)\s.*\):z^u?r?(?P<kind>["\']{3})z# *(fmt|autopep8): *onz# *(fmt|autopep8): *off      c   ,%)r   ([{r   r   r   r   )
r   r   r   r   r   +-*///)r   r   r   r   r   r   zE226,E24,W50,W690   W503W504W602ws_commaidiomshas_keynerepr)applyexceptexitfuncnumliteralsoperatorparenreducerenamesstandarderrorsys_excthrowtuple_params
xreadlines)E231E721W601W603W604W690win32z~\.pycodestyleXDG_CONFIG_HOMEz	~/.configpycodestylez~\.pep8pep8)z	setup.cfgztox.iniz.pep8z.flake8i   rc                 X    |st          | |          }t          j        | ||d          S )z,Return opened file with a specific encoding.limit_byte_check )modeencodingnewline)detect_encodingioopen)filenamerC   rD   rA   s       (lib/python3.11/site-packages/autopep8.pyopen_with_encodingrK      s@     P"8>NOOO78$       c                 \   	 t          | d          5 }ddlm} |                    |j                  d         }ddd           n# 1 swxY w Y   t          | |          5 }|                    |           ddd           n# 1 swxY w Y   |S # t          t          t          f$ r Y dS w xY w)zReturn file encoding.rbr   tokenizeNrD   zlatin-1)
rH   lib2to3.pgen2rP   rF   readlinerK   readLookupErrorSyntaxErrorUnicodeDecodeError)rI   rA   
input_filelib2to3_tokenizerD   	test_files         rJ   rF   rF      sQ   
(D!! 	PZBBBBBB'77
8KLLQOH	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P  8<<< 	-	NN+,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- &89   yysW   B 'AB A		B A	B !B7B BB 
BB B+*B+c                 |    t          |           5 }|                                cddd           S # 1 swxY w Y   dS )zReturn contents of file.N)rK   	readlines)rI   rX   s     rJ   readlines_from_filer]      s    	H	%	% &##%%& & & & & & & & & & & & & & & & & &s   155c              #   P  K   |                     d          r@|r:t          j                            |           rdd                    |          fV  dS dS dS t          j                            |          r%|r%|s%|s%|                      d          rd| v rdV  dS dS dS dS dS dS dS )z6Check for missing blank lines after class declaration.def r   zE303 too many blank lines ({})z(self)r   z#E301 expected 1 blank line, found 0N)
startswithr;   DOCSTRING_REGEXmatchformat)logical_lineblank_linesblank_beforeindent_levelprevious_logicals        rJ   extended_blank_linesri      s%      ""6** = 	L;6<<\JJ 	L6==kJJKKKKKK	L 	L 	L 	L		$	*	*+;	<	< 	= 	=	= 	= ##V--		=
 |##<<<<<<	= 	=	= 	= 	= 	= 	= 	= 	= 	=
 $#rL   c              #   4  K   |d         d         d         }d|d         d         d         z   |z
  }|s|dk    rdS |                      d          }dx}	}
|dk    rt          fnt          dt          z  f}dg|z  }dg|z  }dgg}dg}i }|d         d         }|d         g}d}d}d}d	}|D ]\  }}}}}|	|d         |z
  k     }|r*|d         |z
  }	| o|t          j        t          j        fv}|}|r|}t          j        |          |z
  ||	<   |t          j        k    o|d
v }t          ||
                   D ]}||	         ||         z
  }||v }|r n||
         r|||
         k    }| o |dk    o|	                    |d                   } |r;||
         r3|d         ||
         k    r|d
                    ||
                   fV  n,|r%|s#|r|d
                    ||
                   fV  n||
         r6|d         ||
         k     r$| dur|d
                    ||
                   fV  n|s|r@||	         dt          z  k    r,|r$|s"|d
                    |||         z             fV  |||
<   n| du r|d         ||
<   ns| |t          fv rng|||         z   t          z   }!|dk    rd|!f}"n;||
         rd||
         f}"n(|s||
         rd|!f}"n|t          k    rd|!f}"n	|||
<   d|!f}"| dj
        |" fV  ||	         r9|t          j        t          j        fvr||
         s|d         ||
<   d||d         <   n|t          j        t          j        fv s|dv rt          ||d         <   n^|s|	s|
s|dk    rd||d         dz   <   nC|dk    r=||d         d                                         r||
                             |	           |t          j        k    r|dv r|
dz  }
|                    d           |                    d           t!          |          |
k    r|                    g            ||
                             |	           ||	xx         dz  cc<   n|dv r|
dk    r|                                p|d         }#|                                 t%          |
          D ]}$||$         |#k    rd||$<   t'          |          D ]}%|%|#k    r||%= ||
dz   d= |
dz  }
|
rd|||
         <   t%          |	dd          D ]}&||&         r||&xx         dz  cc<    nt!          |          |
dz   k    sJ |d         |vr2|                                                     d          s|||d         <   |d         |d         k    }|r||	         ||d         |z
  <   |}|rz|szt          j        |          |t          z   k    r\|d         |d         dz   f}'|dt          z  z   }(| r|'d
                    |(          fV  dS |'d
                    |(          fV  dS dS dS dS )zCOverride pycodestyle's function to provide indentation information.r   r   r   r>   N:	rB   Fz]})zE124 {}zE133 {}TzE128 {}zE123 {}E122E127E131E126E121z{} {})uurbbrif([{z)]}r   r   zE129 {}zE125 {})endswithDEFAULT_INDENT_SIZErP   NLNEWLINEr;   expand_indentOPreversedgetrc   unicodeCOMMENTSTRINGisspaceappendlenpoprangelistrstrip))rd   tokensrg   hang_closingindent_charnoqa	first_rownrowsindent_nextrowdepthvalid_hangsparens
rel_indent	open_rowshangsindent_chanceslast_indentindentlast_token_multilineline	last_linelast_line_begins_with_multiline
token_typetextstartendrE   close_bracketopen_rowhanghanging_indentvisual_indentone_indentederrorprev_indentdindidxposdesired_indents)                                            rJ   continued_indentationr      s[      q	!QIr
1a  9,E uzz '',,KOC% $ 
%8%&)<%<%>  S5[F uJ IFE N)A,K!nFDI&+#.4 G G*
D%da9,, 	C(Y&C// I!(+x7G)HH .B+ @	6K *7==LJsO (8;6H45=M %Yu%566  !#H)==!%!4! EU| 8"&%,"6!.. :4!8 :+//a99   *6 *68ve},, )"2"26%="A"ABBBB &6t &6 C )"2"26%="A"ABBBB "658fUm#;#; ,, )"2"26%="A"ABBBB  66c?a*=&===  J J )"2"2<3=h3G4H #I #I J J J J#e$&& %au4/11 ,z(/C C 3!4 199#\2EEE] 3#VE]3EE& 35< 3#\2EE///#\2EE#'E%L#\2Engne45555 3K	)x{H,<===u > "!HF5M'+N58$$X_h.>???,,,'.N58$$   	) 	)E 	)ddll)-N3q6A:&&S[[T#a&'']2244[e##C((( $$u}}
a   T"""y>>U**$$R(((% '',,,sq 5199$jjll<k!n		u & &Aay;..$%q	// 0 0Ck))*3/eaijj)
 948N6%=1 b"--  Cc{ sq( v;;%!)++++a..$$&&//44 /
 ,0uQx( %aCF 2 	=-7_Js1v	)*		 	
:+
: 	!$''<:M+MMMQxQ'%,?(?? 	:	((88999999	((88999999
: 
: 
: 
: 	NMrL   rd   c                      e Zd ZdZ	 	 d-dZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d  Z!d! Z"d" Z#d# Z$d$ Z%d% Z&d& Z'd' Z(d( Z)d) Z*d* Z+d+ Z,d, Z-dS ).FixPEP8a  Fix invalid code.

    Fixer methods are prefixed "fix_". The _fix_source() method looks for these
    automatically.

    The fixer method can take either one or two arguments (in addition to
    self). The first argument is "result", which is the error information from
    pycodestyle. The second argument, "logical", is required only for
    logical-line fixes.

    The fixer method can return the list of modified lines or None. An empty
    list would mean that no changes were made. None would mean that only the
    line reported in the pycodestyle error was modified. Note that the modified
    line numbers that are returned are indexed at 1. This typically would
    correspond with the line number reported in the pycodestyle error
    information.

    [fixed method list]
        - e111,e114,e115,e116
        - e121,e122,e123,e124,e125,e126,e127,e128,e129
        - e201,e202,e203
        - e211
        - e221,e222,e223,e224,e225
        - e231
        - e251,e252
        - e261,e262
        - e271,e272,e273,e274
        - e301,e302,e303,e304,e305,e306
        - e401,e402
        - e502
        - e701,e702,e703,e704
        - e711,e712,e713,e714
        - e722
        - e731
        - w291
        - w503,504

    Nc                    || _         |t          |          | _        n-t          j        |          }|                                | _        || _        t          d                    | j                            | _	        i | _
        t          | j                  D ]J\  }}|                    d          dk    s|                    d          dk    r|| j
        vr
|| j
        |<   K|t                      n|| _        | j        | _        | j        | _        | j        | _        | j        | _        | j        | _        | j        | _        | j        | _        | j        | _        | j        | _        | j        | _        | j        | _        | j        | _        | j        | _        | j         | _!        | j         | _"        | j         | _#        | j$        | _%        | j$        | _&        | j$        | _'        | j         | _(        | j)        | _*        | j$        | _+        | j,        | _-        | j         | _.        | j         | _/        | j         | _0        | j1        | _2        |r|j3        dk    s|j4        r| j5        n| j6        | _7        | j8        | _9        | j:        | _;        | j:        | _<        d S )NrB   import r   from r   )=rI   r]   sourcerG   StringIOr\   options_get_indentwordjoinindent_wordimports	enumeratefindsetlong_line_ignore_cachefix_e112fix_e115_fix_reindentfix_e121fix_e122fix_e123fix_e124fix_e126fix_e127fix_e128fix_e129fix_e131fix_e133fix_e201fix_e202fix_e203fix_e211fix_e271fix_e221fix_e222fix_e223fix_e225fix_e226fix_e227fix_e228fix_e241fix_e224fix_e242fix_e252fix_e262fix_e261fix_e272fix_e273fix_e274fix_e301fix_e306
aggressiveexperimentalfix_long_line_logicallyfix_long_line_physicallyfix_e501fix_e702fix_e703fix_w291fix_w292fix_w293)selfrI   r   contentsr   sioir   s           rJ   __init__zFixPEP8.__init__  sC    !-h77DKK+h''C--//DK*2774;+?+?@@  -- 	' 	'GAt		)$$))TYYw-?-?1-D-D,,%&T" ,3CEEE' 	# ******** * +q00G4H0 (() 	 rL   c           	      R   	 t          | j                  \  }}d}n# t          t          j        f$ r d}Y nw xY wt                      }t          |t                    D ]G}|d         |v rd|d                                         z   }t          | |          rqt          | |          }|d         dz
  }	| j        |	         }
t          t          |                    dk    }|ryd }|rht          | j        |||          }|rOt          t          |d	         d	         dz   |d         d	         dz                                           |          r |||          }n ||          }||rJ | j        |	         |
k    rg }|r|                    |           <|g k    rN| j        j        dk    r<t'          d
                    |d         |d                   t*          j                   |                    |d                    | j        j        dk    rt'          d                    |          t*          j                   |d                                         }t'          d                    | j        |d         |d         |          t*          j                   Id S )NTFkeyr   fix_idr   r   r   z'--->  Not fixing {error} on line {line})r   r   file   z--->  '{}' is not defined.infoz--->  {}:{}:{}:{}column)_find_logicalr   rV   rP   
TokenErrorr   sorted_priority_keylowerhasattrgetattrr   _get_parameters_get_logicalr   intersectionupdater   verboseprintrc   sysstderraddstriprI   )r   resultslogical_startlogical_endlogical_supportcompleted_linesresultfixed_methodnamefix
line_indexoriginal_lineis_logical_fixlogicalmodified_linesr   s                  rJ   _fix_sourcezFixPEP8._fix_source  s   	$+8+E+E(]K"OOX01 	$ 	$ 	$#OOO	$ %%W-888 9	+ 9	+Ff~00%t(:(:(<(<<t-.. 4+d$455#F^a/
 $J 7!$_S%9%9!:!:Q!>! 1"G& 	%".t{/5/</:#< #< # %s5#AJqMA-#AJqMA-,/ ,/ (0 (00< /11 11% %%(S%9%9NN%(S[[N!)----{:.-??)+! 	8#**>::::#r))|+q00ELL&,Tl M I I!$- - - -
 $''v7777<'1,,4;;<LMM Z) ) ) ) "&>//11D-44T]5;F^5;H5E59; ;  #z	+ + + +k9	+ 9	+s    77c                 h   | j         j        | j         j        | j         j        | j         j        d}t          || j                  }| j         j        ri }|D ]J}|d         |vrt                      ||d         <   ||d                  	                    |d                    Kt          d                    t          |          |          t          j                   | j         j        r| j         j        \  fd|D             }|                     t#          d                    | j                  || j         j        	                     | j         j        r>t)          d
 | j        dz
           D                       }|z   dz
  | j         j        d<   d                    | j                  S )z@Return a version of the source code with PEP 8 violations fixed.ignoreselectmax_line_lengthr   r   r   z$--->  {n} issue(s) to fix {progress})nprogressr   c                 @    g | ]}|d          cxk    rk    n n|S r    ).0r=   r   r   s     rJ   
<listcomp>zFixPEP8.fix.<locals>.<listcomp>q  sH     5 5 5Q1V9333333333 333rL   rB   )r   r  r   c              3   @   K   | ]}|                     d           V  dS )r   Ncount)r'  slines     rJ   	<genexpr>zFixPEP8.fix.<locals>.<genexpr>z  sJ       A A! D)) A A A A A ArL   r   )r   r  r   r!  r   _execute_pep8r   r	  r   r  r
  rc   r   r  r  
line_ranger  filter_resultsr   r   sum)r   pep8_optionsr  r#  r=   r+  r   r   s         @@rJ   r  zFixPEP8.fix\  s    l)l)#|; L5	
 
  dk::< 	EH 1 1T7(**(+HQtW%4!%%ai00008??g,, @ 3 39<E E E E <" 	50JE35 5 5 5 5' 5 5 5G 	rwwt{/C/C0737<3JL L L 	M 	M 	M <" 	; A A%)[3%?A A A A AE).):DL#A&wwt{###rL   c                     t          |d                                         d                   }|d         dz
  }| j        |         }d|z  |                                z   | j        |<   dS )znFix a badly indented line.

        This is done by adding or removing from its initial indent only.

        r   r   r    N)intsplitr   lstrip)r   r  num_indent_spacesr  targets        rJ   r   zFixPEP8._fix_reindent  sf      v 4 4 6 6q 9::F^a'
Z("%(9"9FMMOO"KJrL   c                     |d         dz
  }| j         |         }|                                                    d          sg S | j        |z   | j         |<   dS )zFix under-indented comments.r   r   #N)r   r7  r`   r   )r   r  r  r9  s       rJ   r   zFixPEP8.fix_e112  sY    F^a'
Z(}}))#.. 	I"&"2V";JrL   c                     |d         dz
  }| j         |         }t          |          }|                                }|dd         |z   | j         |<   dS )zFix unexpected indentation.r   r   Nr   _get_indentationr7  r   r  r  r9  r   strippeds         rJ   fix_e113zFixPEP8.fix_e113  sU    F^a'
Z(!&))==??"(*x"7JrL   c                     |d         dz
  }| j         |         }t          |          }|                                }|                    d          sg S |dd         |z   | j         |<   dS )zFix over-indented comments.r   r   r;  N)r   r>  r7  r`   r?  s         rJ   fix_e116zFixPEP8.fix_e116  sp    F^a'
Z(!&))==??""3'' 	I"(*x"7JrL   c                     |d         dz
  }| j         |         }t          |          }|dk    rg S |                                }|dd         |z   | j         |<   dS )zFix over-indented.r   r   rl   Nr=  r?  s         rJ   fix_e117zFixPEP8.fix_e117  sc    F^a'
Z(!&))T>>I==??"(*x"7JrL   c                 &   t          |d                                         d                   }|d         dz
  }| j        |         }|t          t	          |                    z
  }t          t	          |                    }g }t          t	          | j        |                             |k    rcd|z  | j        |         z   | j        |<   |                    d|z              |dz  }t          t	          | j        |                             |k    c|S )9Fix indentation undistinguish from the next logical line.r   r   r   r4  )r5  r6  r   r   r>  r   )r   r  r8  r  r9  spaces_to_addr   r  s           rJ   fix_e125zFixPEP8.fix_e125  s   v 4 4 6 6q 9::F^a'
Z()C0@0H0H,I,II%f--.."4;z#:;;<<FF'*]':'+{:'>(?DK
#!!!j.111!OJ	 "4;z#:;;<<FF rL   c                    t          |d                                         d                   }|d         dz
  }| j        |         }|t          t	          |                    z
  }t          t	          |                    }||z
  }|dk    r|dk    rd}|dk    rd|z  | j        |         z   | j        |<   dS t          |          }| j        |         |d         | j        |<   dS )rG  r   r   r   r   r   r4  N)r5  r6  r   r   r>  abs)r   r  r8  r  r9  rH  indent_lengthoffsets           rJ   r   zFixPEP8.fix_e131  s    v 4 4 6 6q 9::F^a'
Z()C0@0H0H,I,II,V4455)M9!!mq&8&8MA'*]':'+{:'>(?DK
### ''F&*k*&=fgg&FDK
###rL   c                     |d         dz
  }| j         |         }|d         dz
  }t          ||d          }|| j         |<   dS )zRemove extraneous whitespace.r   r   r   rB   rM  replacementNr   fix_whitespacer   r  r  r9  rM  fixeds         rJ   r   zFixPEP8.fix_e201  s[    F^a'
Z(!A%v&,+-/ / / #(JrL   c                     | j         |d         dz
           }|d         dz
  }|d|         ||d                             dd          z   }|| j         |d         dz
  <   dS )z-Remove extraneous whitespace around operator.r   r   r   Nrl   r4  )r   replace)r   r  r9  rM  rT  s        rJ   r   zFixPEP8.fix_e224  sk    VF^a/0!A%ww&/"9"9$"D"DD*/F6NQ&'''rL   c                 4   | j         |d         dz
           }|d         dz
  }|d|         dz   ||d         z   }|                    dd          |                    dd          k    r/t          |          t          |          k    r|| j         |d         dz
  <   |                    dd          }	 t	          |          }n# t
          t          j        f$ r Y dS w xY wt          |	                                          sdS t          t          j        ||                    }t          |          D ]M}||d                                         d         k    r'|d         d         }|d|         dz   ||d         z   }N|| j         |d         dz
  <   dS g S )	z'Fix missing whitespace around operator.r   r   r   Nr4  rB   r   r   )r   rV  r>  r   generate_tokensrV   rP   r   check_syntaxr7  r   r;   "missing_whitespace_around_operatorr~   r6  )	r   r  r9  rM  rT  
error_codetserrorses	            rJ   r   zFixPEP8.fix_e225  s   VF^a/0!A%ww#%vww7
 MM#r""fnnS"&=&===U##'7'?'???.3DKv*+D!,,J$U++!45   // >ubIIK KFf%% > >1a001agvg,uVWW~=.3DKv*+++Is   4C CCc                     |d         dz
  }| j         |         }|d         }|d|                                         dz   ||d                                         z   }|| j         |<   dS )zAdd missing whitespace.r   r   r   Nr4  )r   r   r7  rS  s         rJ   fix_e231zFixPEP8.fix_e231  so    F^a'
Z(!ww&&((3.1G1G1I1II"'JrL   c                 ,   |d         dz
  }| j         |         }t          |d         dz
  t          |          dz
            }||                                         r|}n9|d|                                         ||d                                         z   }|                    d          rT|                    d          | j         |<   | j         |dz                                            | j         |dz   <   |dz   |dz   gS || j         |d         dz
  <   dS )z,Remove whitespace around parameter '=' sign.r   r   r   N)z=\
z=\
z=\
 	\r   )r   minr   r  r   r7  rx   )r   r  r  r9  crT  s         rJ   fix_e251zFixPEP8.fix_e251  s   F^a'
Z(
 x 1$Fa! ! !9?? 	>EE2A2J%%''&**;*;*=*==E >>788 	4&+ll;&?&?DK
#*.+j1n*E*L*L*N*NDK
Q'NJN33*/F6NQ&'''rL   c                    | j         |d         dz
           }|d         }|d|                             d          }||d                             d          }||                                rd|z   ndz   }|| j         |d         dz
  <   dS )zFix spacing after comment hash.r   r   r   N 	#z  # r   )r   r   r7  r  )r   r  r9  rM  codecommentrT  s          rJ   r   zFixPEP8.fix_e2625  s    VF^a/0!gvg%%f--/((00GMMOOE((F*/F6NQ&'''rL   c                     |d         dz
  }| j         |         }|d         dz
  }t          ||d          }||k    rg S || j         |<   dS )z*Fix extraneous whitespace around keywords.r   r   r   r4  rO  NrQ  rS  s         rJ   r   zFixPEP8.fix_e271A  si    F^a'
Z(!A%v&,+.0 0 0 F??I&+DK
###rL   c                 ^    d}|| j         |d         dz
           z   | j         |d         dz
  <   dS )zAdd missing blank line.r   r   r   N)r   )r   r  crs      rJ   r   zFixPEP8.fix_e301P  s7    *,t{6&>A;M/N*NF6NQ&'''rL   c                 $   dt          |d                                         d                   z
  }d}| j        |d         dz
                                           dk    rd}d|z  }|| j        |d         |z
           z   | j        |d         |z
  <   dS )	zAdd missing 2 blank lines.r   r   r>   r   r   \r   N)r5  r6  r   r  )r   r  add_linenumrM  rl  s        rJ   fix_e302zFixPEP8.fix_e302U  s    #fVn2244R8999;vf~)*0022d::FKVF^f455 	F6NV+,,,rL   c                    t          |d                             d          d                             d          d                   dz
  }t          d|          }d}|d         dz
  }g }||k     r]|dk    rW| j        |                                         s'd| j        |<   |                    d|z              |dz  }|dz  }||k     r|dk    W|S )	zRemove extra blank lines.r   r   r   )r   r   r   rB   )r5  r6  maxr   r  r   )r   r  delete_linenumcntr   r  s         rJ   fix_e303zFixPEP8.fix_e303`  s    VF^11#66q9??DDQGHH1LQ// f~!N""tqyy;t$**,, $&D!%%a$h///qAID N""tqyy rL   c                 r    |d         dz
  }| j         |                                         sd| j         |<   dS dS )z/Remove blank line following function decorator.r   r   rB   N)r   r  )r   r  r   s      rJ   fix_e304zFixPEP8.fix_e304s  sG    f~!{4 &&(( 	# "DK	# 	#rL   c                 ^   dt          |d                                         d                   z
  }d}|d         dz
  }g }|dk     rst          |          }||k     r]|dk    rW| j        |                                         s'd| j        |<   |                    d|z              |dz  }|dz  }||k     r|dk    Wntd}	 |dk     rn5| j        |                                         }|sn|d         d
k    rn|dz  }<|dz  }|| j        |         z   | j        |<   |                    d|z              |S )z9Add missing 2 blank lines after end of function or class.r   r   r>   r   r   rB   r   r   Tr;  )r5  r6  rK  r   r  r   r7  )r   r  add_delete_linenumru  rM  r  rl  r   s           rJ   fix_e305zFixPEP8.fix_e305y  sr   VF^%9%9%;%;B%?!@!@@!#!!!$%7!8!8***v{{{6*0022 *,DK'"))!f*5551HC! ***v{{ BA::{6*1133 7c>>! aKF"$t{6':":DK!!!f*---rL   c                 t   |d         dz
  }| j         |         }|d         dz
  }|                                                    d          sg S t          j        d|d          d         }|d|                             d	          d
z   |z   dz   ||d                             d	          z   }|| j         |<   dS )zPut imports on separate lines.r   r   r   importz
\bimport\b)patternstringmaxsplitr   Nz	 ,r   r   )r   r7  r`   rer6  r   )r   r  r  r9  rM  indentationrT  s          rJ   fix_e401zFixPEP8.fix_e401  s    F^a'
Z(!A%}}))(33 	Ih}&,q: : ::;=''//$6()+1&''?+A+A&+I+IJ"'JrL   c                    t          || j                  \  }}}t          dd          D ]g}d                    | j        |||z                      }	 t	          d                    |                     n# t
          t          j        f$ r Y cw xY w || j        v r| j        |         |k    s-t          | j        |          }|| j        |         z   | j        |<   t          |          D ]}d| j        ||z   <   d S )Nr   d   rB   )
get_index_offset_contentsr   r   r   rX  rV   rP   r   r   !get_module_imports_on_top_of_file)r   r  r  rM  r9  r   r   
mod_offsets           rJ   fix_e402zFixPEP8.fix_e402  s%   '@AE(N (N$VVq# 	 	A774;z*Q,'>?@@D....!45   $,&&4<+?:+M+M:4;;EG GJ&*T[-D&DDK
#Ahh 	0 	0F-/DK
6)**	0 	0s   "A55BBc                    |rTt          |d                   dk    s;| j        |d         dz
                                                               d          r|                     |          S |d         d         }|d         d         }|d         }t          | j        |dz
  d          }t          | j        |dz   d          }t          d                    |                    }	 |                     |||d                    |                    }	n1# t          t          j        f$ r |                     |          cY S w xY w|	r@t          ||dz             D ]}
d| j        |
<   |	| j        |<   t          |dz   |dz             S g S )	:Try to make lines fit within --max-line-length characters.r   r   r   r;  r   rB   defaultr9  previous_line	next_lineoriginal)r   r   r7  r`   r   get_itemjoin_logical_liner   fix_long_linerV   rP   r   r   )r   r  r  start_line_indexend_line_indexlogical_linesr  r  single_linerT  r  s              rJ   r   zFixPEP8.fix_long_line_logically  s    	9
OOq  Kv*+2244??DD ! 00888"1:a= A
 .>.BBOOOT[.1*<bIII	'(>(>??	9&&"+#//	 ' 1 1EE
 X01 	9 	9 	90088888	9  	C#$4nq6HII - -
*,J'',1DK())A-~/ABBB	s   ',D +EEc                 4   |d         dz
  }| j         |         }t          | j         |dz
  d          }t          | j         |dz   d          }	 |                     ||||          }n# t          t          j        f$ r g cY S w xY w|r|| j         |<   |dz   gS g S )r  r   r   rB   r  r  )r   r  r  rV   rP   r   )r   r  r  r9  r  r  rT  s          rJ   r   z FixPEP8.fix_long_line_physically  s    F^a'
Z( j1nbIIIT[*q."EEE		&&+#	 ' ! !EE
 X01 	 	 	III	  	$&+DK
#N##	s   A( (BBc           
         |||f}|| j         v rg S |                                                    d          rP| j        j        rBt          || j        j        |                                                    d                     S g S t          |||| j        | j        j        | j        j        | j        j	        | j        j
                  }|rt          ||          s|S | j                             |           d S )Nr;  )r   r!  last_comment)r9  r  r  r   r!  r   r   r	  )r   r7  r`   r   r   shorten_commentr!  get_fixed_long_liner   r   r	  code_almost_equalr  )r   r9  r  r  r  cache_entryrT  s          rJ   r  zFixPEP8.fix_long_line  s   }i8$555I==??%%c** 	|& I&$(L$@%.%5%5%7%7%B%B3%G%G!GI I I I I#'( L8|.2L(* * *  	*8U;; 	L#''444trL   c                 x    t          || j                  \  }}}|                    d          dz   | j        |<   dS )z$Remove extraneous escape of newline.rb  r   N)r  r   r   )r   r  r  _r9  s        rJ   fix_e502zFixPEP8.fix_e502  sD    ";F<@K#I #IQ"(--"<"<t"CJrL   c                    |d         dz
  }| j         |         }|d         }|d|         dz   t          |          z   | j        z   ||d                             d          z   }|| j         |d         dz
  <   |d         |d         dz   gS )z9Put colon-separated compound statement on separate lines.r   r   r   Nr   rb  )r   r>  r   r7  )r   r  r  r9  rd  fixed_sources         rJ   fix_e701zFixPEP8.fix_e701  s    F^a'
Z(8rr
T)(001373CDqrr
))+667 +7F6NQ&'vv 233rL   c                    |sg S |d         }|D ]k}|d         dk    r]d|v rYt          j        |          rE| j        j        r5t	          d                    |d                   t          j                   g c S l|d         d	z
  }| j        |         }|	                                
                    d
          rT|	                    d          | j        |<   | j        |d	z                                            | j        |d	z   <   |d	z   |dz   gS |	                                
                    d          r&|	                    d          dz   | j        |<   |d	z   gS |d         d	z
  }|d|         	                    d          	                                }t          |d                   ||d                             d                                          z   }	d}
||d                             d                                          dd         dk    r||d                             d          }
|
r||
z   | j        |<   n|dz   |	z   | j        |<   |d	z   gS )z=Put semicolon-separated compound statement on separate lines.r   r   E702rk   z8---> avoid fixing {error} with other compound statements)r   r   r   r   rn  z
 	\;z
 	;r   r   Nr   # )r
   rb   r   r	  r
  rc   r  r  r   r   rx   r7  r>  )r   r  r  r  r   r  r9  rM  firstsecondinline_comments              rJ   r   zFixPEP8.fix_e702%  sz    	I
 " 		 		Dt&&3$;;9?EE ,7<' 44:FF4N4N Z   
 			F^a'
Z(==??##D)) 	4&,mmK&@&@DK
#*.+j1n*E*L*L*N*NDK
Q'NJN33==??##C(( 	$&,mmJ&?&?$&FDK
#N##!A%ww&&s++2244"=#344/((--44667 &''?!!#&&--//3t;;#FGG_33C88N 	<&+n&<DK
##&+dlV&;DK
#QrL   c                 \   t          || j                  \  }}}t                              |          }|rvd                    |                    d          t          |          | j        z   ||                    d          d         	                                          | j        |<   dS dS )z'Fix multiple statements on one line defz{}
{}{}r   N)
r  r   STARTSWITH_DEF_REGEXrb   rc   groupr>  r   r   r7  r   r  r  r  r9  rb   s         rJ   fix_e704zFixPEP8.fix_e704U  s    ";F<@K#I #IQ$**622 	0&0&7&7A ((4+;;uyy||}}%,,..'0 '0DK
###	0 	0rL   c                    t          || j                  \  }}}|dz   }|t          |          k    rg S |d|                                         }|||         }||d                                         }|                                dk    rd}	n|                                dk    rd}	ng S d                    ||	|g          | j        |<   dS )zFix comparison with None.r   N==is!=is notr4  )r  r   r   r   r7  r  r   )
r   r  r  rM  r9  right_offsetleftcenterright
new_centers
             rJ   fix_e711zFixPEP8.fix_e711`  s    '@AE(N (N$VV z3v;;&&Igvg%%''|+,|}}%,,..<<>>T!!JJ\\^^t##!JJI"%((D*e+D"E"EJrL   c                 F   t          || j                  \  }}}t          j        d|          r"t          j        dd|d          | j        |<   d	S t          j        d|          r"t          j        dd|d          | j        |<   d	S |dz   }|t          |          k    rg S |d	|                                         }|||         }||d	                                         }d	}	|                                d
k    r.t          j        d|          rt          j        dd|d          }	nE|                                dk    r-t          j        d|          rt          j        dd|d          }	|	g S |	d         	                                rd|	z   }	||	z   | j        |<   d	S )z.Fix (trivial case of) comparison with boolean.z^\s*if [\w."\'\[\]]+ == False:$zif ([\w."\'\[\]]+) == False:z
if not \1:r   r*  z^\s*if [\w."\'\[\]]+ != True:$zif ([\w."\'\[\]]+) != True:r   Nr  z\bTrue\bz
\bTrue\b *rB   r  z	\bFalse\bz\bFalse\b *r   r4  )
r  r   r  rb   subr   r   r7  r  isalnum)
r   r  r  rM  r9  r  r  r  r  	new_rights
             rJ   fix_e712zFixPEP8.fix_e712v  s   '@AE(N (N$VV 86?? 	7&(f-L-:F!'M 'M 'MDK
###X7@@ 	7&(f-K-:F!'M 'M 'MDK
### "A:Ls6{{**	'6'?))++DF</0F<==)0022E I||~~%%8K// J "}b%q I I II4''8L%00 K "~r5 J J JI 	|##%% ,)O	&*Y&6DK
###rL   c           	      H   t          || j                  \  }}}|d|         }||d         }t                              |          }d\  }}|rP|                    d          }|                                }d                    |d|         d||d                   }t                              |          }	|	r|	                    d          dk    r|	                    d          }
d                    |d|
         |	                    d          |	                    d          |	                    d          ||	                                d         |          }|r4||z   }
||z   d	z
  }d                    |d|
         d
||d                   }|| j        |<   dS dS dS )z+Fix (trivial case of) non-membership check.Nr   r   r   {}{} {}inr   {5}{0}{1} {2} {3} {4}r   r   znot in)	r  r   COMPARE_NEGATIVE_REGEX_THROUGHsearchr   r   rc   COMPARE_NEGATIVE_REGEXr  )r   r  r  rM  r9  before_targetmatch_notinnotin_pos_startnotin_pos_endrb   	pos_start
new_targetpos_ends                rJ   fix_e713zFixPEP8.fix_e713  s   '@AE(N (N$VV ww4;;FCC)-& 	H)//22O'OO--M%%''($}~~0FH HF '--f55 	5{{1~~%%!KKNN	4;;:I:&AAKKNNF599;;<<$8-I I
  P /& 8I+f4q8G!*!1!1":I:.*WXX:N"P "PJ*4J'''	5 	5%%rL   c           	      f   t          || j                  \  }}}|d|         }||d         }t                              |          }d\  }}|rP|                    d          }|                                }d                    |d|         d||d                   }t                              |          }	|	r|	                    d          	                    d          r|	                    d          }
d                    |d|
         |	                    d	          |	                    d          |	                    d          ||	                                d         |          }|r4||z   }
||z   d
z
  }d                    |d|
         d||d                   }|| j        |<   dS dS dS )z,Fix object identity should be 'is not' case.Nr  r   r  r  r   r  r  r   r   r  )
r  r   r  r  r   r   rc   r  r  r`   )r   r  r  rM  r9  r  match_isnotisnot_pos_startisnot_pos_endrb   r  r  r  s                rJ   fix_e714zFixPEP8.fix_e714  s   '@AE(N (N$VV ww4;;FCC)-& 	H)//22O'OO--M%%''($}~~0FH HF '--f55 	5{{1~~((.. 5!KKNN	4;;:I:&AAKKNNF599;;<<$8-I I
  P /& 8I+f4q8G!*!1!1":I:.*WXX:N"P "PJ*4J'''	5 	55 5rL   c                    t          || j                  \  }}}t                              |          }|rLd                    |d|d         dz
           d||                                d                   | j        |<   dS dS )zfix bare except{}{}{}Nr   r   zexcept BaseException:)r  r   BARE_EXCEPT_REGEXr  rc   r   r  s         rJ   fix_e722zFixPEP8.fix_e722  s    ";F<@K#I #IQ!((00 	&&.oo,x(1,,-/Fuyy{{||$'& '&DK
###	& 	&rL   c                    t          || j                  \  }}}t                              |          }|r|                                }d                    |d|                    d                   |                    d          |                    d          ||d                                                   | j        |<   dS dS )z,Fix do not assign a lambda expression check.z{}def {}({}): return {}Nr   r   r   )	r  r   LAMBDA_REGEXr  r   rc   r   r  r7  )r   r  r  r  r9  rb   r   s          rJ   fix_e731zFixPEP8.fix_e731  s    ";F<@K#I #IQ##F++ 	'))++C&?&F&FA'QQstt##%%'' ''DK
###	' 	'rL   c                     | j         |d         dz
                                           }|dz   | j         |d         dz
  <   dS )zRemove trailing whitespace.r   r   r   N)r   r   )r   r  
fixed_lines      rJ   r   zFixPEP8.fix_w291  sC    [!!34;;==
*4t*;F6NQ&'''rL   c                     d}t          | j                  D ]}|                                }|r n|dz  } t          | j                  }| j        d||z
           | _        t	          dd|z             S )zRemove trailing blank lines.r   r   N)r~   r   r   r   r   )r   r  blank_countr   original_lengths        rJ   fix_w391zFixPEP8.fix_w391  s    T[)) 	! 	!D;;==D !q dk**k"@?[#@"@AQO+,,,rL   c                 :   t          || j                  \  }}}|                                d         }	 t          |          }n# t          t
          j        f$ r Y d S w xY wt          |d         d         |          sd S d}d}d}	t          d          D ]}
||
z
  dk     r n||
z
  dz
  }|dk     st          | j                  |k    r nj|dz   }| j        |         
                                }|s|r|d         dk    r|	dz  }	rd}	 t          d                    | j        ||                             }n# t          t
          j        f$ r Y w xY wd}g }t          |          D ]?\  }}|d         t
          j        t
          j        fv r|                    |           |dz  }@|dk    r||d	         d          }n|}g }|D ]o}|d         t
          j        t
          j        fv r|dz  }|dk    r nAt
          j        |d         k    r(|r&|d         t
          j        k    r|d
         d         } n|}p |                    |          }
|dz
  |	z
  }d                    |d |
         ||
t          |          z   d          
                                          | j        |<   t'          | j        ||                   }| j        |         }|                    |          }|r4d                    |d |         |||dz   d                    | j        |<   d S |d |                             d          r7d                    |d |dz
           |||dz
  d                    | j        |<   d S d                    |d |         |||d                    | j        |<   d S )Nr   F   r   r;  TrB   r   r   {}{}z{} {} {}r  z{} {}{})r  r   r6  rX  rV   rP   r   _is_binary_operatorr   r   r7  r   r   r{   rz   r   r   indexrc   find_newlinerx   )r   r  r  r  r9  one_string_tokenr\  comment_indexfound_not_comment_only_linecomment_only_linenumr   
from_indexto_index
strip_linenewline_countnewline_indexr  tttsoldfix_target_linenlbefore_linebls                           rJ   fix_w503zFixPEP8.fix_w503  sO   ";F<@K#I #IQ!<<>>!,	 !122BBX01 	 	 	FF	"2a58-=>> 	F&+# q (	 (	AQ!###a!+JA~~T[!1!1Z!?!?!A~HZ07799J/)!}33$)$*.'$RWWT[H9L-M%N%NOO!45   MM%bMM ' 'qQ4H,hk:::!((///!Q&Mq  r*++,C  Q4H,hk:::!Q&M A%%E#qt+++A(+8M8M$'F1IMELL)**$q.+??"(--2A2Jq3'7#8#8899:AACC#E #EJ$+oj&@ABBk/2r"" 	J+5+<+<N]N+-=MA-../,1 ,1DK((( 3B3((-- J 09/?/?A&(8+bdee:L0N 0NO,,, 09/?/?$&6BCC8H0J 0JO,,,s#   A AA
/D::EEc                 R   t          || j                  \  }}}d}d }t          dd          D ]}||z   }	 t          d                    | j        ||                             }	n# t
          t          j        f$ r Y Qw xY wd}
g }t          |	          D ]\  }}t          |d         |d                   rA|d         d         dk    r.|d         d         dk    r|d         d         |d         d         f}b|d         t          j
        k    rK|d         dv rA|d         d         dk    r.|d         d         dk    r|d         d         |d         d         f}|d         t          j        t          j        fv r|                    |           |
dz  }
|
dk    r|	d |d                  }n|	}g }|D ])}t          j        |d         k    r|r|d         \  }} n|}* |sd S ||d         |d                  }|rM|dk    rGd	                    |d |d                                                  ||d                    | j        |<   nmd
                    |d |d                                                  ||d         d                                          ||d         d                    | j        |<   | j        |dz            }d}t%          j        d|          }|r|                                d         }d                    |d |         |||d                    | j        |dz   <   d S )Nr   r      rB   r   r   andorr  r  r  z\s*r  )r  r   r   rX  r   rV   rP   r   r   r  NAMEr{   rz   r   r   rc   r   r7  r  rb   span)r   r  r  r  r9  r  operator_positionr   r  r\  r  r  r  r  r  r  comment_rowtarget_operatorr  next_line_indentms                        rJ   fix_w504zFixPEP8.fix_w504O  s   ";F<@K#I #IQ  q! 	 	A!A~H$RWWT[H9L-M%N%NOO!45   MM%bMM 	' 	'q&qtQqT22 'tAw!||!Q1-.qT!Wad1g,>)qTX]**qt}/D/DtAw!||!Q1-.qT!Wad1g,>)qTh.<<<!((///!Q&Mq  +-++,C  #qt+++14Q.KE  	F !21!56G6J!JK 	/[A--&,mm,)!,,-4466}~~&'( '(DK
## '/oo,)!,,-4466(+,,-4466(+,,-'/ '/DK
#
 K
Q/	HVY'' 	+ vvxx{&/&6&6'''(/&''('* '*JN###s   /A''B ?B c                     t          || j                  \  }}}d                    |d |dz            ||dz   d                    | j        |<   d S )Nz{}\{}r   )r  r   rc   )r   r  r  rM  r9  s        rJ   fix_w605zFixPEP8.fix_w605  s`    '@AE(N (N$VV"*//;FQJ;
!4#6 #6JrL   NN).__name__
__module____qualname____doc__r   r  r  r   r   rA  rC  rE  rI  r   r   r   r   r`  re  r   r   r   rp  rv  rx  r{  r  r  r   r   r  r  r  r   r  r  r  r  r  r  r  r   r  r  r  r
  r&  rL   rJ   r   r     s       % %R (,<& <& <& <&|A+ A+ A+F"$ "$ "$H
L 
L 
L	< 	< 	<8 8 88 8 88 8 8  $G G G(
( 
( 
(0 0 0  >( ( (0 0 06
0 
0 
0, , ,O O O
	
 	
 	
  &# # #  B( ( (0 0 0"! ! !F  .  >D D D
4 
4 
4.  .  . `	0 	0 	0F F F,$7 $7 $7L5 5 5@5 5 5>& & &	' 	' 	'< < <
- - -JJ JJ JJX8* 8* 8*t6 6 6 6 6rL   r   c                    d }d fd}d}d}d}t          t          |                     }|D ]\  }|st                                                                        }	|	[d}|	                    d	          }|	                                |	j                                                 }
|
d
d         |k    rd}|r#                                d
d         |k    rd}                                sˉ	                    d          r	                    d          r||k    r|c S 	                    d          r<||k    r |t          j        |fg|                    \  }}|r
||z   dz   c S |c S t          j                                      r|c S t          fd|D                       r |          r|c S |c S dS )zreturn import or from keyword position

    example:
      > 0: import sys
        1: import os
        2:
        3: def function():
    c                     | d         dv r
| dd          } | r| d         dv r
| dd          } | o| d         dk    p| d         dk    S )Nr   uUbBr   rR"'r&  r%  s    rJ   is_string_literalz<get_module_imports_on_top_of_file.<locals>.is_string_literal  s_    7f8D 	DGtOO8D:aC947c>:rL   c                     t          j        |           }|j        D ]*}t          |t           j                  r|j        dk    r dS +dS )N
__future__TF)astparsebody
isinstance
ImportFrommodule)r   nodesr"  s      rJ   is_future_importz;get_module_imports_on_top_of_file.<locals>.is_future_import  sM    	$ 	 	A!S^,, \1I1ItturL   c                     d}d}| D ]Z\  }}|                                                     d          D ](}||z   }	  |          |fc c S # t          $ r Y %w xY w|dz  }[d|fS )Nr   rB   Tr   F)r  
splitlinesrV   )r   rM  r   r  r  	line_partr   s         rJ   has_future_importz<get_module_imports_on_top_of_file.<locals>.has_future_import  s    " 	 	LAy&__..99$??  	i'++D116999999"   HaKFFf}s   A
AA)tryr'   elsefinallyF"""NTkindr  r;  r   r   r   c              3   B   K   | ]}                     |          V  d S Nr`   )r'  kwr   s     rJ   r-  z4get_module_imports_on_top_of_file.<locals>.<genexpr>  s/      DD$$DDDDDDrL   r   )iterr   DOCSTRING_START_REGEXrb   r7  r  r   endposr   r`   	itertoolschainr;   DUNDER_REGEXany)r   import_line_indexr  r$  allowed_try_keywordsin_docstringdocstring_kindsource_streamru  r  remainhitrM  r   r   s                @@rJ   r  r    s_   ; ; ;       @LN6**++M" ) )	T 	%++DKKMM::A}#!"aeeggqx/07799"##;.00#(L 	{{}}RSS!^33${{}} 	__S!! 	??9%% 	'''JJJ__W%% 	'''++#t}== KC  (V|a''''JJJ%++D11 	JJJDDDD/CDDDDD 	t$$ 	JJJJJJ1rL   c                 @    | d         dz
  }|| d         dz
  ||         fS )z2Return (line_index, column_offset, line_contents).r   r   r   r&  )r  r   r  s      rJ   r  r    s2    !#J8q :   rL       O   Fc           
         t          |           }| t          |          d         }	|	                                |	k    sJ |                                                     d          rJ t	          t          |	                    }
t          |
|	|||          }t          t          t          |          	                    | |g                    fd          }|dk    rDt          d                    dg|z   dgz             t          t          j        d	          
           |r,|d         }t          |          t          |          k    rdS |S dS )zBreak up long line and return result.

    Do this by generating multiple reformatted candidates and then
    ranking the candidates to heuristically select the best option.

    Nr;  )r   r   r  c                 *    t          |           S )N)r   )line_shortening_rank)xr   r   r!  s    rJ   <lambda>z%get_fixed_long_line.<locals>.<lambda>	  s#    *%	' ' ' rL   r   r   zP-------------------------------------------------------------------------------
rB   zutf-8r   r   )r>  r   r7  r`   r   rX  shorten_liner   r   unionr
  r   wrap_outputr  r  longest_line_length)r9  r  r  r   r!  r   r   r	  r   r   r   
candidatesbest_candidates      `` `      rJ   r  r    s    f%%FCKKLL!F==??f$$$$}}))#..... /&))**F!#% % %J s:$$fh%78899' ' ' ' ' '( ( (J !||$$bTJ%6"%=>>sz733	5 	5 	5 	5  #A ~..1DX1N1NNN4 rL   c                     t          |           dk    rdS t          d |                                 D                       S )zReturn length of longest line.r   c              3   4   K   | ]}t          |          V  d S r+  r   r'  r   s     rJ   r-  z&longest_line_length.<locals>.<genexpr>!  s(      77Ts4yy777777rL   )r   rs  r"  rh  s    rJ   rG  rG    s=    
4yyA~~q77T__%6%6777777rL   c                     t          |           }|t          t          |                                                     z   dz   S )z/Return single line based on logical line input.r   )r>  untokenize_without_newlinesrX  r7  )rd   r  s     rJ   r  r  $  sH    "<00K4++--..0 0 0267 7rL   c                     d}d}d}| D ]]}|d         }|d         \  }}|d         \  }}	||k    rd}||k    s|dk    r|                     d          s|dz  }|dk    r||z  }|}|	}^|                                S )	z#Return source code based on tokens.rB   r   r>   r   r   r   r   r4  )rx   r   )
r   r   last_rowlast_columnr  token_string	start_rowstart_columnend_row
end_columns
             rJ   rP  rP  ,  s    DHK ! !t$%aD!L !!*xKK''<4+?+?c"" ,@ CKD4L D ;;==rL   c                 t   g }g }d}d}t          d                    |                     D ]	}|d         t          j        t          j        t          j        t          j        t          j        fv rE|sU|d         t          j        t          j	        fv r5d}|
                    |d         d         dz
  |d         d         f           |r6|s4|
                    |d         d         dz
  |d         d         f           d}|d         t          j        k    r|d         dv r|dz  }|d         d	v r|dz  }||fS )
NTr   rB   r   r   r   Frw   }]))rX  r   rP   r   DEDENTINDENTrz   	ENDMARKERr{   SEMIr   r}   )source_linesr  r  last_newliner   r  s         rJ   r   r   H  sM   MKLFRWW\2233  Q4H$hoOX[&( ( (  	!A$8#3X]"CCCL!Q!QqT!W5666 	! 	!  !A$q'A+qtAw!7888 LQ48;tu}}!1!;''rL   c                 4   |d         dz
  }|d         dz
  }d}d}t          dt          |          d          D ]>}|sJ ||         }	|	d         |k    s|	d         |k    r|	d         |k    r|	}||         } n?|dS | |d         |d         dz            }
|||
fS )zdReturn the logical line corresponding to the result.

    Assumes input is already E702-clean.

    r   r   r   Nr   )r   r   )r_  r  r  r  r   collsler   rB  r  s              rJ   r  r  b  s     .1
C

Q
C	B	B1c-((!,,  NQ4#::!A$#++!A$**Bq!BE	ztBqE"Q%!)O,Hr8rL   c                 P    d|cxk    rt          |           k     rn n| |         S |S Nr   rL  )itemsr  r  s      rJ   r  r  y  s9    ECJJU|NrL   c                 J    t          |           }|                    |          S )zReindent all lines.)
Reindenterrun)r   indent_size
reindenters      rJ   reindentrm    s!    F##J>>+&&&rL   c                 n   t          |           }t          |          }t          |          t          |          k    rdS t          |          D ]d\  }}d                    ||                                                   d                    ||                                                   k    r dS edS )zZReturn True if code is similar.

    Ignore whitespace when comparing specific line.

    FrB   T)split_and_strip_non_empty_linesr   r   r   r6  )art   split_asplit_br  r  s         rJ   r  r    s     .a00G-a00G
7||s7||##u((  
7775>''))**bgggen6J6J6L6L.M.MMM55 N 4rL   c                 >    d |                                  D             S )z=Return lines split by newline.

    Ignore empty lines.

    c                 ^    g | ]*}|                                 |                                 +S r&  r  rM  s     rJ   r(  z3split_and_strip_non_empty_lines.<locals>.<listcomp>  -    GGGT$**,,GDJJLLGGGrL   )r"  )r   s    rJ   ro  ro    s#     HGT__%6%6GGGGrL   c                    d| vr| S t          | d          t          t          |                     z  }g }t          j        |           }t          |                                d          D ]q\  }}|                                                    d          r.||vr)t          j
        |          st          |          }|                                }t          |          dk    rt          d t          |          D                       }|d|                             d          dk    s4|d                                         s|d                                         sI|d         dvr?|                                                    d          sd	|                    d
          z   }|                    ||z              \|                    |           sd                    |          S )zFormat block comments.r;  Tinclude_docstringsr   r   c              3   ,   K   | ]\  }}|d k    |V  dS )r;  Nr&  )r'  r  rd  s      rJ   r-  zfix_e265.<locals>.<genexpr>  s7       ) )heQ Cxx "'xxx) )rL   Nz:!r  z# 	rB   )multiline_string_linesr   commented_out_code_linesrG   r   r   r\   r7  r`   r;   r   r>  r   nextr+  r  r   r   rx   r   r   )	r   r   ignored_line_numbersfixed_linesr   line_numberr   r  r   s	            rJ   fix_e265r    s   
&1! ! !#&'?'G'G#H#HI K
+f

C(BBB % %dKKMM$$S))	%333 && 4 +400K;;==D 4yy1}} ) ))D// ) ) ) * * $3$Z%%c**Q..$q'//2C2C. GOO-- /G4''..s33 (  $++f"5"55D{T12222t$$$$77;rL   rB   c                    | o|                      d          | k    }|r| dz   }n| }ddlm} 	 t          |||          }n*# |j        j        t          t          t          f$ r | cY S w xY w|r
||v r|| vr| S |r|                     d          S |S )zjReturn refactored code using lib2to3.

    Skip if ignore string is produced in the refactored code.

    r   r   r   )pgen2)fixer_namesrI   )	r   lib2to3r  refactor_with_2to3r  
ParseErrorrV   rW   UnicodeEncodeError)r   r  r  rI   not_found_end_of_file_newlineinput_sourcer  new_texts           rJ   refactorr    s     %+$Nv}}V/D/D/N!$ }%l2=/79 9 9 K"     	  X&"6"6M$ 'v&&&Os   A   $A'&A'c                 .   t                      }t                                          D ]l\  }}t          || |          rU|rAt	          d                    ||                                          t          j                   |t          |          z  }m|S )Nr   r  --->  Applying {} fix for {}r   )	r   CODE_TO_2TO3rg  
code_matchr
  rc   upperr  r  )r   r  wherer	  fixesrh  r  s          rJ   code_to_2to3r    s    EEE!''))  	cd6&999 	 '4;;E<@JJLLJ J:' ' ' ' SXXELrL   Tglobalc           	      `    |s| S |pg }|pg }t          | t          ||||          |          S )z*Fix various deprecated code (via lib2to3).)r   r  r  r	  rI   )r  r  )r   r   r   r  rI   r  r	  s          rJ   fix_2to3r    s^      \rF\rFF (.',)02 2 2 &' ' ' 'rL   c                 0    |s| S t          | dgd          S )z)Fix deprecated form of raising exception.raisewith_traceback)r  )r  )r   r   s     rJ   fix_w602r    s'     FWI.>????rL   c                    t          | t                    rJ t          j        t                    }| D ]}|                    t                    r|t          xx         dz  cc<   2|                    t                    r|t          xx         dz  cc<   b|                    t                    r|t          xx         dz  cc<   t          ||j
        d          pt          gd         S )zKReturn type of newline used in source.

    Input is a list of lines.

    r   T)r   reverser   )r  r   collectionsdefaultdictr5  rx   CRLFCRLFr   r   )r   counterr   s      rJ   r  r    s     &'*****%c**G  == 	DMMMQMMMM]]2 	BKKK1KKKK]]2 	BKKK1KKK7T:::BrdAFFrL   c                     d}	 t          |           D ]"}|d         t          j        k    r
|d         } n#n# t          t          j        f$ r Y nw xY w|S )zReturn indentation type.r=  r   r   )rX  tokenr\  rV   rP   r   )r   r   r  s      rJ   r   r   '  sx    K (( 	 	Atu|##d $ ,-   s   27 AAc                     |                                  r;t          |           t          |                                           z
  }| d|         S dS )zReturn leading whitespace.NrB   )r  r   r7  )r   non_whitespace_indexs     rJ   r>  r>  4  sJ    zz|| +"4yy3t{{}}+=+==)))**2rL   c                     d}t          j        | |d|z   d|z   |          }d}|D ])}||z  }|r |                    |          s||dz   |z   z  }*|S )z0Return text of unified diff between old and new.r   z	original/zfixed/)linetermrB   z\ No newline at end of file)difflibunified_diffrx   )r  newrI   rE   diffr   r   s          rJ   get_diff_textr  =  s    GSh8	  D D G G  	Gg.. 	GG<<wFFDKrL   c                     g d}d}dg}| d                                          }	 |                    |          S # t          $ r3 	 ||                    |          z   dz   cY S # t          $ r |cY cY S w xY ww xY w)z~Key for sorting PEP8 results.

    Global fixes should be done first. This is important for things like
    indentation.

    )e701e702e225e231e201e262i'  e501r   r   )r  r  
ValueError)pep8_resultprioritymiddle_indexlowest_priorityr   s        rJ   r  r  Q  s      H L 	O
 d

!
!
#
#C ~~c"""      	 /"7"7"<"<<q@@@@ 	  	  	 	  s-   : 
A7A"A7"A3.A72A33A7c           	   #      K   t          | |||||          D ]}|V  |r+t          D ]#}	t          | ||||	|          }
|

|
|k    r|
V  $|rt          | |||          D ]}
|
V  dS dS )zJSeparate line at OPERATOR.

    Multiple candidates will be yielded.

    )r   r   r  r   r   r  )r   r   r  r   key_token_stringsr   N)r   r   r  r!  )_shorten_lineSHORTEN_OPERATOR_GROUPS_shorten_line_at_tokens_shorten_line_at_tokens_new)r   r   r  r   r!  r   r   r  	candidater  	shorteneds              rJ   rD  rD  t  s       #&*0/:/:.81>@ @ @  	   !8 
	  
	 /''"3%' ' 'I $f)<)< 4' /	1 1 1 	 	I OOOO 	 	rL   c              #   V  K   t          |           D ]\  }}}}	|t          j        k    rt          |          st          |          s||dz   d                                                                                             d          sL|d|         }
||d         }||                                z   dz   |z   |
                                z   dz   V  |t          j        k    r|dk    r|t          j	        k    sJ |d|	         }
|}|

                                                    d          r0||	d                                                             d          rnU|

                                                    d          r||z  }n(d|
v r|dd|
                    d          z   z  z  }n||z  }|||	d                                         z   }|                                r'|                                                    d	          r|                                                    d
          r-|

                                                    d          rV|dv r|
dz   dz   |z   }n|
dz   |z   }t          |rt          |          n|          r||z   V  dS )zSeparate line at OPERATOR.

    The input is expected to be free of newlines except for inside multiline
    strings and at the end.

    Multiple candidates will be yielded.

    r   N)r   zpragma:zpylint:r   =r   rr  r4  r;  r   .z+-*/z \)token_offsetsrP   r   is_probably_part_of_multiliner  r  r`   r  r}   r\  r   rx   r7  r   rY  normalize_multiline)r   r   r  r   r   r  r   rT  start_offset
end_offsetr  r  second_indentrT  s                 rJ   r  r    s      &f--8* 8* 				 (***-m<< +-f55 + |a'(()//117799DD.0 0 + =L=)ELMM*F/$6!&/156 7 7 7 758##(;(; ----;J;'E'M'',, -:;;'..00;;C@@-((-- -,EJJsOO(;!<<,#fZ[[&9&@&@&B&BBFLLNN**3//  }}))#.. ||~~&&s++ v%%,v5v- )5/666/46 6 *!E))))q8* 8*rL   c                 2    | t           j        k    s|dv o|dvS )Nr  z()[]{},:.;@=%~)rP   r}   )r   r   s     rJ   r  r    s)    8;&?$-*? )((*rL   Token)r   rT  sposeposr   c                       e Zd ZdZ G d de          Z G d de          Z G d de          Zd Zd	 Z	d
 Z
d Zd Zd Zd ZddZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )ReformattedLineszThe reflowed lines of atoms.

    Each part of the line is represented as an "atom." They can be moved
    around when need be to get the optimal formatting.

    c                   4    e Zd ZdZd Zd Zed             ZdS )ReformattedLines._Indentz,Represent an indentation in the atom stream.c                     || _         d S r+  _indent_amtr   
indent_amts     rJ   r   z!ReformattedLines._Indent.__init__  s    )DrL   c                     d| j         z  S Nr4  r  r   s    rJ   emitzReformattedLines._Indent.emit  s    )))rL   c                     | j         S r+  r  r  s    rJ   sizezReformattedLines._Indent.size  s    ##rL   N)r  r  r  r  r   r  propertyr  r&  rL   rJ   _Indentr    sS        ::	* 	* 	*	* 	* 	* 
	$ 	$ 
	$ 	$ 	$rL   r  c                   .    e Zd ZdZd Zed             ZdS )ReformattedLines._Spacez%Represent a space in the atom stream.c                     dS r  r&  r  s    rJ   r  zReformattedLines._Space.emit  s    3rL   c                     dS Nr   r&  r  s    rJ   r  zReformattedLines._Space.size
      1rL   Nr  r  r  r  r  r  r  r&  rL   rJ   _Spacer    sD        33	 	 	 
	 	 
	 	 	rL   r  c                   .    e Zd ZdZd Zed             ZdS )ReformattedLines._LineBreakz*Represent a line break in the atom stream.c                     dS )Nr   r&  r  s    rJ   r  z ReformattedLines._LineBreak.emit  s    4rL   c                     dS rf  r&  r  s    rJ   r  z ReformattedLines._LineBreak.size  r  rL   Nr  r&  rL   rJ   
_LineBreakr    sD        88	 	 	 
	 	 
	 	 	rL   r  c                 L    || _         g | _        d| _        d | _        d | _        d S rf  )_max_line_length_lines_bracket_depth
_prev_item_prev_prev_item)r   r!  s     rJ   r   zReformattedLines.__init__  s.     /#rL   c                 *    |                                  S r+  )r  r  s    rJ   __repr__zReformattedLines.__repr__   s    yy{{rL   c                     t          |t                    r|                     ||           d S |                     |||           d S r+  )r  Atom	_add_item_add_container)r   objr  break_after_open_brackets       rJ   r  zReformattedLines.add&  sL    c4   	NN3
+++FC-EFFFFFrL   c                    d}t          | j                  dk    rbt          | j        d         | j                  r|dz  }t          | j                  dk    r%t          | j        d         | j                  r|dz  }|dk    r7| j                            |                                            |dz  }|dk    7| j                            |           d S )Nr   r   r>   r   )r   r  r  r  r   )r   item
num_spacess      rJ   add_commentzReformattedLines.add_comment-  s    
t{a$+b/4;77  a
4;!##dk"ot{;; $!OJ1nnKt{{}}---!OJ 1nn 	4     rL   c                 `    | j                             |                     |                     d S r+  )r  r   r  r  s     rJ   
add_indentzReformattedLines.add_indent;  s*    4<<
3344444rL   c                     | j                             |                                            |                     t	          |                     d S r+  )r  r   r  r  r   )r   r   s     rJ   add_line_breakzReformattedLines.add_line_break>  s@    4??,,---F$$$$$rL   c                     | j                             ||                                            | j                             |dz   |                     |                     d S r  )r  insertr  r  )r   r  r  s      rJ   add_line_break_atz"ReformattedLines.add_line_break_atB  sR    5$//"3"3444519dll:&>&>?????rL   Fc                    | j         r-t          | j         d         | j        | j        | j        f          rd S t          | j                  }| j        rt          | j                  nd}| j        j        s$| j        j	        s| j        j
        s| j        j        r|d         dvs|d         dk    r|s}|dk    r|d         dk    r|dk    r|d         d	k    r|d         d
v r
|d         dvsE|d         dv s;|r|dk    s3| j        rb|dvr`| j        j
        s| j        j        s| j        j	        r@|dv r:| j                             |                                            d S d S d S d S d S d S d S d S d S )Nr>   rB   r   z	([{.,:}])r  fromr  r}  rk   rZ  z.,}])z:,z+-)r   r   r   r   r   r   z**r  )r  r  r  r  r  r   r  r  
is_keyword	is_stringis_name	is_numberr   )r   	curr_textequal	prev_textprev_prev_texts        rJ   add_space_if_neededz$ReformattedLines.add_space_if_neededF  s   	)B$/4<!M O  O	 FDO,,	-1-AIGD()))r 	 o(!	. -1O,E!	. o%	!	. *.)B	!	.
 l+--|s""u" &&9R=C+?+?8## q\S   }%%)A,g*E*E mt##  $ #c)) $ * $&&&. '&0 ' &0 ' HHHKt{{}}-----/ '&+?+?## !  *) '& IH	 '&rL   c                     | j         S )z(Return the previous non-whitespace item.)r  r  s    rJ   previous_itemzReformattedLines.previous_itemt  s
    rL   c                 B    |                                  |z   | j        k    S r+  )current_sizer  )r   item_extents     rJ   fits_on_current_linez%ReformattedLines.fits_on_current_linex  s!      ""[0D4IIIrL   c                 z    d}t          | j                  D ]#}||j        z  }t          || j                  r n$|S )z3The size of the current line minus the indentation.r   )r~   r  r  r  r  )r   r  r  s      rJ   r  zReformattedLines.current_size{  sQ    T[)) 	 	DDID$00  rL   c                 ^    | j         o&t          | j         d         | j        | j        f          S )Nr>   )r  r  r  r  r  s    rJ   
line_emptyzReformattedLines.line_empty  s2     <4;r? OT\:< <	=rL   c                     d}| j         D ]B}t          || j                  r|                                }||                                z  }C|                                dz   S )NrB   r   )r  r  r  r   r  )r   r  r  s      rJ   r  zReformattedLines.emit  s`    K 	" 	"D$00 )diikk!FF}}%%rL   c                    | j         rl| j         j        r`|j        rY| j                            |                                            | j                            |                     |                     t          |          }| j        r8| j        r1|                     ||           |dv r| 	                    ||           n| j        r| 
                                s|                     t          |                    r|                     |           nY| j                            |                                            | j                            |                     |                     | j                            |           || j         c| _         | _        |dv r| xj        dz  c_        dS |dv r| xj        dz  c_        | j        dk    sJ dS dS )zAdd an item to the line.

        Reflow the line to get the best formatting after the item is
        inserted. The bracket depth indicates if the item is being
        inserted inside of a container or not.

        z.,)]}rw   r   rZ  r   N)r  r  r  r   r  r  r   r  &_prevent_default_initializer_splitting_split_after_delimiterr  r  r   _enforce_spacer  )r   r  r  	item_texts       rJ   r  zReformattedLines._add_item  s    ? 	9t8 	9T^ 	9Kt00111Kt||J77888DMM	; 	=4. 	=77jIIIG##++D*===[ 	=!2!2 	=((Y88 =##D)))) ""4??#4#4555""4<<
#;#;<<<4   04do--1$%1$&!++++  ++rL   c                    |dz   }t          | j                  dk    r|                                 s|                     |j        | j        z   dz             st          |          d         dk    r| j        j        rd}|dz   }n|st          | j                  dvr[| j                            | 	                                           | j                            | 
                    |                     d	}n|                                 dz   }d	}t          |t          t          f          r|}|                    | d
|z  |           d S )Nr   r  r   r   r   Tr   rw   Fr4  )r  )r   r  r  r  r  r  r  r  r   r  r  r  r  ListComprehensionIfExpressionreflow)r   	containerr  r  actual_indents        rJ   r  zReformattedLines._add_container  sn   "Q DO$$++!! ,))!44q8: : , y!!!$++0G++/( *Q(	1((55
 ""4??#4#4555""4<<
#;#;<<<+0( --//!3M',$i"3\!BCC 	'&M 	s]22J 	 	L 	L 	L 	L 	LrL   c                 T   t          |          dk    r|                                  dS | j        r| j        rt          | j                  dk    rdS |                                  | j                            | j                  }t          | j        |dz
           | j                  s|                     |j	        dz             rdS t          | j        |dz
           | j
                  r| j        |dz
  = |                     | j                            | j                  |           dS )a  Prevent splitting between a default initializer.

        When there is a default initializer, it's best to keep it all on
        the same line. It's nicer and more readable, even if it goes
        over the maximum allowable line length. This goes back along the
        current line to determine if we have a default initializer, and,
        if so, to remove extraneous whitespaces and add a line
        break/indent before it if needed.

        r  Nr   )r   _delete_whitespacer  r  r  r  r  r  r  r  r  r  )r   r  r  prev_prev_indexs       rJ   r"  z7ReformattedLines._prevent_default_initializer_splitting  s6    4==C ##%%%F 	t'; 	((C//F!!!+++D,@AA t{?Q#67FF	%%di!m44	 F dk/A"56DD 	1Oa/0t{001EFF)	+ 	+ 	+ 	+ 	+rL   c                    |                                   |                     |j                  rdS d}t          | j                  D ]Z}|rt          |t                    r|j        s n9d}t          || j                  r|}t          || j	        | j
        f          r dS [|sdS |                     | j                            |          |           dS )z&Split the line only after a delimiter.N)r-  r  r  r~   r  r  r  is_colonr  r  r  r  r  )r   r  r  
last_spacecurrent_items        rJ   r#  z'ReformattedLines._split_after_delimiter
	  s    !!!$$TY// 	F
$T[11 	 	L"d33" "*"
 !
,44 *)
,$,(GHH   	Ft{00<<jIIIIIrL   c                 d   t          | j        d         | j        | j        | j        f          rdS | j        sdS t          |          }t          | j                  }|dk    r|dk    s|dk    r|dk    s|dk    r4|dk    r0| j                            |                                            dS dS dS )zEnforce a space in certain situations.

        There are cases where we will want a space where normally we
        wouldn't put one. This just enforces the addition of a space.

        r>   Nr  r  r}  r   )r  r  r  r  r  r  r   r   )r   r  r%  r  s       rJ   r$  zReformattedLines._enforce_space%	  s     dk"o{DOT\BD D 	F 	FDMM	DO,,	
 #)v"5"5(""yC'7'7#)x"7"7Kt{{}}----- "7"7rL   c                     t          | j        d         | j        | j        | j        f          r7| j        d= t          | j        d         | j        | j        | j        f          5dS dS )z/Delete all whitespace from the end of the line.r>   N)r  r  r  r  r  r  s    rJ   r-  z#ReformattedLines._delete_whitespace?	  sy    R4;+/<+9 : : 	 B R4;+/<+9 : : 	  	  	  	  	 rL   NF)r  r  r  r  objectr  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r"  r#  r$  r-  r&  rL   rJ   r  r    s        $ $ $ $ $& $ $ $	 	 	 	 	 	 	 		 	 	 	 	V 	 	 	$ $ $  G G G! ! !5 5 5% % %@ @ @,. ,. ,. ,.\  J J J  = = =
& & &', ', ',R"L "L "LH%+ %+ %+NJ J J6. . .4         rL   r  c                       e Zd ZdZd Zd Zd Z	 	 	 ddZd Ze	d             Z
e	d	             Ze	d
             Ze	d             Ze	d             Ze	d             Ze	d             ZdS )r  z3The smallest unbreakable unit that can be reflowed.c                     || _         d S r+  )_atom)r   atoms     rJ   r   zAtom.__init__J	  s    


rL   c                     | j         j        S r+  r9  rT  r  s    rJ   r  zAtom.__repr__M	  s    z&&rL   c                     | j         S r+  )r  r  s    rJ   __len__zAtom.__len__P	  s
    yrL   Fc                 ^   | j         j        t          j        k    r|                    |            d S |r|n| j        }| j         j        dvr|dz  }|                                }|s|                    |          sl|r|                    | j        dz             sM|	                                s9| j
        s2|r|j        rt          |           dk    s|                    |           n"|                    t          |                      |                    | t!          |          |           d S )Nz,:([{}])r   r   )r9  r   rP   r   r  r  rT  r  r  r  r0  r  r   r  r  r  r   )	r   reflowed_linescontinued_indentextentr  is_list_comp_or_if_exprnext_is_dot
total_size	prev_items	            rJ   r)  zAtom.reflowS	  sb    : H$444&&t,,,F%4VV49
:"*44!OJ"0022	'	>33J??	> 	>  44TY]CC		>
 ))++	> 	> 	>  )0	> #%% ))*:;;;;..wt}}===4%5!6!63	5 	5 	5 	5 	5rL   c                 *    |                                  S r+  )r  r  s    rJ   r  z	Atom.emitw	  s    }}rL   c                 >    t          j        | j        j                  S r+  )keyword	iskeywordr9  rT  r  s    rJ   r  zAtom.is_keywordz	  s     !8999rL   c                 6    | j         j        t          j        k    S r+  )r9  r   rP   r   r  s    rJ   r  zAtom.is_string~	      z$77rL   c                 6    | j         j        t          j        k    S r+  )r9  r   rP   r  r  s    rJ   r  zAtom.is_name	  s    z$55rL   c                 6    | j         j        t          j        k    S r+  )r9  r   rP   NUMBERr  s    rJ   r  zAtom.is_number	  rL  rL   c                 "    | j         j        dk    S )Nr   r<  r  s    rJ   is_commazAtom.is_comma	      z&#--rL   c                 "    | j         j        dk    S )Nrk   r<  r  s    rJ   r0  zAtom.is_colon	  rR  rL   c                 4    t          | j        j                  S r+  )r   r9  rT  r  s    rJ   r  z	Atom.size	  s    4:*+++rL   N)FFF)r  r  r  r  r   r  r>  r)  r  r  r  r  r  r  rQ  r0  r  r&  rL   rJ   r  r  F	  s3       ==  ' ' '  
 "' %	"5 "5 "5 "5H   : : X: 8 8 X8 6 6 X6 8 8 X8 . . X. . . X. , , X, , ,rL   r  c                       e Zd ZdZd Zd Zd Zd Z	 ddZd Z	e
d	             Ze
d
             Ze
d             Ze
d             Ze
d             Ze
d             Ze
d             Ze
d             ZdS )	Containerz#Base class for all container types.c                     || _         d S r+  _items)r   rg  s     rJ   r   zContainer.__init__	  s    rL   c                 &   d}d}| j         D ]}|j        r|dz  }nn|j        r|dz  }nat          |          }|rK|sD|                    t          d                    s'|                    t          d                    s|dz  }||z  }|j        }|S )NrB   F, z: z
([{,.:}]) z	([{,.:}])r4  )rY  rQ  r0  r   rx   tupler`   r  )r   r  last_was_keywordr  item_strings        rJ   r  zContainer.__repr__	  s     K 	/ 	/D} &$ &$%dmm"%" !//%*=*=>>" &00{1C1CDD	" cMF+%#rL   c              #   &   K   | j         D ]}|V  d S r+  rX  )r   elements     rJ   __iter__zContainer.__iter__	  s,      { 	 	GMMMM	 	rL   c                     | j         |         S r+  rX  )r   r   s     rJ   __getitem__zContainer.__getitem__	  s    {3rL   Fc           
         d}t          | j                  D ]E\  }}t          | j        |dz             }t          |t                    r}t          | t
          t          f          }|                    |||                     |          ||ot          |          dk               |r|j
        r|                    |           d}nA|                    |t          |          |           t          |t
          t          f           }|r~|dk    rxt          |          | j        k    r`|rt          |          | j        k    rFt          | j                  dk    st          |t                    s|                    |           d}qt          | j        |dz             }	t          |          dvr|rt          |t                     st          |          d	k    r|	rt          |	t                    rt          |          d
k    rW|                                sC|                    |                     |dz             dz             s|                    |           Gd S )NFr   r  )rC  rD  r   r   r   )r  r   r  rk   not)r   rY  r  r  r  r'  r(  r)  _get_extentr   rQ  r  r  r   open_bracketr   rV  r  r  )
r   r@  rA  r  last_was_containerr  r  	next_itemrC  next_next_items
             rJ   r)  zContainer.reflow	  s   "&t{33 *	D *	DMUD eai88I$%% Jt&7%FGG (N,< ,,U334K)2 *C)0););s)B	  E E E
 & D$- D"112BCCC%*""""4-=)>)>#;= = =)3D;L;G;I *J *J &J" )D-2aZZ !222 3"))"4"48J"J"JT[!!Q&&jD.I.I&--.>???+0((!)$+uqy!A!ADMM)999 :&0I&F&F :I&&#--" .,6~t,L,L .(/	(:(:e(C(C&1133 )D&;;((33a79 9 )D
 #112BCCCU*	D *	DrL   c                    d}t          | j        |dz
            }|ot          |          dk    }|t          | j                  k     rt          | j        |          }|dz  }t	          |t
          t          f          rnt	          |t                    r|r|j        r|r|dz  }n
||j	        z  }|}n t          |          dvr|j        s|j
        sn9t          |          dk    rd}||j	        z  }|}|t          | j                  k     |S )zbThe extent of the full element.

        E.g., the length of a function call or keyword.

        r   r   r  )r  r  rk   re  T)r  rY  r   r   r  r'  r(  rV  r  r  r  )r   r  rB  rF  seen_dotr  s         rJ   rf  zContainer._get_extent	  s9    T[%!)44	:!3!3s!:c$+&&&&DK//DQJE$!2L ABB $	**  !2  ,!$)+ $I$--'===l >+/> >t}}##diFI1 c$+&&&&4 rL   c                     dS NFr&  r  s    rJ   r  zContainer.is_string
      urL   c                 D    t          |                                           S r+  )r   r  r  s    rJ   r  zContainer.size
  s    4==??###rL   c                     dS rn  r&  r  s    rJ   r  zContainer.is_keyword
  ro  rL   c                     dS rn  r&  r  s    rJ   r  zContainer.is_name
  ro  rL   c                     dS rn  r&  r  s    rJ   rQ  zContainer.is_comma 
  ro  rL   c                     dS rn  r&  r  s    rJ   r0  zContainer.is_colon$
  ro  rL   c                     d S r+  r&  r  s    rJ   rg  zContainer.open_bracket(
      trL   c                     d S r+  r&  r  s    rJ   r   zContainer.close_bracket,
  rv  rL   Nr5  )r  r  r  r  r   r  ra  rc  r)  rf  r  r  r  r  r  rQ  r0  rg  r   r&  rL   rJ   rV  rV  	  s\       --    .        ).-D -D -D -D^# # #J   X $ $ X$   X   X   X   X   X   X  rL   rV  c                   >    e Zd ZdZed             Zed             ZdS )Tuplez'A high-level representation of a tuple.c                     dS )Nr   r&  r  s    rJ   rg  zTuple.open_bracket5
      srL   c                     dS )Nrr  r&  r  s    rJ   r   zTuple.close_bracket9
  r{  rL   Nr  r  r  r  r  rg  r   r&  rL   rJ   ry  ry  1
  sN        11  X   X  rL   ry  c                   >    e Zd ZdZed             Zed             ZdS )Listz&A high-level representation of a list.c                     dS )Nr   r&  r  s    rJ   rg  zList.open_bracketB
  r{  rL   c                     dS )N]r&  r  s    rJ   r   zList.close_bracketF
  r{  rL   Nr}  r&  rL   rJ   r  r  >
  sN        00  X   X  rL   r  c                   >    e Zd ZdZed             Zed             ZdS )	DictOrSetz3A high-level representation of a dictionary or set.c                     dS )Nr   r&  r  s    rJ   rg  zDictOrSet.open_bracketO
  r{  rL   c                     dS )N}r&  r  s    rJ   r   zDictOrSet.close_bracketS
  r{  rL   Nr}  r&  rL   rJ   r  r  K
  sN        ==  X   X  rL   r  c                   (    e Zd ZdZed             ZdS )r'  z4A high-level representation of a list comprehension.c                 `    d}| j         D ]#}t          |t                    r n||j        z  }$|S rf  )rY  r  r(  r  )r   lengthr  s      rJ   r  zListComprehension.size\
  sB    K 	  	 D$-- diFFrL   N)r  r  r  r  r  r  r&  rL   rJ   r'  r'  X
  s3        >>  X  rL   r'  c                       e Zd ZdZdS )r(  z0A high-level representation of an if-expression.N)r  r  r  r  r&  rL   rJ   r(  r(  f
  s        ::::rL   r(  c                    t          t          | |                    g}|dz  }t          |           }||k     rt          | |          }|j        dv r|dk    rt	          |          |dz
  fS |dk    rt          |          |dz
  fS |                    t          |                     |j        dk    rt          |          |fS |j        dk    rt          |          |fS |j        dk    rt          |          |fS n|j        dv r)t          | |          \  }}|                    |           n|j        dk    r*t          | |d          \  }}|                    |           nW|j        dk    r*t          | |d          \  }}|                    |           n"|                    t          |                     |dz  }||k     d	S )
z9Parse a high-level container, such as a list, tuple, etc.r   z,)]}forrv   rr  r  r  rw   r  )r  r  r   rT  r'  r(  r   ry  r  r  _parse_container)r   r  	for_or_ifrg  
num_tokenstokr*  s          rJ   r  r  k
  s    %'(()E	QJEVJ
*

VE]#v%%
 E!!)%00%!)<<d""$U++UQY77 LLc### 3&&ee,,!S((UU++!S((!%((%00 ) &&!1&%!@!@YLL####&&!1&%!G!GYLL####%%!1&%!F!FYLL#### LLc###
] *

` <rL   c                 v   d}g }t          |           }||k     rt          | |          }|j        t          j        k    sJ |j        t
          j        k    rnc|j        dv r-t          | |          \  }}|sdS |	                    |           n"|	                    t          |                     |dz  }||k     |S )zoParse the tokens.

    This converts the tokens into a form where we can manipulate them
    more easily.

    r   rw   Nr   )r   r  r   r  r\  rP   r{   rT  r  r   r  )r   r  parsed_tokensr  r  r*  s         rJ   _parse_tokensr  
  s     EMVJ
*

VE]#~---->X---u$$!1&%!@!@Y t  ++++  c+++
! *

$ rL   c                    t          | d                   dk    r|dt          z  z   }n|dt          z  z   }| }t          |          }|                    t	          |                    d                               |srt          | d          }t          | d          }|rP|rNt          |          d         dk    r5t	          |          t	          |          z   dz   t	          |          k    rdS | D ]t}	|                    t          |	          d	
           |}
|r1t          |	t                    rd}d|
                                dz   z  }|	                    |||           |
}u|                                S )z'Reflow the lines so that it looks nice.r   defz  r4  r   r   r   NT)r  F)r   ry   r  r  r   r7  r  r  r  rV  r  r)  r  )r  r  r!  start_on_prefix_linerA  r  linesfirst_tokensecond_tokenr  save_continued_indents              rJ   _reflow_linesr  
  s    }Q  E))&3F)FF&/B)BB#77_--E	S++F3344555  }a00q11 	(	L!!!$++s;///!3s;K7L7LLL4 	1 	1!!'$--t!<<< 0 	@JtY$?$? 	@#( "e&8&8&:&:Q&>?E+-EFFF0::<<rL   c              #   b  K   ||z   V  t          |           }|rt          |||d          }|r2t          t          |                                                    r|V  t          |||d          }|r6t          t          |                                                    r
|V  dS dS dS dS )zShorten the line taking its length into account.

    The input is expected to be free of newlines except for inside
    multiline strings and at the end.

    T)r  FN)r  r  rY  r  r7  )r   r   r  r!  r  rT  s         rJ   r  r  
  s       
!&))M  m[/379 9 9 	\"5ellnn"E"EFF 	KKKm[/38: : : 	\"5ellnn"E"EFF 	KKKKK 	 	 	 	rL   c                 r   g }t          t          |                     D ]\  }}|\  }	}
}}|	t          j        k    sJ |
|v rdddd                    |
          }|rCt          | |dz   ddg          d         |k    s!t          | |dz   ddg          d         |k    r|dk    r|
d	k    r| |dz
           d         d
v r|t          |          dz
  k     r|                    |           t          | |dz
            }|	t          j	        k    r-|r+|d         t          j	        k    r|                    |           d}d}t          ||          D ]7}|r+|d|z   |z   z  }dD ]}|                    |          r||z  }/|}|rJ |}8|J t          |dk    rt          |          n|          r||z   S dS )zSeparate line by breaking at tokens in key_token_strings.

    The input is expected to be free of newlines except for inside
    multiline strings and at the end.

    rr  r  r  r   r   r   r   Nr  r   r   z,(%[r   r   rw   )r   r  r  r\  r   r  r   r   rP   r   split_at_offsetsrx   rY  r  )r   r   r  r   r  r   offsetsr  _tr   rT  r  r  unwanted_next_tokenprevious_tokencurrent_indentrT  r   symbols                      rJ   r  r    s    G v!6!677 ,- ,- 				U\)))),,, # # #l++   # 	V"QY&*D\3 3 33469LM M V"QY&*D\3 3 33469LM M  		lc11uqy!!$.. CKK!O++z*** &feai88Nho-- .#1!#4#G#G|,,,NE 11 ) ) 
	)TN*T11E 2 2==(( 2"k1N2
 E%%%%(NN!A~~ (...+02 2 #U""4rL   c              #      K   d}d}d}| D ]X}|d         }|d         }|d         \  }}|d         \  }	}
||z  }||k    r||z  }|}|t          |          z  }||||fV  |	}|
}YdS )zYield tokens and offsets.r   r   r   r   NrL  )r   r  previous_end_rowprevious_end_columnr  r   rT  rU  rV  rW  rX  r  s               rJ   r  r  \  s      J ) )qT
t$%aD!L !!* 	l"
y((--J " 	c,'''
 	 	 	
 #(/) )rL   c                 X   |                      d          r,|                                                     d          r| dz   S |                      d          rd| z   S |                      d          r| dz   S |                      d          r| dz   S |                      d	          r| dz   S | S )
zrNormalize multiline-related code that will cause syntax error.

    This is for purposes of checking syntax.

    r_   rk   z passzreturn z	def _(): @zdef _(): passzclass )zif zelif for zwhile )r`   r   rx   r%  s    rJ   r  r  {  s     v 	4;;==#9#9##>#> 	g~		#	# T!!			 o%%		"	" g~	;	<	< g~KrL   c                     | d|                              d          }| |d                             d          }|                    d          r| S ||z   |z   S )z3Replace whitespace at offset and return fixed line.Nrb  r;  )r   r7  r`   )r   rM  rP  r  r  s        rJ   rR  rR    se     =,,DM  --E +%%rL   c                      G fddt           j                  t          j        d|d| }|                                 |j                                        S )z,Execute pycodestyle via python method calls.c                   8     e Zd ZdZ fdZ fdZd Z xZS )"_execute_pep8.<locals>.QuietReportz'Version of checker that does not print.c                 \    t          |                               |           g | _        d S r+  )superr    _QuietReport__full_error_results)r   r   QuietReport	__class__s     rJ   r   z+_execute_pep8.<locals>.QuietReport.__init__  s/    +t$$--g666(*D%%%rL   c                     t          |                               ||||          }|r$| j                            |||dz   |d           dS dS )zCollect errors.r   )r   r   r   r   N)r  r   r  r   )r   r  rM  r   checkrh  r  r  s         rJ   r   z(_execute_pep8.<locals>.QuietReport.error  s    d++11+2826279 9D  $)00(%z!# #$ $ $ $ $$ $rL   c                     | j         S )zReturn error results in detail.

            Results are in the form of a list of dictionaries. Each
            dictionary contains 'id', 'line', 'column', and 'info'.

            )r  r  s    rJ   full_error_resultsz5_execute_pep8.<locals>.QuietReport.full_error_results  s     ,,rL   )r  r  r  r  r   r   r  __classcell__)r  r  s   @rJ   r  r    sq        55	+ 	+ 	+ 	+ 	+ 	+	$ 	$ 	$ 	$ 	$ 	$	- 	- 	- 	- 	- 	- 	-rL   r  rB   )r  reporterrB   )r;   
BaseReportChecker	check_allreportr  )r2  r   checkerr  s      @rJ   r.  r.    s    - - - - - - -k, - - -< ! 2F[ 2 2$02 2G>,,...rL   c                     |r8|                      d                              t          t          z             dz   S |                      d          S )Nz 	r   )r7  r   r  r  )r   with_rstrips     rJ   _remove_leading_and_normalizer    sE     ;{{7##**2733d::;;wrL   c                   (    e Zd ZdZd ZefdZd ZdS )ri  zReindents badly-indented code to uniformly use four-space indentation.

    Released to the public domain, by Tim Peters, 03 October 2000.

    c                    t          j        |          }|                                }t          |          | _        g | _        t          |d          D ]\  }}|| j        v r| j                            |           )|t          |          k    }| j                            t          |          
                                t          ||          z              | j                            dd            d| _        || _        d S )Nr   rz  r   )rG   r   r\   r|  string_content_line_numbersr  r   r   r   r>  
expandtabsr  r
  r  
input_text)r   r  r   r_  r  r   r  s          rJ   r   zReindenter.__init__  s   k*%%}}+A*+M+M(
 
!*<q!A!A!A 
	 
	Kd>>>
!!$'''' *S->->>
!!$T**55771$DDE   
 	
!T"""
$rL   c                    |dk     r| j         S 	 t          t          j        | j                            }n## t
          t          j        f$ r
 | j         cY S w xY w| j        }|                    t          |          df           i }g }|d         d         }|
                    |d|                    t          t          |          dz
            D ]}||         \  }}||dz            d         }	t          ||                   }
||z  }|dk     r|
r|                    |
d          }|dk     rWt          |dz   t          |          dz
            D ]3}||         \  }}|dk    r |
t          ||                   k    r||z  } n4|dk     r[t          |dz
  dd          D ]F}||         \  }}|dk    r3|
t          ||dz
                     z   t          ||                   z
  } nG|dk     r|
}nd}|dk    sJ |||
<   ||
z
  }|dk    s|
dk    r|
                    |||	                    ]t          |||	         |          D ]\  }}|| j        v r|                    |           $|dk    r8|dk    r|                    |           F|                    d|z  |z              bt!          t          |          |           }|                    ||d                    d                    |          S )	zcFix indentation and return modified line numbers.

        Line numbers are indexed at 1.

        r   r   r>   rz  r   r4  NrB   )r  _reindent_statsrP   rX  getlinerV   r   r  r   r   extendr   _leading_space_countr   r   r  rc  r   )r   rk  statsr  	have2wantafterr   thisstmt	thislevelnextstmthavewantjjlinejlevelr  r  r   removes                      rJ   rj  zReindenter.run  s    ???"	##H$<T\$J$JKKEEX01 	# 	# 	#?"""	# 
c%jj!_%%%	 !HQKU1Q3Z   s5zzA~&& 5	4 5	4A"'(HiQU|AH'h88D{*Daxx  %==r22Daxx!&q1uc%jj1n!=!= & &A,1!HME6%{{#'+?e+M+M#M#M+1K+?D %  +
 axx "'q1ub"!5!5 & &A,1!HME6%{{(,/C(-eai(80: 0: ):(<U5\(J(J)K !&	  +
 axx#D19999"IdO$;DqyyDAIIU8H#456666)25(9J3K9A*C *C *C 4 4%K"d&FFFT****4<<!LL....!LLtd):;;;;!$%9$%?%?$!G!GT&'']33334 wwu~~s   &6 AAc                     | j         t          | j                  k    rd}n"| j        | j                  }| xj         dz  c_         |S )zLine-getter for tokenize.rB   r   )r  r   r  )r   r   s     rJ   r  zReindenter.getline;  s@    :TZ((DD:dj)DJJ!OJJrL   N)r  r  r  r  r   ry   rj  r  r&  rL   rJ   ri  ri    sZ         % % %4 2 P P P Pd    rL   ri  c                    d}d}g }| D ]}|d         }|d         d         }|d         }|t           j        k    rd}3|t           j        k    rd}|dz  }K|t           j        k    rd}|dz  }c|t           j        k    r|r|                    |df           |t           j        k    r|rd}|r|                    ||f           |S )zReturn list of (lineno, indentlevel) pairs.

    One for each stmt and comment line. indentlevel is -1 for comment
    lines, as a signal that tokenize doesn't know what to do about them;
    indeed, they're our headache!

    r   r   r   r   r>   )rP   r{   r\  r[  r   r   rz   )r   	find_stmtlevelr  r  r   r,  r   s           rJ   r  r  E  s    IEE "- "-qT
!Qt))) II8?**IQJEE8?**IQJEE8+++ *eR[))) 8;&& 	- I -eU^,,,LrL   c                     d}|t          |           k     r0| |         dk    r$|dz  }|t          |           k     r| |         dk    $|S )z(Return number of leading spaces in line.r   r4  r   rL  )r   r   s     rJ   r  r  x  sM    	A
c$ii--DGsNN	Q c$ii--DGsNNHrL   c                     ddl m} d |D             } |||          }ddlm} 	 t	          |                    | |                    S # |j        $ r | cY S w xY w)zQUse lib2to3 to refactor the source.

    Return the refactored source code.

    r   )RefactoringToolc                     g | ]}d |z   S )zlib2to3.fixes.fix_r&  r'  names     rJ   r(  z&refactor_with_2to3.<locals>.<listcomp>  s    BBBd"T)BBBrL   )r  explicitrO   )r  )lib2to3.refactorr  rR   rP   r   refactor_stringr   )source_textr  rI   r  fixerstoolrY   s          rJ   r  r    s     100000BBkBBBF?v???D::::::t++Kh+GGHHH&   s   #A AAc                 f    	 t          | ddd          S # t          t          t          f$ r Y dS w xY w)zReturn True if syntax is okay.z<string>execT)dont_inheritF)compilerV   	TypeErrorr  rN  s    rJ   rY  rY    sG    tZdCCCCJ/   uus    00c                 L   t          t          j        |                     }|sg S |d                                         }ddit	          t          j        d          d          D ]&\  }}|                                }||k    r n||<   'fdfd|D             S )zA wrapper around 're.finditer' to find line numbers.

    Returns a list of line numbers where pattern was found in contents.
    r>   r   z\nr   c                 f    |                     dd|                                           }|         S )zuGet the line number of string in a files contents.

        Failing to find the newline is OK, -1 maps to 0

        r   r   )rfindr   )rb   r   newline_offsetnewline_offsetss      rJ   get_line_numz,find_with_line_numbers.<locals>.get_line_num  s-     "a??~..rL   c                 .    g | ]} |          d z   S )r   r&  )r'  rb   r   r  s     rJ   r(  z*find_with_line_numbers.<locals>.<listcomp>  s*    CCC%LL))A-CCCrL   )r   r  finditerr   r   )	r~  r   matchesr   line_numr  rM  r  r  s	    `     @@rJ   find_with_line_numbersr    s    
 2;w1122G 	
"+



C 	AO !UH!=!=qAA + +!C<<E"*/ / / / / DCCCC7CCCCrL   c                    t          t          |           }t          t          |           }t          t	          j        d|                     dz   }i }|D ]}d||<   |D ]}d||<   g }d}d}t          |                                          D ]3\  }	}
|
du r	|du r|	}d}|
du r|du r|                    ||	f           d}4|du r|                    ||f           |S )zReturns a list of tuples representing the disabled ranges.

    If disabled and no re-enable will disable for rest of file.

    r   r   TFN)	r  ENABLE_REGEXDISABLE_REGEXr   r  findallr   rg  r   )r   enable_line_numsdisable_line_numstotal_linesenable_commandsnumdisabled_rangescurrently_enableddisabled_startr   commanded_enableds              rJ   get_disabled_rangesr    s<    .lFCC.}fEEbjv..//!3KO $ $#  % %$ON#)/*?*?*A*A#B#B % %%%*;t*C*C!N %$&&+<+E+E""ND#9::: $E!!<===rL   c                 ^    | d         }|D ]!}|d         |cxk    r|d         k    rn  dS "dS )z;Filter out reports based on tuple of disabled ranges.

    r   r   r   FTr&  )r  r  r   disabled_ranges       rJ   filter_disabled_resultsr    sY     &>D)  !9999q(99999955 :4rL   c              #     	K   t          | d          }t          | d          }t          |           }t          |           		r	fd|D             }t          d |D                       }|D ]}|d                                         }|d         |v r|                    d          r=|d         |v r|d	v rL|s#|d         d
z   |v r|                    d          rq|dk    r|                    d          r|d
k    r|                    d          r|dk    r|                    d          r|d         |v r|                    d          r|r|                    d          r|V  dS )z|Filter out spurious reports from pycodestyle.

    If aggressive is True, we allow possibly unsafe fixes (E711, E712).

    Frx  Tc                 4    g | ]}t          |          |S r&  )r  )r'  r  r  s     rJ   r(  z"filter_results.<locals>.<listcomp>  s?     
 
 
,C- -

 
 
rL   c              3   R   K   | ]"}|d                                           dk    V  #dS )r   e901N)r  r'  r  s     rJ   r-  z!filter_results.<locals>.<genexpr>  s7      HHf6$<%%''61HHHHHHrL   r   r   )e1r  w191)r  r   )w29w39r   )e711e72w6)e712e713e714r   e704)e26r  )r  e7N)r|  r}  r  r4  r  r`   )
r   r  r   !non_docstring_string_line_numbersall_string_line_numberscommented_out_code_line_numbershas_e901r=   issue_idr  s
            @rJ   r0  r0    s      )?5)* )* )*%44) ) ) '?v&F&F# *&11O 

 
 
 
!(
 
 
 HHHHHHHH * *T7==??V9999""#9:: V9///8##  	qy1}1HHH "">22 ??""#899 ??""#;<< ??""F,, V9777""?33 
  	""<00 U* *rL   c           	      n   t                      }d}	 t          |           D ]v}|d         }|d         d         }|d         d         }|t          j        k    r>||k    r8|s|t          j        k    r&|t          t          d|z   d|z                       z  }|}wn# t          t          j        f$ r Y nw xY w|S )zReturn line numbers that are within multiline strings.

    The line numbers are indexed at 1.

    Docstrings are ignored.

    rB   r   r   r   r   )r   rX  rP   r   r\  r   rV   r   )r   ry  line_numbersprevious_token_typer  r   rU  rW  s           rJ   r|  r|  .  s     55L (( 	- 	-A1J!QId1gGX_,,g1E1E&K'8?:: !Ca)mQ[(I(I$J$JJL",	- ,-    s   BB B21B2c                 X   g }	 t          |           D ]}|d         }|d         }|d         d         }|d         }|                                                    d          sP|t          j        k    r|                    d                                          }t          j                    5  t          j        dt                     d|v r(d|vr$t          |          r|                    |           d	d	d	           n# 1 swxY w Y   n# t          t          j        f$ r Y nw xY w|S )
zReturn line numbers of comments that are likely code.

    Commented-out code is bad practice, but modifying it just adds even
    more clutter.

    r   r   r   r   r;  r  )categoryr4  N)rX  r7  r`   rP   r   r  warningscatch_warningsfilterwarningsSyntaxWarningrY  r   rV   r   )r   r$  r  r   rT  rU  r   stripped_lines           rJ   r}  r}  N  s    L (( 	7 	7A1JQ4L!QIQ4D ;;==++C00 X--- , 3 3C 8 8 > > @ @,.. 7 7
 +H}MMMM},,=00$]33 1 %++I6667 7 7 7 7 7 7 7 7 7 7 7 7 7 7	70 ,-    s7   B)D -AD5D D	D D		D D'&D'c                 D   t          |           |k    sJ |                                 } t          |           dz   }t          |t          |          dz             }d}t          |           t          |                     | d                             z
  |k    r'| d                                         s| d|         dz   S |rZt          j        d|           rEt          j        | 	                    d          |||d	d	
          }d
                    |          dz   S | dz   S )zReturn trimmed or split long comment line.

    If there are no comments immediately following it, do a text wrap.
    Doing this wrapping on all comments in general would lead to jagged
    comment text.

    r  H   r  r>   Nr   z\s*#+\s*\w+rg  F)initial_indentsubsequent_indentwidthbreak_long_wordsbreak_on_hyphens)r   r   r>  rc  r  r  rb   textwrapwrapr7  r   )r   r!  r  r  MIN_CHARACTER_REPEATsplit_liness         rJ   r  r  u  s6    t99&&&&;;==D #4((4/K/k**R/1 1O D		CDH--...2FFFH 	G $_$%,,	 -"(>488 -mDKK$7$73>6A*95:5:< < < yy%%,,$;rL   c                     fd| D             }|rC| d         | d                              d          k    r|d                              d          |d<   |S )zcReturn fixed line endings.

    All lines will be modified to use the most common line ending.
    c                 @    g | ]}|                     d           z   S )
r   )r'  r   rE   s     rJ   r(  z*normalize_line_endings.<locals>.<listcomp>  s*    <<<dDKK')<<<rL   r>   r:  r;  )r  rE   r   s    ` rJ   normalize_line_endingsr<    sd    
 =<<<e<<<D +b	U2Y--f55558??6**RKrL   c                 V    |                     |           p|                      |          S r+  r,  )rp  rt   s     rJ   mutual_startswithr>    s!    <<??-all1oo-rL   c                    |r]t          |t                    rJ d |D             D ]9}t          |                                 |                                          r dS :|r_t          |t                    rJ d |D             D ]9}t          |                                 |                                          r dS :dS dS )Nc                 6    g | ]}|                                 S r&  ru  r'  rd  s     rJ   r(  zcode_match.<locals>.<listcomp>  s     7771QWWYY777rL   Fc                 6    g | ]}|                                 S r&  ru  rA  s     rJ   r(  zcode_match.<locals>.<listcomp>  s     888Aaggii888rL   T)r  r   r>  r  )rh  r   r  ignored_codeselected_codes        rJ   r  r    s     fg.....77777 	 	L |/A/A/C/CDD uu  fg.....88888 	 	M }/B/B/D/DEE ttu4rL   c                     t          ||          }t          | t                    s#|                     |pt	                                } t          j        |           }t          |                                |          S )zgReturn fixed source code.

    "encoding" will be used to decode "source" if it is a byte string.

    )r   )	_get_optionsr  r   decodeget_encodingrG   r   	fix_linesr\   )r   r   rD   apply_configr   s        rJ   fix_coderK    si     7L11Gfg&& ;x9<>>::
+f

CS]]__g6666rL   c                 *   | st          dg|          S t          | t                    rt          dg|          }|                                 D ]\  }}t	          ||          s"t          d                    |                    t          t          ||                    }t          |t          t          f          s>t          |t          t          f          r"t          d                    |                    t          |||           n| }|S )zReturn parsed options.rB   rJ  zNo such option '{}'z"Option '{}' should not be a string)
parse_argsr  dictrg  r  r  rc   typer  strr   setattr)raw_optionsrJ  r   r  valueexpected_types         rJ   rF  rF    s'    ;2$\::::+t$$ bT===&,,.. 
	* 
	*KD%7D)) E !6!=!=d!C!CDDD !$!7!788Mmc7^<< Kec7^44 K$<CCDIIK K KGT5))))
	* NrL   c                 b   t          |           }d                    t          | d                    }t                      }|j        r|}nr|j        |j        |j        |j        d}t          j
        |          }|                                }	t          ||	          }
d |
D             }t          ||||          }d}t                      }t          |          |vr|j        dk    r||j        k    rns|dz  }|                    t          |                     t#          j        |          }t%          ||||          }|                                }t          |          |vt          j
        |          }d                    t          |                                |                    S )	zReturn fixed source code.rB   r   r  c                 <    h | ]}|d          t           v |d          S )r   )"SELECTED_GLOBAL_FIXED_METHOD_CODESr  s     rJ   	<setcomp>zfix_lines.<locals>.<setcomp>  s8     H H H&4L$FFF FFFrL   )rI   codesr   r   )r   r   )r  r   r<  r   r/  r  r   r!  r   rG   r   r\   r.  apply_global_fixeshashpep8_passesr  copyr   r  )r_  r   rI   original_newline
tmp_sourceprevious_hashesr  r2  r   r   r  rZ  passesr   r  s                  rJ   rI  rI    s    $L11/dCCDDJ eeO 7! nn&6#0	
 
 k*%%==??h77H HG H H H ***13;057 7 7
 F UU
|

O
3
3!##1D(D(D!D..///Y|,,
#9	; ; ; wwyy |

O
3
3" +l
#
#C77)#--//;KLLMMMrL   c                    |st          | g|          }t          |           }|}|j        s	|j        s|rt	          |           }|rt          t          ||                    }t          |||           }|j        rt          j	        |          }|
                                }t          |||           }|r*|                    |           |                                 n |j        dk    r|                    |          }|S |j        rd                    |                                          }	|                                }
|r!|d                             d          d         nd}|                    d          d         }|	|
k    s||k    rAt'          | d|          5 }|                    |           d d d            n# 1 swxY w Y   |S d S |r)|                    |           |                                 |S )	NrM  rQ   r  r   rB   r>   r   w)rN  r]   in_placer  rF   LineEndingWrapperrF  rI  rG   r   r\   r  writeflushjobsencoder   r"  r6  rK   )rI   r   outputrJ  original_sourcer  rD   r  r  r  rT  original_source_last_linefixed_source_last_linefps                 rJ   fix_filerp    sY    DhZlCCC)(33O"L -7< -6 -"8,, K";v#I#I#IJJ\7XFFFL| k,''mmoo_c8<< 	)LLLLNNNN\A;;x((D		 77?++6688''))3BJOB%%d++B// 	" ".!3!3D!9!9"!=u%)???#HcHEEE '&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' 't 	LL&&&LLNNNs   %GGGc               #      K   t          t                                                                D ]L} t          j        |           r6t          |           }|dd         dgk    r5t          |           }|r|| fV  MdS )z'Yield multiple (code, function) tuples.Nr   r   )r   globalsvaluesinspect
isfunctionr  extract_code_from_function)function	argumentsrh  s      rJ   global_fixesry  D  s      ))++,, ' 'h'' 	''11I!}
**-h77D 'X&&&&' 'rL   c                     t           j        j        dk    rAt          j        |           r| j        } t          t          j        |           j                  S t          j	        |           d         S )Nr   r   )
r  version_infomajorrt  ismethod__func__r   	signature
parameters
getargspec)rw  s    rJ   r  r  Q  sb    
"" H%% 	)(HG%h//:;;;!(++A..rL   c           	      >   |g }t          fddD                       rt          | j                  } t                      D ]\  }}|                                t
          v r|                                |vr7t          |j        j                  rZj	        rAt          d                    ||                                          t          j                    || j                  } t          | j        j        j        ||j	        	          } | S )
zRun global fixes on source code.

    These are fixes that only need be done once (unlike those in
    FixPEP8, which are dependent on pycodestyle).

    Nc              3   P   K   | ] }t          |j        j                   V  !dS )r  N)r  r   r  )r'  rh  r   s     rJ   r-  z%apply_global_fixes.<locals>.<genexpr>i  sJ       ) ) d7>'.III ) ) ) ) ) )rL   )E101E111)rk  r  r  r   )r   )r   r   r  rI   r  r	  )r4  rm  rk  ry  r  rX  r  r   r  r	  r
  rc   r  r  r   r  )r   r   r  rI   rZ  rh  rw  s    `     rJ   r[  r[  _  se    }
 ) ) ) )') ) ) ) ) ;&&-&9; ; ; )NN 
= 
=x::<<===JJLL--d7>'.III 	= '4;;E<@JJLLJ J:' ' ' ' Xf)0);= = =F f!(!3$^$^'!%o/ / /F MrL   c                     | j                             d          sdS t          j        dd| j                   }|sdS 	 t	          |dd                    n# t
          $ r Y dS w xY w|S )z Return code handled by function.r   Nz^fix_rB   r   )r  r`   r  r  r5  r  )rw  rh  s     rJ   rv  rv    s    ''// t6'2x011D tDH   tt Ks   A 
A#"A#c                  l    d                     t          j                  g} d                    |           S )Nzpycodestyle: {}r[  )rc   r;   __version__r   )packagess    rJ   _get_package_versionr    s-    !(()@AABH99XrL   c            	      x   t          j        t          t                    d          } |                     ddd                    t          t                                           |                     ddd	d
d           |                     dddd           |                     dddd           |                     ddt          d                    t                               |                     ddd           |                     dddd           |                     ddt          d d!d"#           |                     d$d%d d&t          d'(           |                     d)d*d	d
d+           |                     d,dd-           |                     d.d/d01           |                     d2dd3           |                     d4d5d6d7                    t                               |                     d8d5d6d9           |                     d:d d;t          d<(           |                     d=d>d?d@t          dAdBC           |                     dDt          t          t           j        E           |                     dFddG           |                     dHddI           |                     dJdKdLM           | S )NzReturn command-line parser.autopep8)descriptionprogz	--versionversionz%(prog)s {} ({}))actionr  z-vz	--verboser+  r   zCprint verbose messages; multiple -v result in more verbose messages)r  r  helpz-dz--diff
store_truez#print the diff for the fixed source)r  r  z-iz
--in-placezmake changes to files in placez--global-configrI   zapath to a global pep8 config file; if this file does not exist then this is ignored (default: {}))metavarr  r  z--ignore-local-configzdon't look for and apply local config files; if not passed, defaults are updated with any config files in the project's root directoryz-rz--recursivezHrun recursively over directories; must be used with --in-place or --diffz-jz--jobsr"  r   z@number of parallel jobs; match CPU count if value is less than 1)rP  r  r  r  z-pz--pep8-passesr>   z<maximum number of additional pep8 passes (default: infinite))r  r  rP  r  z-az--aggressivezLenable non-whitespace changes; multiple -a result in more aggressive changesz--experimentalzenable experimental fixesz	--excludeglobszCexclude file/directory names that match these comma-separated globs)r  r  z--list-fixesz3list codes for fixes; used by --ignore and --selectz--ignorer]  rB   z.do not fix these errors/warnings (default: {})z--selectz*fix only these errors/warnings (e.g. E4,W)z--max-line-lengthr>  z6set maximum allowed line length (default: %(default)s)z--line-rangez--ranger   Nr   zlonly fix errors found within this inclusive range of line numbers (e.g. 1 99); line numbers are indexed at 1)r  r  rP  nargsr  z--indent-size)r  rP  r  z--hang-closingz)hang-closing option passed to pycodestylez--exit-codezchange to behavior of exit code. default behavior of return value, 0 is no differences, 1 is error exit. return 2 when add this option. 2 is exists differences.filesr   z&files to format or '-' for standard in)r  r  )argparseArgumentParserdocstring_summaryr  add_argumentrc   r  r  DEFAULT_CONFIGr5  DEFAULT_IGNOREry   SUPPRESS)parsers    rJ   create_parserr    s   $1B71K1K*46 6 6F
I 2 9 9')=)?)?!A !A  B B B k' !K  L L L h|B  D D D
l<=  ? ? ?
): .--3VN-C-C	  E E E
 /L  M M M mLF  G G G hS#qG  H H H os "3  4 4 4 nWaM  N N N (8  : : :
W5  6 6 6 |8  9 9 9 
Hb--3VN-C-C  E E E 
HbI  K K K
+S"36  7 7 7 	6 $3a=  > > >
 1D x'8  : : :
(H  J J J
lJ  K K K
 sE  G G G MrL   c                     t                      }d}t           fdt          D                       rd}d|v }d|v } D ]}|dk    rN|r|r|                    h d           $|r|                    h d           >|                    h d	           V|d
v rM|r|r|                    dh           u|r|                    ddh           |                    ddh           |dv r|s|                    |           |S )zexpand to individual E/W codesFc              3   P   K   | ]t          fd D                       V   dS )c              3   B   K   | ]}                     |          V  d S r+  r,  )r'  rh  conflicting_codes     rJ   r-  z*_expand_codes.<locals>.<genexpr>.<genexpr>  sE         !++D11     rL   N)r4  )r'  r  rZ  s    @rJ   r-  z _expand_codes.<locals>.<genexpr>  sj        
 !	     !         rL   Tr   r   W>   W1W2W3W6W505>   r  r  r  r  r   r  >   r  r  r  r  r   r  )W5W50r  r   )r   allCONFLICTING_CODESr  r  )rZ  ignore_codesretis_conflictis_ignore_w503is_ignore_w504rh  s   `      rJ   _expand_codesr    s   
%%CK
    
 %6      |+N|+N  3;; E. E

;;;<<<< E

CCCDDDD

CCCDDDD]"" -. -

F8$$$$ -

FF+,,,,

FF+,,,,***{*GGDMMMJrL   c                 6   t                      }|                    |           j        s"j        s|                    t
          d           d j        D             _        |rct          |          }	 t          |          }n# t          $ r d}Y nw xY w|r|}|                    |           d j        D             _        dj        v rt          j                  dk    r|                    t
          d           j
        r|                    t
          d           j        r|                    t
          d	           j        r|                    t
          d
           t          j                  dk    r)j        s"j
        s|                    t
          d           j        r)j        s"j
        s|                    t
          d           j        r"j
        r|                    t
          d           j        dk    r|                    t
          d           j        dk    r|                    t
          d           j        rBt!          t#          j                  j        rt#          j                  ng           _        j        rYt#          j                  _        t'          fdt(          D                       rj                            t(                     n1j        s*j        r
h d_        nt#          t.                    _        j        rt#          j                  _        ni _        j        dk     rddl}|                                _        j        dk    r)j        s"j
        s|                    t
          d           j        rcj        d         dk    r|                    t
          d           j        d         j        d         k    r|                    t
          d           S )zParse command-line options.zincorrect number of argumentsc                 ,    g | ]}t          |          S r&  decode_filenamer  s     rJ   r(  zparse_args.<locals>.<listcomp>  s     ???D/$''???rL   Nc                 ,    g | ]}t          |          S r&  r  r  s     rJ   r(  zparse_args.<locals>.<listcomp>  s     CCCod++CCCrL   r   r   z"cannot mix stdin and regular filesz)--diff cannot be used with standard inputz---in-place cannot be used with standard inputz.--recursive cannot be used with standard inputz^autopep8 only takes one filename as argument unless the "--in-place" or "--diff" args are usedz2--recursive must be used with --in-place or --diffz,--in-place and --diff are mutually exclusiver   z(--max-line-length must be greater than 0z$--indent-size must be greater than 0c              3   \   K   | ]%t          fd j        D                        V  &dS )c              3   B   K   | ]}                     |          V  d S r+  r,  )r'  ignore_coder  s     rJ   r-  z'parse_args.<locals>.<genexpr>.<genexpr>a  sE        # %//<<     rL   N)r4  r  )r'  r  argss    @rJ   r-  zparse_args.<locals>.<genexpr>`  sq       
 

 %	     '+{     
 
 
 
 
 
rL   >   Er  r  r  r  z!parallel jobs requires --in-placez --range must be positive numberszAFirst value of --range should be less than or equal to the second)r  rN  r  
list_fixesexitEXIT_CODE_ARGPARSE_ERRORread_configread_pyproject_toml	Exceptionr   r  re  	recursiver!  rk  r   r  _split_comma_separatedr  r  r  r  r   r  excluderi  multiprocessing	cpu_countr/  )rx  rJ  r  parser_with_pyproject_tomlr  r  s        @rJ   rN  rN  
  s   __FY''D: Odo O,.MNNN??DJ???DJ 
DT6**	.)<T6)J)J&& 	. 	. 	.)-&&&	.% 	0/F  ++CC
CCC

djtz??QKK(4  
 9 	KK(;  
 = 	KK(?  
 > 	KK(@  
 4:DMTY$@	
 	
 	
 ~ 
t} 
	 
$@	
 	
 	

 } 
 
$:	
 	
 	

 q  $6	
 	
 	

 1$2	
 	
 	

 { 
#"4;//48KG#DK000R
 

 { A,T[99 
 
 
 

 ):
 
 
 
 
 	2 K0111[ A? 	A777DKK0@@DK| -dl;;y1}} 	#--//	y1}}dm}ty}$/	
 	
 	

  ?1""KK(2   ?1 222KK(    Ks   7B BBc              #     K   |                      |          D ]\  }}|                    d                              dd          }|                    |          sD||         }|t          u r|                     ||          }n6|t          u r|                     ||          }n|                     ||          }|||fV  d S )Nr   r  )rg  r7  rV  r   r5  getintbool
getboolean)configsectionoption_listkr  norm_optopt_typerT  s           rJ   _get_normalize_optionsr    s      ,,w'' ! !A88C==((c22x(( 	x(s??MM'1--EE%%gq11EEJJw**E5     ! !rL   c           	        
 t                      }	 |                    | j                   | j        s| j        o@t
          j                            t
          j                            | j                            x
}|rK|                    
fdt          D                       rn$t
          j        
                    
          \  
}|Ki }d |j        D             }dD ]`}|                    |          st          |||          D ]6\  }}}	| j        r$t          d                    |||	                     |	||<   7a |j        di | n# t$          $ r Y nw xY w|S )z5Read both user configuration and local configuration.c                 P    g | ]"}t           j                            |          #S r&  )ospathr   )r'  fnparents     rJ   r(  zread_config.<locals>.<listcomp>  s9      :  :  :$& !#VR 8 8  :  :  :rL   c                 P    i | ]#}|j         |j        pt          |j                  $S r&  destrP  r  r'  os     rJ   
<dictcomp>zread_config.<locals>.<dictcomp>  s;     1 1 1 vqv8ai 1 1 1rL   )r<   r;   flake8z+enable config: section={}, key={}, value={}r&  )r	   rT   global_configignore_local_configr  r  r  abspathcommonprefixPROJECT_CONFIGr6  _actionshas_sectionr  r	  r
  rc   set_defaultsr   )r  r  r  taildefaultsr  r  r  r  rT  r  s             @rJ   r  r    s   FD&'''' 	7 J 227??$$TZ00,2 ,2 2FT 7;;  :  :  :  :*8 :  :  : ; ; !#v!6!6	  7 1 1 &1 1 1 9 	+ 	+G%%g.. &<VW=H'J 'J + +"!U< ,GNNE+ + , , ,%*""+ 	''h''''    Ms   D;E 
EEc                 :   ddl }d}t          j                            | j                  rAt          | j                  5 }|                    |          }ddd           n# 1 swxY w Y   | j        s| j        o@t          j        	                    t          j        
                    | j                            x}}|rt          j                            |d          }t          j                            |          r=t          |          5 }|                    |          }	 ddd           n/# 1 swxY w Y   t          j                            |          \  }}||sdS |                    di                               d          dS |                    d                              d          }i }d |j        D             }	d}
|                                D ]\  }}|                    d                              dd	          }|	                    |          sDt%          |          t&          t(          fv r||
v rd
                    |          }n|}| j        r#t-          d                    ||                     |||<   |r |j        di | |S )z+Read pyproject.toml and load configuration.r   Nzpyproject.tomlr  r  c                 P    i | ]#}|j         |j        pt          |j                  $S r&  r  r  s     rJ   r  z'read_pyproject_toml.<locals>.<dictcomp>  s;     - - - 6164T!)__ - - -rL   )r  r   r   r  r   z.enable pyproject.toml config: key={}, value={}r&  )tomlr  r  existsr  rH   loadr  r  r  r  r   r6  r   r  rg  r7  rV  rP  r   r\  r	  r
  rc   r  )r  r  r  r  ro  r  r  pyproject_tomlr  r  TUPLED_OPTIONSr  vr  rT  s                  rJ   r  r    s   KKKF	w~~d()) #$$%% 	#YYr]]F	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# # 	3
 .rwG  ,,(. (. 	. 	3W\\&2BCCNw~~n-- .)) R!YYr]]F                W]]622NVT  	3  tzz&"!!*--5tZZ##J//FH- -"O- - -K *N,,.. # #A88C==((c22x(( 	77tUm##N(B(BHHQKKEEE< 	7 %%+VAu%5%57 7 7" (''h'''Ms#   A!!A%(A%D00D47D4c                 @    d |                      d          D             S )zReturn a set of strings.c                 ^    h | ]*}|                                 |                                 +S r&  ru  )r'  r   s     rJ   rY  z)_split_comma_separated.<locals>.<setcomp>  rv  rL   r   r6  )r  s    rJ   r  r    s"    GGV\\#%6%6GGGGrL   c                 |    t          | t                    r| S |                     t          j                              S )zReturn Unicode filename.)r  r   rG  r  getfilesystemencodingr  s    rJ   r  r     s4    (G$$ ??3466777rL   c               #   B  K   dt          t          j                  fV  t          ddd          } t	          |           D ]x}t          j        d|          }|r_|                    d                                          t          j	        ddt          t          | |          j                            fV  yt          t                                D ]Y\  }}|                                d	t          |          z
  dz  z   t          j	        ddt          |j                            fV  Zt          t                    D ][}|                                d	t          |          z
  dz  z   t          j	        ddt          t          j                            fV  \dS )
zYield pep8 error codes that autopep8 fixes.

    Each item we yield is a tuple of the code followed by its
    description.

    r  NrB   )rI   r   r   zfix_([ew][0-9][0-9][0-9])r   z\s+r4  r   )r  rm  r  r   dirr  rb   r  r  r  r  r   ry  r   r  r  )instance	attributerh  rw  s       rJ   supported_fixesr    s      $X%566
7777dR@@@H]]  	x3Y?? 	

1##%%vs(9)E)E)MNNP P    #<>>22 I Ixzz||q3t99}33vfc#4X5E#F#FGGI 	I 	I 	I 	I |$$ I Izz||q3t99}33vfc#4X5E#F#FGGI 	I 	I 	I 	II IrL   c                 @    | r|                      d          d         ndS )zReturn summary of docstring.r   r   rB   r  )	docstrings    rJ   r  r  $  s#    '089??4  ##b8rL   c                 
   |                                  sdS d}|                                                     d          }d|d                                                             d          s|d                                         d         dvrfdD ]c\  }}|d                             |          }|d                             |          }	|dk    r"|	dk     s	|	|dz   k    rt          d|z             dt          fd|D                       }
|d	t          d|
|z
            z  z  }|t          |          z  }|d
t          d |D                       z  z  }dddd	                    |d         d                   }t          |          dk    r4|r2|d                                                             |          r|dz  }t          |          D ]"\  }}|                                 }|                    d          r0dD ]'}|                    |          r|dz  }||k    r|dz  }(|                    d          r	d|v r|dz  }|                    d          rt          |          t          |          k    r|dz  }|                    d          r4|dd                                                             d          r|dz  }|                    d          r<t          |          dk    r)|d                                         s
|d         dv r|dz  }|                    d          r|dz  }t          |          r|dz  }t          j        d|                    d                    r|dz  }t          j        d|                    d                    r|dz  }|                    d           r|dz  }|                    d!          r|d"z  }|                    d#          rt          |          }|dz  }|t          |          k     r||t          ||                   z  }||                                                             d          r|}n4||                             d#          sn|dz  }|t          |          k     |||k     r|d$z  }n	||rdndz  }d|v r|                    d%          r|d$z  }|                    d%          r|dz  }|d$t!          |          z  z  }$t          d|          S )&zDReturn rank of candidate.

    This is for sorting candidates.

    r   r   r;  r>   rw   z()z[]z{}r   c              3   `   K   | ](}t          |                                          z   V  )d S r+  )r   r  )r'  rB  rM  s     rJ   r-  z'line_shortening_rank.<locals>.<genexpr>D  s6      AAa&3qwwyy>>1AAAAAArL   r   r   c              3   4   K   | ]}t          |          V  d S r+  rL  rM  s     rJ   r-  z'line_shortening_rank.<locals>.<genexpr>K  s(      "?"?3t99"?"?"?"?"?"?rL   rr  r  r  r     )r  r   r   r   r   r  i  z': )r   r   r   r  r   Nr   r   r  i,  r  z.*[(\[{]\s*[\-\+~]$z\ z.*lambda\s*\*$r   r  2   rn  
   rk   )r  r   r6  r7  r`   r   rs  r   standard_deviationr   r   rx   r  has_arithmetic_operatorr  rb   count_unbalanced_brackets)r  r   r!  r   rankr  openingclosingopening_locclosing_loccurrent_longestbad_staring_symbollinenocurrent_line	bad_start	total_lenrM  s                   @rJ   rA  rA  )  s    ?? qD$$T**EF!HOO((--:a"U**"4 	: 	:Wg  (--00K(--00Ka??k[1_&D&D [99FAAAA5AAAAAOAA89999DCJJD 	A""?"?"?"?"?????D   #eAhrl## 
 5zzA~~	!HOO(();<<	 BJD )% 0 0 _= _=#))++""3'' 	2 	 	I&&y11  y(( !!";<<	\!!DLD  !566 	<  C$4$444 %%c**SbS!((**33C88  %%c**L!!A%%b!))++ &/;B/?3/F/F $$S)) &|44  8*L,?,?,F,FGG 	DLD8%|':':5'A'ABB 	DLD  !566 	BJD ""6** 	BJD  && 	3 L))IaKF3u::%%Sv///	=''))44S99  /IV}--d33 ! 3u::%% ?**
|22 ,<#8#8#=#=BJD   %% 	CKD.|<<<<q$<<rL   c                     t          |           } | sdS t          |           t          |           z  t          fd| D                       t          |           z  dz  S )zReturn standard deviation.r   c              3   (   K   | ]}|z
  d z  V  dS )r   Nr&  )r'  r"  means     rJ   r-  z%standard_deviation.<locals>.<genexpr>  s+      11ATa111111rL   g      ?)r   r1  r   )numbersr  s    @rJ   r  r    sl    7mmG qw<<#g,,&D111111111LL   rL   c                 2    t           j        D ]	}|| v r dS 
dS )z6Return True if line contains any arithmetic operators.TF)r;   ARITHMETIC_OP)r   r*   s     rJ   r  r    s2    -  t44  5rL   c                     d}dD ]@\  }}|t          |                     |          |                     |          z
            z  }A|S )z/Return number of unmatched open/close brackets.r   r  )rK  r+  )r   r+  r  r  s       rJ   r	  r	    sS    E. @ @TZZ((4::g+>+>>???LrL   c                    g }d}d}t          |          D ]L}|t          |           k     r5||k    r/|                    | ||                                                    |}M|                    | |d                    |S )z9Split line at offsets.

    Return list of strings.

    r   N)r   r   r   r  )r   r  r  previous_offsetcurrent_offsets        rJ   r  r    s     FON // ) )CII%%/^*K*KMM$~=>DDFFGGG(
MM$~'(((MrL   c                   $    e Zd ZdZd Zd Zd ZdS )rf  zReplace line endings to work with sys.stdout.

    It seems that sys.stdout expects only '\n' as the line ending, no matter
    the platform. Otherwise, we get repeated line endings.

    c                     || _         d S r+  )_LineEndingWrapper__output)r   rk  s     rJ   r   zLineEndingWrapper.__init__  s    rL   c                     | j                             |                    dd                              dd                     d S )Nr   r   r   )r!  rg  rV  )r   ss     rJ   rg  zLineEndingWrapper.write  s<    AIIfd33;;D$GGHHHHHrL   c                 8    | j                                          d S r+  )r!  rh  r  s    rJ   rh  zLineEndingWrapper.flush  s    rL   N)r  r  r  r  r   rg  rh  r&  rL   rJ   rf  rf    sN           I I I    rL   rf  c                 <   t           j                            |           }|                    d          rdS |D ]2}t	          j        ||          r dS t	          j        | |          r dS 3t           j                            |           st          |           sdS dS )z4Return True if file is okay for modifying/recursing.r  FT)r  r  basenamer`   fnmatchisdiris_python_file)rI   r  	base_namer~  s       rJ   
match_filer+     s      **IC   u  ?9g.. 	55?8W-- 	55	 7=="" >(+C+C u4rL   c              #   V  K   | r|                      d          }|rat          j                            |          rBt          j        |          D ],\  }}| fd|D             z  } fd|D             |dd<   -n&d}D ]}t          j        ||          rd} n|s|V  | dS dS )zYield filenames.r   c                     g | ]P}t          t          j                            |                    0t          j                            |          QS r&  r+  r  r  r   )r'  fr  roots     rJ   r(  zfind_files.<locals>.<listcomp>  s\     6 6 6!+BGLLq,A,A,3"5 "56bgll433 6 6 6rL   c                 p    g | ]2}t          t          j                            |                    0|3S r&  r.  )r'  r   r  r0  s     rJ   r(  zfind_files.<locals>.<listcomp>  sL     ": ": ":%/T10E0E07&9 &9":! ": ": ":rL   NFT)r   r  r  r(  walkr'  )		filenamesr  r  r  directorieschildrenis_exclude_matchr~  r0  s	     `     @rJ   
find_filesr7    s7     
 }}Q 	t,, 	/1wt}} : :+k8 6 6 6 6 6X 6 6 6 6	": ": ": ": ":[ ": ": ":AAA	:  %"  ?411 '+$E $ 


#      rL   c                    | d         j         r4t          d                    | d                   t          j                   	 t          |  S # t          $ r/}t          t          |          t          j                   |d}~ww xY w)z>Helper function for optionally running fix_file() in parallel.r   z	[file:{}]r   r   N)r	  r
  rc   r  r  rp  IOErrorr   )r  r   s     rJ   	_fix_filer:  )  s    !} Bk  A//cjAAAA$$   genn3:....s   A 
B*B  Bc                    g }t          | |j        |j                  } |j        dk    rddl}|                    |j                  }g }| D ]5}|                    t          ||ff          }|                    |           6|	                                 |
                                 |j        rf|D ]c}	t          j                            |	                                                                           t          j                                         d|                    d |D                        n| D ]}t          |||f          }||j        r|dk    r|                    |           :|j        r|                    |           Wt)          |          }
d
                    |
                                          |                                k    r|                    |           |S )z?Fix list of files.

    Optionally fix files recursively.

    r   r   Nc                 :    g | ]}||                                 S r+  )r   )r'  rB  s     rJ   r(  z&fix_multiple_files.<locals>.<listcomp>I  s!    ???ArL   rB   )r7  r  r  ri  r  Poolapply_asyncr:  r   closer   r  r  stdoutrg  r   rG  rh  r  re  r]   r"  )r3  r   rk  r  r  poolretsr  r  r=   rl  s              rJ   fix_multiple_filesrC  4  s    G9g&7III|a##GL11 	 	D""9g.@AACKK

		< 	# # #
  !1!1222
  """"?????@@@@ 	( 	(DT7F344C{| ("99NN3'''! (s####"5d";";77?++6688CNN<L<LLLNN3'''NrL   c                    |                      d          rdS 	 t          | t                    5 }|                    t                    }|s	 ddd           dS |                                d         }ddd           n# 1 swxY w Y   n# t
          t          f$ r Y dS w xY wt                              |          sdS dS )z'Return True if filename is Python file.z.pyTr@   NFr   )	rx   rK   MAX_PYTHON_FILE_DETECTION_BYTESrT   r"  r9  
IndexErrorPYTHON_SHEBANG_REGEXrb   )rI   r/  r   
first_lines       rJ   r)  r)  [  s:    t	!@B B B 	.EF669::D 	. 	. 	. 	. 	. 	. 	. 	. **1-J	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. Z    uu  %%j11 u4s@   B B B B 4B  BB BB B! B!c                 `    d| v p*d| v p&|                                                      d          S )zReturn True if line is likely part of a multiline string.

    When multiline strings are involved, pep8 reports the error as being
    at the start of the multiline string, which doesn't work for us.

    r(  z'''rn  )r   rx   r%  s    rJ   r  r  q  s:     	 	%	%t$$rL   c                 j     t          j        |          t          | d          r| j        n|           S )z&Return output with specified encoding.buffer)codecs	getwriterr  rK  )rk  rD   s     rJ   rF  rF    s<    %6H%%)0)B)B'2fmm+13 3 3rL   c                  N    t          j                    pt          j                    S )zReturn preferred encoding.)localegetpreferredencodingr  getdefaultencodingr&  rL   rJ   rH  rH    s    &((DC,B,D,DDrL   c                    | t           j        } 	 t          j        t          j        t          j                   n# t
          $ r Y nw xY w	 t          | dd         |          }|j        rLt          t                                D ])\  }}t          d                    ||                     *t          S |j        dgk    r|j        rJ t           j        j        pt#                      }t           j                                        }t'          |||          }t)          t           j        |                              |           t/          |          t/          |          k    r|j        r	t2          S dS dS |j        s|j        r't7          t9          |j                            |_        n#t;          |j                  dk    sJ |j        rJ t?          |j        |t           j                  }|j        rtA          d |D                       }	ntA          d	 |D                       }	|j        r	|	r	t2          S dS dS # tB          $ r
 tD          cY S tF          $ r
 tD          cY S w xY w)
zCommand-line entry.Nr   rM  z{code} - {description})rh  r  r   rQ   c                 4    g | ]}t          |          d k    S )r   rL  r'  r  s     rJ   r(  zmain.<locals>.<listcomp>  s"    <<<S3s88q=<<<rL   c                     g | ]}|d uS r+  r&  rT  s     rJ   r(  zmain.<locals>.<listcomp>  s    >>>s3d?>>>rL   )$r  argvsignalSIGPIPESIG_DFLAttributeErrorrN  r  r   r  r
  rc   EXIT_CODE_OKr  re  stdinrD   rH  rT   rK  rF  r@  rg  r\  	exit_codeEXIT_CODE_EXISTS_DIFFr  r   r   r   r  rC  r4  r9  EXIT_CODE_ERRORKeyboardInterrupt)
rV  rJ  r  rh  r  rD   
read_stdinfixed_stdinr  r  s
             rJ   mainrc    s   |xfnfn5555   )$qrr(>>>? 	 %+O,=,=%>%> 9 9!k.55; 6 8 8 9 9 9 9:#}$$$y);\^^H))J":thGGGK 
X666<<[IIIJ4#4#444> 100 541 1 } *	 *!#dj//22

4:!++++>)))(T3:FFGy @<<G<<<== >>g>>>??~ -# -,,- - - -      s6   ): 
AAA+I 7B?I ;CI I'I'&I'c                       e Zd ZdZd Zd ZdS )CachedTokenizerzzA one-element cache around tokenize.generate_tokens().

    Original code written by Ned Batchelder, in coverage.py.

    c                 "    d | _         d | _        d S r+  )	last_textlast_tokensr  s    rJ   r   zCachedTokenizer.__init__  s    rL   c                     || j         k    rFt          j        |          }t          t	          j        |j                            | _        || _         | j        S )z*A stand-in for tokenize.generate_tokens().)rg  rG   r   r   rP   rX  rS   rh  )r   r   	string_ios      rJ   rX  zCachedTokenizer.generate_tokens  sS    4>!!D))I#();<<   D "DNrL   N)r  r  r  r  r   rX  r&  rL   rJ   re  re    s<                       rL   re  __main__)r=   Nr>   )r>   )r=  r>  FFFr+  r5  )NrB   )rB   F)TNNrB   r  F)T)FFrB   )FrB   r  )NNF)r  rB   N)NT)r  r  r   r   r   r   r  rL  r  r^  r  r'  rt  rG   r1  rI  rO  r  r  rW  r  r4  r  rP   r(  r  configparserr   r	   r   ImportErrorr;   r
   r   	NameErrorrQ  r  r  r  r  r  rG  r  r  r  r  r  r/  r  r  r[  r_  r^  r  	frozensetr  r  ry   r  rX  r  platformr  
expanduserr  r   getenvr  r  rE  rK   rF   r]   ri   register_checkr   _checksr6  r   r  r  r  rG  r  rP  r   r  r  rm  r  ro  r  r  r  r  r  r  r   r>  r  r  rD  r  r  
namedtupler  r  r  rV  ry  r  r  r'  r(  r  r  r  r  r  r  r  rR  r.  r  ri  r  r  r  rY  r  r  r  r0  r|  r}  r  r<  r>  r  rK  rF  rI  rp  ry  r  r[  rv  r  r  r  rN  r  r  r  r  r  r  r  rA  r  r  r	  r  rf  r+  r7  r:  rC  r)  r  rF  rH  rc  re  _cached_tokenizerrX  r  r  r&  rL   rJ   <module>rw     sI  d	 	 ' & & & & &       % % % % % % ' ' ' ' ' '           				       				 				  



     



#======""""""" # # #------""""""""#     9 9 9 9 9 9GG   GGG  
	 "rz"=>> rzBCC#$JKK !+,F!G!G BJ}-- !rz">?? "
#=>> rz344
566   $)IseIseI"""##I"""##IAAABBI---..%    %  % &,Z " LJKFH   * <7W''(9::NNW\\)"),=">"> #B"$'"4"4["A"A"/1 1N 
w~~n%% O
|w++J77bg&8&8&E&EvNN= #'       & & &= = =*  / 0 0 0|: |: |:~ '(IJ  0 1 1 1[6 [6 [6 [6 [6f [6 [6 [6|R R Rj      =?FK- - - -`8 8 87 7 7  8( ( (4  .   ' ' '  &H H H'  '  '  ' T   B	 	 	 	 BD%*' ' ' '$@ @ @ @G G G(
 
 
    (        H FH# # # #N 35B* B* B* B*J* * * 	w )A )A )A 	B 	BZ  Z  Z  Z  Z v Z  Z  Z z
N, N, N, N, N,6 N, N, N,bW W W W W W W Wt
 
 
 
 
I 
 
 

 
 
 
 
9 
 
 

 
 
 
 
	 
 
 
    	   ; ; ; ; ;9 ; ; ;
8 8 8 8v  B' ' 'T  8L L L^) ) )>  (& & &#/ #/ #/L       { { { { { { { {|0 0 0f     $  D D DB  D  C C CL   @$ $ $N       F  . . .  "7 7 7 7  03N 3N 3N 3Nl, , , ,^
' 
' 
'/ / / BD!# # # #L  "  
F F FR# # #LC C C CL! ! !# # #L3 3 3lH H H
8 8 8I I I89 9 9 ',Q Q Q Qh           (       &  &  ,  $ $ $ $N  ,  3 3 3E E E
5 5 5 5p         f      . $O%% #3 zCHTTVV s$   ,A9 9BBB B('B(