
    hbm                    2
   S r SSKJr  SSKJr  SSKJr  SSKJr  SSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJrJr  SSKrSr S	r!S
r"Sr#\RH                  " S5      r%\RH                  " S5      r&\RH                  " S5      r'\RH                  " S5      r(\RH                  " S5      r)\RH                  " S5      r*\RH                  " S5      r+\RH                  " S5      r,\RH                  " S5      r-\RH                  " S5      r.\RH                  " S5      r/\RH                  " S5      r0Sr1Sr2Sr3Sr4\5" \5" S/5      \5" S/5      \5" / SQ5      \5" / SQ5      \5" / SQ5      \5" / S Q5      /5      r6S!r7S"r8S#r9\Rt                  S$:X  a  \Rv                  Ry                  S%5      r=ON\Rv                  R}                  \R~                  " S&5      =(       d    \Rv                  Ry                  S'5      S(5      r=\Rv                  R                  \=5      (       da  \Rt                  S$:X  a  \Rv                  Ry                  S)5      r=O5\Rv                  R}                  \Rv                  Ry                  S'5      S*5      r=S+rAS,rBS-rC\R                  S.:  a  S/rCSS0 jrESS1 jrFS2\G4S3 jrHSS4 jrIS5 rJS6 rKS7 rL\R                  " \5        \R                  S8   \R                  	 \R                  " \K5        \R                  " \L5         " S9 S:\P5      rQS; rRS< rS  SS= jrTS> rUS? rVS@ rWSA rXSB rYSSC jrZSSD jr[SE r\SF r]SG r^SH r_SI r`SJ raSK rb SSL jrc SSM jrdSN re\R                  " SO/ SPQ5      rg " SQ SR\P5      rh " SS ST\P5      ri " SU SV\P5      rj " SW SX\j5      rk " SY SZ\j5      rl " S[ S\\j5      rm " S] S^\j5      rn " S_ S`\j5      roSSa jrpSb rqSc rrSd rsSe rtSf ruSg rvSh rwSi rxSSj jry " Sk Sl\P5      rzSm r{Sn r|So r}Sp r~Sq rSr rSs rSSt jrSu rSSv jrSw rSx rSy rSSz jrS{ rSS| jrSS} jrS~ rS r  SS jrS rS rS rS rS\GR&                  S\S\GSS4S jrSS jrS rS rS rS rS rS rS r SS jrS rS rS rS r " S S\P5      rS rS rS rSS jrS rS rS rS rSS jr " S S\P5      r\" 5       r\GR^                  r\S:X  a  \GRb                  " \" 5       5        gg)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Errorz2.3.2

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): *offz.^[ \t\f]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)zY([=!]=)\s+type(?:\s*\(\s*([^)]*[^ )])\s*\))|\btype(?:\s*\(\s*([^)]*[^ )])\s*\))\s+([=!]=)z(type\s*\(\s*[^)]*?[^\s)]\s*\))      c   ,%)r   ([{r   r   r   r   )
r   r   r   r   r   +-*///)r   r   r   r   r   r   zE226,E24,W50,W690   W503W504win32z~\.pycodestyleXDG_CONFIG_HOMEz	~/.configpycodestylez~\.pep8pep8)z	setup.cfgztox.iniz.pep8z.flake8i   F)      Tc                 &    UR                    SU  S3$ )N: r
   )__name__)messagecategory___lines        B/home/james-whalen/.local/lib/python3.13/site-packages/autopep8.py_custom_formatwarningr-      s     7)2..    c                 N    U(       d	  [        XS9n[        R                  " XUSS9$ )z,Return opened file with a specific encoding.limit_byte_check )modeencodingnewline)detect_encodingioopen)filenamer3   r4   r1   s       r,   open_with_encodingr:      s'    "8O778 r.   r9   c                 N    [        U 5       n[        U5       H`  u  p#US:X  a  US   S:X  a
    S S S 5        gUS:  a    O>[        R                  U5      nU(       d  MD  UR	                  5       S   s  sS S S 5        $    S S S 5        g! , (       d  f       g= f! [
         a     gf = f)Nr   u   ﻿	utf-8-sigr   utf-8)r8   	enumerateENCODING_MAGIC_COMMENTsearchgroups	Exception)r9   
input_fileidxr+   matchs        r,   _detect_encoding_from_filerF      s    (^z&z2	!8Q8 3& ^ !8.55d;5 <<>!,, ^2   ^   sJ   B !BB "BB1	B ;B=B 
BB B 
B$#B$c                     [        U 5      nUS:X  a  U$  [        XS9 nUR                  U5        SSS5        U$ ! , (       d  f       U$ = f! [        [        [
        4 a     gf = f)zReturn file encoding.r<   r4   Nzlatin-1)rF   r:   readLookupErrorSyntaxErrorUnicodeDecodeError)r9   r1   r4   	test_files       r,   r6   r6      sf    )(3H;<	NN+, = =<&89 s+   	A :	A 
A	A 	A A$#A$c                 n    [        U 5       nUR                  5       sSSS5        $ ! , (       d  f       g= f)zReturn contents of file.N)r:   	readlines)r9   rC   s     r,   readlines_from_filerP      s$    	H	%##% 
&	%	%s   &
4c              #   |  #    UR                  S5      (       aC  U(       a;  [        R                  R                  U 5      (       a  SSR	                  U5      4v   ggg[        R                  R                  U5      (       a;  U(       a3  U(       d+  U(       d#  U R                  S5      (       a  SU ;   a  Sv   ggggggg7f)z6Check for missing blank lines after class declaration.zdef z
async def r   zE303 too many blank lines ({})z(self)r   z#E301 expected 1 blank line, found 0N)
startswithr    DOCSTRING_REGEXrE   format)logical_lineblank_linesblank_beforeindent_levelprevious_logicals        r,   extended_blank_linesr[      s      ""#9::;66<<\JJ6==kJKK K;		$	$	*	*+;	<	< ##$:;;|#<< $ <    
=s   B:B<c              #     #    US   S   S   nSUS   S   S   -   U-
  nU(       d  US:X  a  gU R                  S5      nS=pUS:w  a  [        4O[        S[        -  4nS/U-  nS/U-  nS//nS/n0 nUS   S   nUS   /nSnSnSnS	nU GH  u  nnnnnU	US   U-
  :  nU(       a;  US   U-
  n	U(       + =(       a#    U[        R                  [        R                  4;  nUnU(       Ga  Un[
        R                  " U5      U-
  X'   U[        R                  :H  =(       a    US
;   n[        X   5       H  nX   UU   -
  nUU;   nU(       d  M    O   X   (       a  WX   :H  nU(       + =(       a     WS:  =(       a    UR                  US   5      n U(       a0  UU
   (       a&  US   UU
   :w  a  USR                  UU
   5      4v   GO3U(       a(  W(       d!  U(       a  USR                  UU
   5      4v   GOUU
   (       a*  US   UU
   :  a  U SLa  USR                  UU
   5      4v   OW(       d  U(       a=  X   S[        -  :X  a.  U(       a"  U(       d  USR                  UUW   -   5      4v   WX'   OU SL a	  US   UU
'   OwU U[        4;   a  OjX-W   -   [        -   n!WS::  a  SU!4n"O>UU
   (       a  SUU
   4n"O,U(       d  X   (       a  SU!4n"OU[        :  a  SU!4n"OUX'   SU!4n"USR                  " U"6 4v   X   (       a?  U[        R                  [        R                  4;  a  UU
   (       d  US   UU
'   SUUS   '   OU[        R                  [        R                  4;   d  US;   a  [        UUS   '   O[U(       d   U	(       d  U
(       d  US:X  a  SUUS   S-   '   O4US:X  a.  UUS   S R                  5       (       a  X   R                  U	5        U[        R                  :X  Gau  US;   ag  U
S-  n
UR                  S5        UR                  S5        [!        U5      U
:X  a  UR                  / 5        X   R                  U	5        X==   S-  ss'   OUS;   a  U
S:  a  UR#                  5       =(       d    US   n#UR#                  5         [%        U
5       H  n$UU$   U#:  d  M  SUU$'   M     ['        U5       H  n%U%U#:  d  M  UU%	 M     XS-   S2	 U
S-  n
U
(       a  SUUU
   '   [%        U	SS5       H  n&UU&   (       d  M  UU&==   S-  ss'     O   [!        U5      U
S-   :X  d   eUS   U;  a,  UR)                  5       R                  S5      (       d  UUUS   '   US   US   :g  nU(       a  X   UUS   U-
  '   UnGM     U(       av  U(       dn  [
        R                  " U5      U[        -   :X  aL  WS   US   S-   4n'US[        -  -   n(W (       a  U'SR                  U(5      4v   gU'SR                  U(5      4v   gggg7f)zCOverride pycodestyle's function to provide indentation information.r   r   r   N:	r2   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_SIZEtokenizeNLNEWLINEr    expand_indentOPreversedgetrU   strCOMMENTSTRINGisspaceappendlenpoprangelistrstrip))rV   tokensrY   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_multiliner+   	last_linelast_line_begins_with_multiline
token_typetextstartendr5   close_bracketopen_rowhanghanging_indentvisual_indentone_indentederrorprev_indentdindrD   posdesired_indents)                                            r,   continued_indentationr      s{     q	!QIr
1a  9,Euz '',KOC $ 
%8%&)<%<%>  S5[F uJ IFE N)A,K!nFDI&+#.4*
D%da9,,(Y&C// I!(++x7G7G)HH .B+K *77=LJO (8;;6H45=M %Y%56!H)==!%!4!>	 7
 |"&%,"6!.. :4!8 :+//a9  8ve}, )"2"26%="ABBt )"2"26%="ABB58fUm#; , )"2"26%="ABB ?a*=&==  )"2"2<3=h3G4H #I J J#$& %au4+- ,(/C C 3!4 19#\2EE]#VE]3E&5<#\2E//#\2E#'EL#\2Egnne455 Kx{{H,<,<==u!!HF5M'+N58$X__h.>.>??,,'*N58$  Eddl)-N3q6A:&S[T#a&']2244##C( $u}
a T"y>U*$$R( '',q 519$jjl<k!n		uAay;.$%q	 &  /Ck)*3/ 0 aij)
48N6%=1 b"-Cc{{sq( . v;%!)+++a.$$&//44 ,0uQx( %aCF 2-7_Js1v	)*	O /5T 	+!!$'<:M+MMQxQ'%,?(??	((899	((899 	N , 	s    EXMX&X:XC>XrV   c                   <   \ rS rSrSr  S4S jrS\4S jrS rS r	S	 r
S
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r S  r!S! r"S" r#S# r$S$ r%S% r&S& r'S' r(S( r)S) r*S* r+S+ r,S, r-S- r.S. r/S/ r0S0 r1S1 r2S2 r3S3r4g)5FixPEP8i  a^  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,e275
    - e301,e302,e303,e304,e305,e306
    - e401,e402
    - e502
    - e701,e702,e703,e704
    - e711,e712,e713,e714
    - e721,e722
    - e731
    - w291
    - w503,504

Nc                    Xl         Uc  [        U5      U l        O+[        R                  " U5      nUR                  5       U l        X l        [        SR                  U R                  5      5      U l	        [        R                  " U R                  5      U l        0 U l        [        U R                  5       HP  u  pgUR                  S5      S:X  d  UR                  S5      S:X  d  M1  XpR                  ;  d  MB  X`R                  U'   MR     Uc
  [        5       OUU l        U R"                  U l        U R&                  U l        U R&                  U l        U R&                  U l        U R&                  U l        U R&                  U l        U R&                  U l        U R&                  U l        U R&                  U l        U R8                  U l        U R<                  U l        U R<                  U l         U R<                  U l!        U R<                  U l"        U RF                  U l$        U RF                  U l%        U RF                  U l&        U RN                  U l(        U RN                  U l)        U RN                  U l*        U RF                  U l+        U RX                  U l-        U RN                  U l.        U R^                  U l0        U RF                  U l1        U RF                  U l2        U RF                  U l3        U RF                  U l4        U Rj                  U l6        U(       a-  URn                  S:  d  URp                  (       a  U Rr                  OU Rt                  U l;        U Rx                  U l=        U R|                  U l?        U R|                  U l@        g )Nr2   import r   from r   )Ar9   rP   sourcer7   StringIOrO   options_get_indentwordjoinindent_wordcopyoriginal_sourceimportsr>   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_e204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_e275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)selfr9   r   contentsr   sioir+   s           r,   __init__FixPEP8.__init__  s    !-h7DK++h'C--/DK*2774;;+?@#yy5  -GA		)$)TYYw-?1-D,%&T"	 . ,3CE' 	# **************** ++q0G4H4H (()) 	 r.   returnc                 V    US   S-
  nU R                   U   nU R                  U   nX4:g  $ )z?Check if the fix affects the number of lines of another remark.r+   r   )r   r   )r   result
line_indextargetoriginal_targets        r,   _check_affected_anothers FixPEP8._check_affected_anothers  s7    F^a'
Z(..z:((r.   c           	      ^    [        U R                  5      u  p#Sn[        5       n[        U[        S9 GHS  nUS   U;   a  M  SUS   R                  5       -   n[        X5      (       Ga  [        X5      nUS   S-
  n	U R                  U	   n
[        [        U5      5      S:  nU(       a  S nU(       a\  [        U R                  UWW5      nU(       a=  [        [        US	   S	   S-   US   S	   S-   5      5      R                  U5      (       a  M  U R!                  U5      (       a  M  U" Xl5      nO!U R!                  U5      (       a  GM  U" U5      nUc  U(       a   eU R                  U	   U
:X  a  / nU(       a  UR#                  U5        GMY  U/ :X  aL  U R$                  R&                  S:  a/  [)        S
R+                  US   US   S9[,        R.                  S9  GM  GM  UR1                  US   5        GM  U R$                  R&                  S:  d  GM  [)        SR+                  U5      [,        R.                  S9  US   R3                  5       n[)        SR+                  U R4                  US   US   U5      [,        R.                  S9  GMV     g ! [        [        R                  4 a    Sn GNf = f)NTFkeyr+   fix_idr   r   r   z'--->  Not fixing {error} on line {line})r   r+   filer"   z--->  '{}' is not defined.infoz--->  {}:{}:{}:{}column)_find_logicalr   rK   rm   
TokenErrorr   sorted_priority_keylowerhasattrgetattrry   _get_parameters_get_logicalr{   intersectionr   updater   verboseprintrU   sysstderraddstripr9   )r   resultslogical_startlogical_endlogical_supportcompleted_linesr   fixed_methodnamefixr   original_lineis_logical_fixlogicalmodified_linesr   s                  r,   _fix_sourceFixPEP8._fix_source   s   	$+8+E(]"O %W-8Ff~0%t(:(:(<<t..d5#F^a/
 $J 7!$_S%9!:Q!>!"G&".t{{/5/</:#< #s5#AJqMA-#AJqMA-,/ (00< /11(1 %44V<< %(%9N44V<< %([N!)---{{:.-?)+!#**>:#r)||++q0ELL&,Tl M I!$- 1 $''v7<<''1,4;;<LM ZZ) "&>//1D-44T]]5;F^5;H5E59;  #zz	+s 9	 X001 	$#O	$s   J J,+J,c                    U R                   R                  U R                   R                  U R                   R                  U R                   R                  S.n[        XR                  5      nU R                   R                  (       ak  0 nU H4  nUS   U;  a  [        5       X4S   '   X4S      R                  US   5        M6     [        SR                  [        U5      US9[        R                  S9  U R                   R                  (       a?  U R                   R                  u  pVU Vs/ s H  nXTS   s=::  a  U::  d  M  O  M  UPM     nnU R!                  [#        SR%                  U R                  5      UU R                   R&                  S95        U R                   R                  (       a@  [)        S	 U R                  WS
-
  W  5       5      nXW-   S
-
  U R                   R                  S
'   SR%                  U R                  5      $ s  snf )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   r2   )r   r  r   c              3   D   #    U  H  nUR                  S 5      v   M     g7f)r
   Ncount).0slines     r,   	<genexpr>FixPEP8.fix.<locals>.<genexpr>  s$      A%?E D))%?s    r   )r   r  r  r  r   _execute_pep8r   r  r   r
  r  rU   ry   r  r	  
line_ranger  filter_resultsr   r   sum)r   pep8_optionsr  r  rr   r   r!  s           r,   r  FixPEP8.fixg  s    ll))ll))#||;; LL55	
  kk:<<HT7(*(+HtW%4!%%ai0  8??g, @ 39<E <<""00JE") 5'QV933 3 'G 5 	rwwt{{/C0737<<3J3JL 	M <<"" A%)[[3%?A AE).):DLL##A&wwt{{##5s   *H
H
H
c                     [        US   R                  5       S   5      nUS   S-
  nU R                  U   nSU-  UR                  5       -   U R                  U'   g)z^Fix 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   r   s        r,   r   FixPEP8._fix_reindent  s\      v 4 4 6q 9:F^a'
Z("%(9"9FMMO"KJr.   c                     US   S-
  nU R                   U   nUR                  5       R                  S5      (       d  / $ U R                  U-   U R                   U'   g)zFix under-indented comments.r+   r   #N)r   r1  rS   r   )r   r   r   r   s       r,   r   FixPEP8.fix_e112  sS    F^a'
Z(}}))#..I"&"2"2V";Jr.   c                     US   S-
  nU R                   U   n[        U5      nUR                  5       nUSS U-   U R                   U'   g)zFix unexpected indentation.r+   r   Nr   _get_indentationr1  r   r   r   r   r   strippeds         r,   fix_e113FixPEP8.fix_e113  sL    F^a'
Z(!&)==?"(*x"7Jr.   c                     US   S-
  nU R                   U   n[        U5      nUR                  5       nUR                  S5      (       d  / $ USS U-   U R                   U'   g)zFix over-indented comments.r+   r   r5  N)r   r9  r1  rS   r:  s         r,   fix_e116FixPEP8.fix_e116  sb    F^a'
Z(!&)==?""3''I"(*x"7Jr.   c                     US   S-
  nU R                   U   n[        U5      nUS:X  a  / $ UR                  5       nUSS U-   U R                   U'   g)zFix over-indented.r+   r   r_   Nr8  r:  s         r,   fix_e117FixPEP8.fix_e117  sX    F^a'
Z(!&)T>I==?"(*x"7Jr.   c                    [        US   R                  5       S   5      nUS   S-
  nU R                  U   nU[        [	        U5      5      -
  n[        [	        U5      5      n/ n[        [	        U R                  U   5      5      U:  ab  SU-  U R                  U   -   U R                  U'   UR                  SU-   5        US-  n[        [	        U R                  U   5      5      U:  a  Mb  U$ )9Fix indentation undistinguish from the next logical line.r   r   r+   r.  )r/  r0  r   ry   r9  rx   )r   r   r2  r   r   spaces_to_addr   r  s           r,   fix_e125FixPEP8.fix_e125  s    v 4 4 6q 9:F^a'
Z()C0@0H,II%f-."4;;z#:;<F'*]':'+{{:'>(?DKK
#!!!j.1!OJ	 "4;;z#:;<F r.   c                    [        US   R                  5       S   5      nUS   S-
  nU R                  U   nU[        [	        U5      5      -
  n[        [	        U5      5      nX&-
  nUS:X  a  US:X  a  SnUS:  a#  SU-  U R                  U   -   U R                  U'   g[        U5      nU R                  U   US U R                  U'   g)rE  r   r   r+   r   r   r.  N)r/  r0  r   ry   r9  abs)r   r   r2  r   r   rF  indent_lengthoffsets           r,   r   FixPEP8.fix_e131  s    v 4 4 6q 9:F^a'
Z()C0@0H,II,V45)9!mq&8MA'*]':'+{{:'>(?DKK
# 'F&*kk*&=fg&FDKK
#r.   c                 t    US   S-
  nU R                   U   nUS   S-
  n[        UUSS9nXPR                   U'   g)zRemove extraneous whitespace.r+   r   r   r2   rL  replacementNr   fix_whitespacer   r   r   r   rL  fixeds         r,   r   FixPEP8.fix_e201  sM    F^a'
Z(!A%v&,+-/ #(Jr.   c                     U R                   US   S-
     nUS   S-
  nUSU X#S R                  SS5      -   nX@R                   US   S-
  '   g)z-Remove extraneous whitespace around operator.r+   r   r   Nr_   r.  )r   replace)r   r   r   rL  rT  s        r,   r   FixPEP8.fix_e224  s^    VF^a/0!A%w&/"9"9$"DD*/F6NQ&'r.   c                    U R                   US   S-
     nUS   S-
  nUSU S-   X#S -   nUR                  SS5      UR                  SS5      :X  a  [        U5      [        U5      :X  a  X@R                   US   S-
  '   UR                  SS5      n [	        U5      n[        UR                  5       5      (       d  g [        R                  n[        U" XF5      5      n[        U5       H3  n	XYS   R!                  5       S   :w  a  M  U	S   S   nUSU S-   XCS -   nM5     X@R                   US   S-
  '   g/ $ ! [
        [        R                  4 a     gf = f! [         a    [        R                  n Nf = f)	z'Fix missing whitespace around operator.r+   r   r   Nr.  r2   r   r   )r   rW  r9  rs   generate_tokensrK   rm   r   check_syntaxr1  r    "missing_whitespace_around_operatorAttributeErrormissing_whitespacer|   rr   r0  )
r   r   r   rL  rT  
error_codets_missing_whitespaceerrorses
             r,   r   FixPEP8.fix_e225  s   VF^a/0!A%w#%w7
 MM#r"fnnS"&==U#'7'??.3KKv*+D!,J$U+  //EBB $ -e89Ff%1a01agv,uW~=	 &
 /4KKv*+I'  !4!45  " E&1&D&D#Es$   D5 ;E 5EEE21E2c                     US   S-
  nU R                   U   nUS   nUSU R                  5       S-   X4S R                  5       -   nXPR                   U'   g)zAdd missing whitespace.r+   r   r   Nr.  )r   r}   r1  rS  s         r,   fix_e231FixPEP8.fix_e231#  s_    F^a'
Z(!w&&(3.1G1G1II"'Jr.   c                    US   S-
  nU R                   U   n[        US   S-
  [        U5      S-
  5      nX4   R                  5       (       a  UnO&USU R	                  5       X4S R                  5       -   nUR                  S5      (       aX  UR	                  S5      U R                   U'   U R                   US-      R                  5       U R                   US-   '   US-   US-   /$ XPR                   US   S-
  '   g)z,Remove whitespace around parameter '=' sign.r+   r   r   N)z=\
z=\
z=\
 	\r   )r   minry   r  r}   r1  rk   )r   r   r   r   crT  s         r,   fix_e251FixPEP8.fix_e251+  s    F^a'
Z(
 x 1$Fa! 9??E2AJ%%'&**;*;*==E >>788&+ll;&?DKK
#*.++j1n*E*L*L*NDKK
Q'NJN33*/F6NQ&'r.   c                     U R                   US   S-
     nUS   nUSU R                  S5      nX#S R                  S5      nXER                  5       (       a  SU-   OS-   nX`R                   US   S-
  '   g)z&Fix spacing after inline comment hash.r+   r   r   N 	#z  # r
   )r   r}   r1  r  )r   r   r   rL  codecommentrT  s          r,   r   FixPEP8.fix_e262F  s{    VF^a/0!gv%%f-/((0MMOO(F*/F6NQ&'r.   c                 d   U R                   US   S-
     n[        U5      nUR                  S5      n[        S [	        U5       5       5      nUSU nXES R                  S5      nUR                  S5      (       a  gX6-   UR                  5       (       a  SU-   OS-   nXR                   US   S-
  '   g)	z%Fix spacing after block comment hash.r+   r   z 	c              3   :   #    U  H  u  pUS :w  d  M  Uv   M     g7f)r5  N )r"  indexrk  s      r,   r$  #FixPEP8.fix_e265.<locals>.<genexpr>X  s     F/heQ#XEE/s   	N!r.  r
   )r   r9  r1  nextr>   rS   r  )	r   r   r   r   r+   r   hashesrq  rT  s	            r,   fix_e265FixPEP8.fix_e265R  s    VF^a/0!&)}}U#F)D/FGdst*##E* c""GMMOO3=N*/F6NQ&'r.   c                     U R                   US   S-
     nUR                  5       R                  S5      (       a  g[        U5      nUS-   UR	                  S5      -   nX@R                   US   S-
  '   g)z"Fix too many block comment hashes.r+   r   r5  N# z# 	)r   r  rk   r9  r1  )r   r   r   indentationrT  s        r,   fix_e266FixPEP8.fix_e266d  sl    VF^a/0 <<>""3''&v.d"V]]6%::*/F6NQ&'r.   c                     US   S-
  nU R                   U   nUS   S-
  n[        UUSS9nXS:X  a  / $ XPR                   U'   g)z*Fix extraneous whitespace around keywords.r+   r   r   r.  rO  NrQ  rS  s         r,   r   FixPEP8.fix_e271q  sW    F^a'
Z(!A%v&,+.0 ?I&+KK
#r.   c                 \    SnX R                   US   S-
     -   U R                   US   S-
  '   g)zAdd missing blank line.r
   r+   r   N)r   )r   r   crs      r,   r   FixPEP8.fix_e301  s3    *,{{6&>A;M/N*NF6NQ&'r.   c                     S[        US   R                  5       S   5      -
  nSnU R                  US   S-
     R                  5       S:X  a  SnSU-  nX@R                  US   U-
     -   U R                  US   U-
  '   g)	zAdd missing 2 blank lines.r   r   r]   r   r+   \r
   N)r/  r0  r   r  )r   r   add_linenumrL  r  s        r,   fix_e302FixPEP8.fix_e302  s    #fVn224R899;;vf~)*002d:FKVF^f455 	F6NV+,r.   c                 n   [        US   R                  S5      S   R                  S5      S   5      S-
  n[        SU5      nSnUS   S-
  n/ nX2:  ab  US:  a\  U R                  U   R	                  5       (       d(  SU R                  U'   UR                  SU-   5        US-  nUS-  nX2:  a  US:  a  M\  U$ )	zRemove extra blank lines.r   r   r   )r   r   r+   r2   )r/  r0  maxr   r  rx   )r   r   delete_linenumcntr+   r  s         r,   fix_e303FixPEP8.fix_e303  s    VF^11#6q9??DQGH1LQ/ f~!"tqy;;t$**,,$&D!%%a$h/qAID "tqy r.   c                 x    US   S-
  nU R                   U   R                  5       (       d  SU R                   U'   gg)z/Remove blank line following function decorator.r+   r   r2   N)r   r  )r   r   r+   s      r,   fix_e304FixPEP8.fix_e304  s;    f~!{{4 &&(( "DKK )r.   c                 D   S[        US   R                  5       S   5      -
  nSnUS   S-
  n/ nUS:  at  [        U5      nX2:  ab  US:  a\  U R                  U   R	                  5       (       d(  SU R                  U'   UR                  SU-   5        US-  nUS-  nX2:  a  US:  a  M\  U$ Sn US:  a  O6U R                  U   R                  5       nU(       d  OUS   S	:w  a  OUS-  nM=  US-  nX`R                  U   -   U R                  U'   UR                  SU-   5        U$ )
z9Add missing 2 blank lines after end of function or class.r   r   r]   r   r+   r2   r   r
   r5  )r/  r0  rJ  r   r  rx   r1  )r   r   add_delete_linenumr  rL  r  r  r+   s           r,   fix_e305FixPEP8.fix_e305  sF   VF^%9%9%;B%?!@@!#!!$%7!8*v{{{6*0022*,DKK'"))!f*51HC! *v{,  BA:{{6*1137c>!  aKF"${{6':":DKK!!!f*-r.   c                 >   US   S-
  nU R                   U   nUS   S-
  nUR                  5       R                  S5      (       d  / $ [        R                  " SUSS9S   nUSU R                  S	5      S
-   U-   S-   X4S R                  S	5      -   nX`R                   U'   g)zPut imports on separate lines.r+   r   r   importz
\bimport\b)patternstringmaxsplitr   Nz	 ,r
   r   )r   r1  rS   rer0  r}   )r   r   r   r   rL  r  rT  s          r,   fix_e401FixPEP8.fix_e401  s    F^a'
Z(!A%}}))(33Ihh}&,q::;=''/$6()+1'?+A+A&+IJ"'Jr.   c                    [        UU R                  5      u  p#n[        SS5       H>  nSR                  U R                  X"U-    5      n [	        SR                  U5      5          O   X@R                  ;   a  U R                  U   U:w  d5  [        U R                  U5      nWU R                  U   -   U R                  U'   [        W5       H  nSU R                  X#-   '   M     g ! [
        [        R                  4 a     M  f = f)Nr   d   r2   )
get_index_offset_contentsr   r{   r   rZ  rK   rm   r   r   !get_module_imports_on_top_of_file)r   r   r   rL  r   r   r+   
mod_offsets           r,   fix_e402FixPEP8.fix_e402  s    '@AE(N$Vq#A774;;zQ,?@D.   ,,&4<<+?:+M:4;;;EGJ&*T[[-D&DDKK
#AhF-/DKK
)*   !4!45 s   
C##D Dc                    U(       aI  [        US   5      S:X  d7  U R                  US   S-
     R                  5       R                  S5      (       a  U R	                  U5      $ US   S   nUS   S   nUS   n[        U R                  US-
  SS9n[        U R                  US-   SS9n[        SR                  U5      5      n U R                  UUUSR                  U5      S9n	U	(       aD  [        X4S-   5       H  n
SU R                  U
'   M     XR                  U'   [        US-   US-   5      $ / $ ! [        [        R                  4 a    U R	                  U5      s $ f = f)	:Try to make lines fit within --max-line-length characters.r   r   r+   r5  r   r2   defaultr   previous_line	next_lineoriginal)ry   r   r1  rS   r   get_itemjoin_logical_liner   fix_long_linerK   rm   r   r{   )r   r   r  start_line_indexend_line_indexlogical_linesr  r  single_linerT  r   s              r,   r   FixPEP8.fix_long_line_logically  si    
Oq KKv*+224??DD0088"1:a= A
 .>.BBOT[[.1*<bI	'(>?	9&&"+#/	 ' 1E #$4q6HI
*,J' J,1KK())A-~/ABB	 X001 	90088	9s   !D0 0+EEc                 4   US   S-
  nU R                   U   n[        U R                   US-
  SS9n[        U R                   US-   SS9n U R                  UUUUS9nU(       a  X`R                   U'   US-   /$ / $ ! [        [        R
                  4 a    / s $ f = f)r  r+   r   r2   r  r  )r   r  r  rK   rm   r   )r   r   r   r   r  r  rT  s          r,   r    FixPEP8.fix_long_line_physically  s    F^a'
Z( j1nbIT[[*q."E		&&+#	 ' !E &+KK
#N##	 X001 	I	s   	A8 8BBc                 n   XU4nXPR                   ;   a  / $ UR                  5       R                  S5      (       a^  U R                  R                  (       aA  [        UU R                  R                  UR                  5       R                  S5      (       + S9$ / $ [        UUUU R                  U R                  R                  U R                  R                  U R                  R                  U R                  R                  S9nU(       a  [        XF5      (       d  U$ U R                   R                  U5        g )Nr5  )r+   r  last_comment)r   r  r  r   r  r   r   r  )r   r1  rS   r   r   shorten_commentr  get_fixed_long_liner   r   r  code_almost_equalr
  )r   r   r  r  r  cache_entryrT  s          r,   r  FixPEP8.fix_long_line$  s    i8555I==?%%c**||&&&$(LL$@$@%.%5%5%7%B%B3%G!GI I I#'(( LL88||..22LL((* *8;;L##''4r.   c                 x    [        UU R                  5      u  p#nUR                  S5      S-   U R                  U'   g)z$Remove extraneous escape of newline.ri  r
   N)r  r   r}   )r   r   r   r)   r   s        r,   fix_e502FixPEP8.fix_e502C  s7    ";F<@KK#I"(--"<t"CJr.   c                     US   S-
  nU R                   U   nUS   nUSU S-   [        U5      -   U R                  -   X4S R                  S5      -   nXPR                   US   S-
  '   US   US   S-   /$ )z9Put colon-separated compound statement on separate lines.r+   r   r   Nr
   ri  )r   r9  r   r1  )r   r   r   r   rk  fixed_sources         r,   fix_e701FixPEP8.fix_e701I  s    F^a'
Z(8r
T)(01373C3CDr
))+67 +7F6NQ&'vv 233r.   c                 ~   U(       d  / $ US   nU H  nUS   S:X  d  M  SU;   d  M  [         R                  R                  U5      (       d  M<  U R                  R                  (       a(  [        SR                  US   S9[        R                  S9  / s  $    US   S	-
  nU R                  U   nUR                  5       R                  S
5      (       aX  UR                  S5      U R                  U'   U R                  US	-      R                  5       U R                  US	-   '   US	-   US-   /$ UR                  5       R                  S5      (       a'  UR                  S5      S-   U R                  U'   US	-   /$ US   S	-
  nUSU R                  S5      R                  5       n[        US   5      XgS R                  S5      R                  5       -   n	Sn
XgS R                  S5      R                  5       SS S:X  a  XgS R                  S5      n
U
(       a  X-   U R                  U'   OUS-   U	-   U R                  U'   US	-   /$ )z=Put semicolon-separated compound statement on separate lines.r   r   E702r^   z8---> avoid fixing {error} with other compound statements)r   r   r+   r   r  z
 	\;z
 	;r
   r   Nr   r~  )r    !STARTSWITH_INDENT_STATEMENT_REGEXrE   r   r  r  rU   r  r	  r   r}   rk   r1  r9  )r   r   r  r  r+   r   r   rL  firstsecondinline_comments              r,   r   FixPEP8.fix_e702U  s   I
 "Dt&4KAAGGMM<<''44:FF4N ZZ
 	 " F^a'
Z(==?##D))&,mmK&@DKK
#*.++j1n*E*L*L*NDKK
Q'NJN33==?##C((&,mmJ&?$&FDKK
#N##!A%w&&s+224"=#34/((-4467 '?!!#&--/3t;#G_33C8N&+&<DKK
#&+dlV&;DKK
#Qr.   c                 8   [        UU R                  5      u  p#n[        R                  U5      nU(       ae  SR	                  UR                  S5      [        U5      U R                  -   XER                  S5      S R                  5       5      U R                  U'   gg)z'Fix multiple statements on one line defz{}
{}{}r   N)
r  r   STARTSWITH_DEF_REGEXrE   rU   groupr9  r   r   r1  r   r   r   r)   r   rE   s         r,   fix_e704FixPEP8.fix_e704  s    ";F<@KK#I$**62&0&7&7A (4+;+;;yy|}%,,.'0DKK
# r.   c                 T   [        UU R                  5      u  p#nUS-   nU[        U5      :  a  / $ USU R                  5       nXCU nXES R	                  5       nUR                  5       S:X  a  Sn	OUR                  5       S:X  a  Sn	O/ $ SR                  XiU/5      U R                  U'   g)zFix comparison with None.r   N==is!=is notr.  )r  r   ry   r}   r1  r  r   )
r   r   r   rL  r   right_offsetleftcenterright
new_centers
             r,   fix_e711FixPEP8.fix_e711  s    '@AE(N$V z3v;&Igv%%'|,}%,,.<<>T!J\\^t#!JI"%((De+D"EJr.   c                 @   [        UU R                  5      u  p#n[        R                  " SU5      (       a%  [        R                  " SSUSS9U R                  U'   g	[        R                  " SU5      (       a%  [        R                  " SSUSS9U R                  U'   g	US-   nU[        U5      :  a  / $ US	U R                  5       nXCU nXES	 R                  5       nS	n	UR                  5       S
:X  a4  [        R                  " SU5      (       a  [        R                  " SSUSS9n	OGUR                  5       S:X  a3  [        R                  " SU5      (       a  [        R                  " SSUSS9n	U	c  / $ U	S   R                  5       (       a  SU	-   n	Xi-   U R                  U'   g	)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 *r2   r  z	\bFalse\bz\bFalse\b *r   r.  )
r  r   r  rE   subry   r}   r1  r  isalnum)
r   r   r   rL  r   r  r  r  r  	new_rights
             r,   fix_e712FixPEP8.fix_e712  sx   '@AE(N$V 886??&(ff-L-:F!'MDKK
#XX7@@&(ff-K-:F!'MDKK
# "A:Ls6{*	'6?))+D<0F=)002E I||~%88K// "}b%q II4'88L%00 "~r5 JI 	|##%%)O	&*&6DKK
#r.   c           	         [        UU R                  5      u  p#nUSU nXCS n[        R                  U5      nSu  pxU(       a9  UR	                  S5      nUR                  5       nSR                  USU SXHS 5      n[        R                  U5      n	U	(       a  U	R                  S5      S:X  a  U	R	                  S5      n
SR                  USU
 U	R                  S5      U	R                  S5      U	R                  S5      XIR                  5       S U5      nU(       a#  Xs-   n
X-   S	-
  nSR                  USU
 S
XS 5      nXR                  U'   ggg)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_THROUGHr@   r   r   rU   COMPARE_NEGATIVE_REGEXr  )r   r   r   rL  r   before_targetmatch_notinnotin_pos_startnotin_pos_endrE   	pos_start
new_targetpos_ends                r,   fix_e713FixPEP8.fix_e713  s\   '@AE(N$V w4;;FC)-&)//2O'OO-M%%'($~0FHF '--f5{{1~%!KKN	4;;:I&AAKKNF99;<$8-I
  / 8I+4q8G!*!1!1":I.*X:N"PJ*4J' & r.   c           	         [        UU R                  5      u  p#nUSU nXCS n[        R                  U5      nSu  pxU(       a9  UR	                  S5      nUR                  5       nSR                  USU SXHS 5      n[        R                  U5      n	U	(       a  U	R                  S5      R                  S5      (       a  U	R	                  S5      n
SR                  USU
 U	R                  S	5      U	R                  S5      U	R                  S5      XIR                  5       S U5      nU(       a#  Xs-   n
X-   S
-
  nSR                  USU
 SXS 5      nXR                  U'   ggg)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   rU   r  r  rS   )r   r   r   rL  r   r  match_isnotisnot_pos_startisnot_pos_endrE   r  r  r  s                r,   fix_e714FixPEP8.fix_e714  se   '@AE(N$V w4;;FC)-&)//2O'OO-M%%'($~0FHF '--f5{{1~((..!KKN	4;;:I&AAKKNF99;<$8-I
  / 8I+4q8G!*!1!1":I.*X:N"PJ*4J' / r.   c                    [        UU R                  5      u  p#n[        R                  U5      nU(       Ga'  UR	                  5       nUR                  5       nSnSn	UR                  5       S   n
U
c  UR                  5       S   nOUR                  5       S   nXGS n	SnUR                  5       S   S:H  =(       d    UR                  5       S   S:H  nU(       a  S	nU S
USU  3n[        R                  " SU5      nSnU(       a  UR                  5       nUSU R                  5       n[        U5      S:  a=  U S
USU  3nU
b  SR                  USS 5      nU S
US    3nOSR                  U5      nXGS n[        R                  U5      nU(       aM  [        UR                  5       5      S:  a  UR                  5       nUUS n	UR                  5       S   nU S
U 3nO`[        R                  " SU5      nU(       aB  UR                  S5      nUR                  S5      nU S
U 3nUUR                  5       S nU U 3n	U U U SU SU	 3nUU R                  U'   gg)zfix comparison typer2   r   Nr   z isinstancer   r  r"   z not isinstance, z^\s+r.  r]   z^\s*([^\s:]+)(.*)$r   r  )r  r   COMPARE_TYPE_REGEXr@   r   r   rA   r  rE   r  r0  ry   r   
TYPE_REGEX)r   r   r   r)   r   rE   r   r   _prefix_suffixfirst_match_type_obj_target_objisinstance_stmtis_not_condition
_type_compindent_matchr   _prefix_tmp_suffix_tmp_suffix_type_matchtype_match_endcmp_b_else_suffix_match_else_suffix_else_suffix_other_else_suffix_endfix_lines                              r,   fix_e721FixPEP8.fix_e721  s   ";F<@KK#I"))&1 KKME))+CGG#(<<>!#4 #+#llnQ/#llnQ/ ,+Oq!T)FU\\^A->$-F   "3'=6&5>*:;J88GV4LF%++- %...0K;1$ +}Bvfu~.>?
'3!hh{3B'78G$/=;r?2C!DJ!hh{3G ,K!+!2!2;!?!{((*+q0%7%;%;%=N)./:G*113A6 +}Bug6
%'XX)&" &#5#;#;A#>L);)A)A!)D&$/=<.!AJ'23E3I3I3K3L'M$!3 45E4FGG (7)O#4Aj\7)L  '/DKK
# r.   c                     [        UU R                  5      u  p#n[        R                  U5      nU(       a:  SR	                  USUS   S-
   SXER                  5       S 5      U R                  U'   gg)zfix bare except{}{}{}Nr   r   zexcept BaseException:)r  r   BARE_EXCEPT_REGEXr@   rU   r   r  s         r,   fix_e722FixPEP8.fix_e722T  sp    ";F<@KK#I!((0&.oo,x(1,-/Fyy{|$'&DKK
# r.   c                 R   [        UU R                  5      u  p#n[        R                  U5      nU(       ar  UR	                  5       nSR                  USUR                  S5       UR                  S5      UR                  S5      XFS R                  5       5      U R                  U'   gg)z,Fix do not assign a lambda expression check.z{}def {}({}): return {}Nr   r   r   )	r  r   LAMBDA_REGEXr@   r   rU   r   r  r1  )r   r   r   r)   r   rE   r   s          r,   fix_e731FixPEP8.fix_e731^  s    ";F<@KK#I##F+))+C&?&F&FA'QQt##%''DKK
# r.   c                 z    U R                   US   S-
     R                  5       nUS-   U R                   US   S-
  '   g)zRemove trailing whitespace.r+   r   r
   N)r   r}   )r   r   
fixed_lines      r,   r   FixPEP8.fix_w291i  s>    [[!!34;;=
*4t*;F6NQ&'r.   c                     Sn[        U R                  5       H!  nUR                  5       nU(       a    O	US-  nM#     [        U R                  5      nU R                  SXB-
   U l        [	        SSU-   5      $ )zRemove trailing blank lines.r   r   N)rr   r   r}   ry   r{   )r   r)   blank_countr+   original_lengths        r,   fix_w391FixPEP8.fix_w391n  sm    T[[)D;;=Dq  * dkk*kk"@?#@AQO+,,r.   c                    [        UU R                  5      u  p#nUR                  5       S   n [        U5      n[        US   S   U5      (       d  g SnSnSn	[        S5       GH  n
X*-
  S:  a    GO~X*-
  S-
  nUS:  d  [        U R                  5      U::  a    GOUUS-   nU R                  U   R                  5       nU(       d  U(       a  US   S:X  a  U	S-  n	Mx  Sn [        SR                  U R                  X 5      5      nSn/ n[        U5       HE  u  nnUS   [
        R                  [
        R                  4;   d  M/  UR                  U5        US-  nMG     US:  a  XoS	   S  nOUn/ nU Hx  nUS   [
        R                  [
        R                  4;   a  US-  nUS::  a    OE[
        R                   US   :X  a(  U(       a!  US   [
        R                  :w  a
  US
   S   n  OUnMz       O   UR#                  U5      n
US-
  U	-
  nSR%                  US U
 XJ[        U5      -   S  R                  5       5      U R                  U'   ['        U R                  UU 5      nU R                  U   nUR#                  U5      nU(       a*  SR%                  US U UUUS-   S  5      U R                  U'   g US U R)                  S5      (       a-  SR%                  US US-
   UUUS-
  S  5      U R                  U'   g SR%                  US U UUUS  5      U R                  U'   g ! [        [
        R                  4 a     g f = f! [        [
        R                  4 a     GM  f = f)Nr   F   r   r5  Tr2   r   r"   {}{}z{} {} {}r  z{} {}{})r  r   r0  rZ  rK   rm   r   _is_binary_operatorr{   ry   r1  r   r>   ro   rn   rx   ru   rv  rU   find_newlinerk   )r   r   r   r)   r   one_string_tokenr`  comment_indexfound_not_comment_only_linecomment_only_linenumr   
from_indexto_index
strip_linenewline_countnewline_indexrv  tttsoldfix_target_linenlbefore_linebls                           r,   fix_w503FixPEP8.fix_w503|  s   ";F<@KK#I!<<>!,	 !12B #2a58-=>>&+# qA!##!+JA~T[[!1Z!?!A~HZ0779J/z!}3$)$*.'$RWWT[[-M%NO MM%bMqQ4H,,hkk::!((/!Q&M * q r*+,CQ4H,,hkk::!Q&M A%##qt+A(++8M$'F1IM  Q R LL)*$q.+??"(--2AJ3'7#889:AAC#EJ$++ojABkk/2r"+5+<+<N]+-=MA-./,1DKK( 3B((-- 09/?/?A&(8+bde:L0NO, 09/?/?$&6BC8H0JO,G X001 		4  !4!45 s#   L &L<L98L9<MMc                 ~   [        UU R                  5      u  p#nSnS n[        SS5       GH^  nX'-   n [        SR	                  U R                  X( 5      5      n	Sn
/ n[        U	5       H  u  p[        US   US   5      (       a.  US   S   S:X  a   US   S   S:X  a  US   S   US   S   4nMF  MH  MJ  US   [        R                  :X  a7  US   S;   a.  US   S   S:X  a   US   S   S:X  a  US   S   US   S   4nM  M  M  US   [        R                  [        R                  4;   d  M  UR                  U5        U
S-  n
M     U
S:  a	  U	S US    nOU	n/ nU H-  n[        R                  US   :X  a  U(       a
  US   u  nn  OUnM/       O   U(       d  g XFS   US    nU(       a<  WS:X  a6  S	R                  US US    R!                  5       XES  5      U R                  U'   OLS
R                  US US    R!                  5       XFS   S  R#                  5       XFS   S  5      U R                  U'   U R                  US-      nSn[$        R&                  " SU5      nU(       a  UR)                  5       S   nSR                  US U UUUS  5      U R                  US-   '   g ! [
        [        R                  4 a     GM  f = f)Nr   r      r2   r   r"   andorr*  r+  r  z\s*r  )r  r   r{   rZ  r   rK   rm   r   r>   r,  NAMEro   rn   rx   ru   rU   r}   r1  r  rE   span)r   r   r   r)   r   r/  operator_positionr   r3  r`  r5  r6  rv  r7  r8  r9  comment_rowtarget_operatorr  next_line_indentms                        r,   fix_w504FixPEP8.fix_w504  s   ";F<@KK#I  q!A!~H$RWWT[[-M%NO MM%bM&qtQqT22tAw!|!Q1-.qT!Wad1g,>) )5|qTX]]*qt}/DtAw!|!Q1-.qT!Wad1g,>) )5|qTh..<<!((/!Q&M * q +-+,C##qt+14Q.K	 
 9 : ! 1!56G6JK[A-&,mm,)!,-446~&'(DKK
# '/oo,)!,-446+,-446+,-'/DKK
#
 KK
Q/	HHVY' vvx{&/&6&6''(/&'('*JN#Y  !4!45 s   &JJ<;J<c                     [        UU R                  5      u  p#nSR                  US US-    XCS-   S  5      U R                  U'   g )Nz{}\{}r   )r  r   rU   )r   r   r   rL  r   s        r,   fix_w605FixPEP8.fix_w605  sK    '@AE(N$V"*//;FQJ
!4#6Jr.   )(r9   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   NN)5r&   
__module____qualname____firstlineno____doc__r   boolr   r  r  r   r   r<  r?  rB  rG  r   r   r   r   rf  rl  r   r{  r  r   r   r  r  r  r  r  r  r   r   r  r  r  r   r  r  r  r  r  r  r  r  r   r&  r>  rL  rO  __static_attributes__ru  r.   r,   r   r     s   %R (,?&B)$ )E+N"$H
L	<888$G(
(0#J(06
00$0,O
	
&#B(0"!F.>D
41 f	0F,$7L5@5>D/L&	'<
-JJX8*t6r.   r   c                   ^^ S nS mU4S jnSnSnSn[        [        U 5      5      nU GH  u  nmU(       dq  [        R                  TR	                  5       5      n	U	bK  SnU	R                  S	5      nTU	R                  5       U	R                   R                  5       n
U
S
S U:X  a  SnM  U(       a  TR                  5       S
S U:X  a  SnM  TR                  5       (       d  M  TR                  S5      (       a  M  TR                  S5      (       a  X:X  a  M  Us  $ TR                  S5      (       a>  X:X  a  GM  U" [        R                  " UT4/U5      5      u  pU(       a	  X-   S-   s  $ Us  $ [        R                  R                  T5      (       a  Us  $ [        U4S jU 5       5      (       a  GM  U" T5      (       a  Us  $ Us  $    g)zrreturn import or from keyword position

example:
  > 0: import sys
    1: import os
    2:
    3: def function():
c                     U S   S;   a  U SS  n U (       a  U S   S;   a  U SS  n U =(       a    U S   S:H  =(       d    U S   S:H  $ )Nr   uUbBr   rR"'ru  r+   s    r,   is_string_literal<get_module_imports_on_top_of_file.<locals>.is_string_literal  sQ    7f8DDGtO8D:aC947c>:r.   c                     [         R                  " U 5      nUR                   H6  n[        U[         R                  5      (       d  M$  UR
                  S:X  d  M6    g   g)N
__future__TF)astparsebody
isinstance
ImportFrommodule)r+   nodesr  s      r,   is_future_import;get_module_imports_on_top_of_file.<locals>.is_future_import  sA    		$A!S^^,,\1I  r.   c                    > SnSnU  HA  u  p4UR                  5       R                  S5       H  nX%-   n T" U5      U4s  s  $    US-  nMC     SU4$ ! [         a     M2  f = f)Nr   r2   Tr   F)r  
splitlinesrK   )r   rL  r+   r)   r  	line_partrj  s         r,   has_future_import<get_module_imports_on_top_of_file.<locals>.has_future_import   s~    "LA&__.99$?	'+D1699 @ aKF # f} # s   	A
AA)tryexceptelsefinallyF"""NTkindr*  r5  r   r   r   c              3   F   >#    U  H  nTR                  U5      v   M     g 7fNrS   )r"  kwr+   s     r,   r$  4get_module_imports_on_top_of_file.<locals>.<genexpr>U  s     D/C$$/C   !r   )iterr>   DOCSTRING_START_REGEXrE   r1  r  r   endposr}   rS   	itertoolschainr    DUNDER_REGEXany)r   import_line_indexr_  ro  allowed_try_keywordsin_docstringdocstring_kindsource_streamr  rK  remainhitrL  rj  r+   s                @@r,   r  r  	  s   ; @LN6*+M"	T%++DKKM:A}#!"aeegqxx0779"#;.0#(L{{}RS!^3${{}}__S!!??9%%'J__W%%'+#t}=KC |a''J%%++D11JD/CDDDt$$JJS #T r.   c                 ,    U S   S-
  nUU S   S-
  X   4$ )z2Return (line_index, column_offset, line_contents).r+   r   r   ru  )r   r   r   s      r,   r  r  ^  s0    !#J8q    r.   c                 *  ^^^ [        U 5      nU [        U5      S n	U	R                  5       U	:X  d   eU R                  5       R                  S5      (       a   e[	        [        U	5      5      n
[        XUTTUTUS9n[        [        [        U5      R                  X/5      5      UUU4S jS9nUS:  a9  [        SR                  S/U-   S/-   5      [        [        R                  S	5      S
9  U(       a   US   n[        U5      [        U5      :  a  gU$ g)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.

Nr5  )r   r   r  c                    > [        U TTTS9$ )N)r   )line_shortening_rank)xr   r   r  s    r,   <lambda>%get_fixed_long_line.<locals>.<lambda>  s    *%	'r.   r   r   zP-------------------------------------------------------------------------------
r2   r=   r   r   )r9  ry   r1  rS   r|   rZ  shorten_liner   r   unionr  r   wrap_outputr  r	  longest_line_length)r   r  r  r   r  r   r   r  r   r   r~   
candidatesbest_candidates      `` `      r,   r  r  f  s    f%FCKL!F==?f$$$}}))#.... /&)*F!#%J s:$$f%789'(J !|$$bTJ%6"%=>szz73	5 #A ~.1DX1NN r.   c                 b    [        U 5      S:X  a  g[        S U R                  5        5       5      $ )zReturn length of longest line.r   c              3   8   #    U  H  n[        U5      v   M     g 7frx  ry   r"  r+   s     r,   r$  &longest_line_length.<locals>.<genexpr>  s     7%6Ts4yy%6   )ry   r  rm  rp  s    r,   r  r    s(    
4yA~7T__%6777r.   c                 h    [        U 5      nU[        [        U R                  5       5      5      -   S-   $ )z/Return single line based on logical line input.r
   )r9  untokenize_without_newlinesrZ  r1  )rV   r  s     r,   r  r    s:    "<0K4++-.0 0267 7r.   c                     SnSnSnU  HQ  nUS   nUS   u  pgUS   u  pXb:  a  SnXs:  d  US:X  a  UR                  S5      (       d  US-  nUS:w  a  X-  nUnU	nMS     UR                  5       $ )	z#Return source code based on tokens.r2   r   r]   r   r   r"   r
   r.  )rk   r}   )
r~   r   last_rowlast_columnr7  token_string	start_rowstart_columnend_row
end_columns
             r,   r  r    s    DHKt$%aD! !!K'<4+?c""CKD4 D # & ;;=r.   c                    / n/ nSnSn[        SR                  U 5      5       GH  nUS   [        R                  [        R                  [        R
                  [        R                  [        R                  4;   a  MZ  U(       dM  US   [        R                  [        R                  4;   a&  SnUR                  US   S   S-
  US   S   45        M  U(       a+  U(       d$  UR                  US   S   S-
  US   S   45        SnUS   [        R                  :X  d  M  US   S;   a  US-  nGM
  US   S	;   d  GM  US-  nGM     X4$ )
NTr   r2   r"   r   r   Frj   }]))rZ  r   rm   ru   DEDENTINDENTrn   	ENDMARKERro   SEMIrx   rq   )source_linesr  r  last_newliner   r7  s         r,   r   r     s(   MKLFRWW\23Q4H$$hooOOX[[&&( ( !A$8#3#3X]]"CCL!Q!QqT!W56  !A$q'A+qtAw!78 LQ48;;tu}!1!! 4" ''r.   c                     US   S-
  nUS   S-
  nSnSn[        S[        U5      S5       H5  nU(       d   eX8   n	U	S   U:  d  U	S   U:X  d  M$  U	S   U:  d  M/  U	nX(   n  O   Uc  gXS   US   S-    n
XgU
4$ )z\Return the logical line corresponding to the result.

Assumes input is already E702-clean.

r+   r   r   Nr   )r{   ry   )r  r   r  r  r   collsler   r  r  s              r,   r  r    s     .1
C

Q
C	B	B1c-(!,{NQ4#:!A$#+!A$*B!B - 
zqE"Q%!),H8r.   c                 B    SUs=::  a  [        U 5      :  a   X   $   U$ U$ Nr   r  )itemsrv  r  s      r,   r  r    s+    ECJ|  N7Nr.   c                 :    [        X5      nUR                  U5      $ )zReindent all lines.)
Reindenterrun)r   indent_size
leave_tabs
reindenters       r,   reindentr    s    F/J>>+&&r.   c                    [        U 5      n[        U5      n[        U5      [        U5      :w  a  g[        U5       HK  u  pESR                  X$   R	                  5       5      SR                  X4   R	                  5       5      :w  d  MK    g   g)zRReturn True if code is similar.

Ignore whitespace when comparing specific line.

Fr2   T)split_and_strip_non_empty_linesry   r>   r   r0  )arg   split_asplit_brv  r)   s         r,   r  r    st     .a0G-a0G
7|s7|#(
777>'')*bgggn6J6J6L.MM ) r.   c                     U R                  5        Vs/ s H)  oR                  5       (       d  M  UR                  5       PM+     sn$ s  snf )z5Return lines split by newline.

Ignore empty lines.

)rm  r  )r   r+   s     r,   r  r    s3     &*__%6G%6T**,LDJJL%6GGGs
   AAc                    [        U [        5      (       a   e[        R                  " [        5      nU  H  nUR                  [        5      (       a  U[        ==   S-  ss'   M0  UR                  [        5      (       a  U[        ==   S-  ss'   M]  UR                  [        5      (       d  My  U[        ==   S-  ss'   M     [        XR                  SS9=(       d    [        /S   $ )zCReturn type of newline used in source.

Input is a list of lines.

r   T)r   reverser   )rf  rt   collectionsdefaultdictr/  rk   CRLFCRLFr   rs   )r   counterr+   s      r,   r-  r-    s     &#&&&&%%c*G==DMQM]]2BK1K]]2BK1K  7T:BrdAFFr.   c                     Sn [        U 5       H"  nUS   [        R                  :X  d  M  US   n  U$     U$ ! [        [        R
                  4 a     U$ f = f)zReturn indentation type.    r   r   )rZ  tokenr  rK   rm   r   )r   r   r7  s      r,   r   r   /  sl    K (Atu||#d  )  ,,- s   #8 8 8 AAc                     U R                  5       (       a*  [        U 5      [        U R                  5       5      -
  nU SU $ g)zReturn leading whitespace.Nr2   )r  ry   r1  )r+   non_whitespace_indexs     r,   r9  r9  <  s9    zz||"4y3t{{}+==))**r.   c                     Sn[         R                  " XSU-   SU-   US9nSnU H2  nXV-  nU(       d  M  UR                  U5      (       a  M(  XSS-   U-   -  nM4     U$ )z0Return text of unified diff between old and new.r
   z	original/zfixed/)linetermr2   z\ No newline at end of file)difflibunified_diffrk   )r9  newr9   r5   diffr   r+   s          r,   get_diff_textr  E  st    Gh8	D D 4g..<<wFFD  Kr.   c                     / SQnSnS/nU S   R                  5       n UR                  U5      $ ! [         a.     X#R                  U5      -   S-   s $ ! [         a    Us s $ f = ff = f)zrKey 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   rv  
ValueError)pep8_resultprioritymiddle_indexlowest_priorityr   s        r,   r   r   Y  s    H L 	O
 d

!
!
#C ~~c""  	 "7"7"<<q@@ 	 	  s,   / 
A'AA'A#A'"A##A'c           
   #      #    [        U UUUUUS9 H  nUv   M	     U(       a+  [         H!  n	[        U UUUU	US9n
U
c  M  X:w  d  M  U
v   M#     U(       a  [        U UUUS9 H  n
U
v   M	     gg7f)zBSeparate 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              r,   r  r  |  s      #&*0/:/:.81>@	 @ !8/''"3%'I $)< "9 4' /	1I O1 s   9A.A.(A.c              #     #    Sn[        U 5       GH  u  nnn	n
[        (       a-  U[        R                  :X  a  SnOU[        R                  :X  a  SnU(       a  MJ  U[        R
                  :X  a  [        U5      (       d  [        U5      (       dp  XS-   S R                  5       R                  5       R                  S5      (       d9  USU	 nXS nX,R                  5       -   S-   U-   UR                  5       -   S-   v   M  U[        R                  :X  d  GM  US:w  d  GM  U[        R                  :w  d   eUSU
 nUnUR                  5       R                  S5      (       a'  XS R                  5       R                  S	5      (       a  ONUR                  5       R                  S5      (       a  X-  nO%SU;   a  US
SUR!                  S5      -   -  -  nOX-  nXU
S R                  5       -   nUR                  5       (       a$  UR                  5       R                  S5      (       a  GM  UR                  5       R                  S5      (       a  GM<  UR                  5       R                  S5      (       a  GMc  US;   a  US-   S-   U-   nOUS-   U-   n[#        U(       a  [%        U5      OU5      (       d  GM  X.-   v   GM     g7f)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.

FTr   N)r   zpragma:zpylint:r
   =r   r  r.  r5  r   .z+-*/z \)token_offsetsIS_SUPPORT_TOKEN_FSTRINGrm   FSTRING_STARTFSTRING_ENDru   is_probably_part_of_multiliner  r   rS   r  rq   r  r}   rk   r1  r   r[  normalize_multiline)r~   r   r  r   r   r  	in_stringr   r  start_offset
end_offsetr  r  second_indentrT  s                  r,   r  r    s     I &f-				##X333 	x333!	 (***-m<<-f55a'()//1779DD.0 0 =L)EM*F/$6!&/156 7588#(; ---;J'E'M'',,;'..0;;C@@((--,EJJsO(;!<<,#Z[&9&@&@&BBFLLNN**3// }}))#..||~&&s++v%,v5v- ) 06/46 6!)){ .s   DJ>J>FJ>2J>c                 X    U [         R                  :H  =(       d    US;   =(       a    US;  $ )NrB  z()[]{},:.;@=%~)rm   rq   )r   r   s     r,   r,  r,    s+    8;;&?$-*? )((*r.   Token)r   r  sposeposr+   c                       \ rS rSrSr " S S\5      r " S S\5      r " S S\5      rS	 r	S
 r
S rS rS rS rS rSS jrS rS rS rS rS rS rS rS rS rS rS rSrg)ReformattedLinesi  zThe 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    \ rS rSrSrS rS r\S 5       rSr	g)ReformattedLines._Indenti  z,Represent an indentation in the atom stream.c                     Xl         g rx  _indent_amtr   
indent_amts     r,   r   !ReformattedLines._Indent.__init__
  s    )r.   c                      SU R                   -  $ Nr.  r  r   s    r,   emitReformattedLines._Indent.emit  s    ))))r.   c                     U R                   $ rx  r  r  s    r,   sizeReformattedLines._Indent.size  s    ###r.   r  N)
r&   rR  rS  rT  rU  r   r  propertyr  rW  ru  r.   r,   _Indentr    s#    :	*	* 
	$ 
	$r.   r  c                   .    \ rS rSrSrS r\S 5       rSrg)ReformattedLines._Spacei  z%Represent a space in the atom stream.c                     gr
  ru  r  s    r,   r  ReformattedLines._Space.emit  s    r.   c                     gNr   ru  r  s    r,   r  ReformattedLines._Space.size      r.   ru  N	r&   rR  rS  rT  rU  r  r  r  rW  ru  r.   r,   _Spacer    s    3	 
	 
	r.   r  c                   .    \ rS rSrSrS r\S 5       rSrg)ReformattedLines._LineBreaki  z*Represent a line break in the atom stream.c                     g)Nr
   ru  r  s    r,   r   ReformattedLines._LineBreak.emit#  s    r.   c                     gr  ru  r  s    r,   r   ReformattedLines._LineBreak.size&  r  r.   ru  Nr  ru  r.   r,   
_LineBreakr    s    8	 
	 
	r.   r#  c                 V    Xl         / U l        SU l        S U l        S U l        SU l        g )Nr   F)_max_line_length_lines_bracket_depth
_prev_item_prev_prev_item_in_fstring)r   r  s     r,   r   ReformattedLines.__init__*  s.     /# r.   c                 "    U R                  5       $ rx  )r  r  s    r,   __repr__ReformattedLines.__repr__2  s    yy{r.   c                 v    [        U[        5      (       a  U R                  X5        g U R                  XU5        g rx  )rf  Atom	_add_item_add_container)r   objr  break_after_open_brackets       r,   r
  ReformattedLines.add8  s/    c4  NN3+C-EFr.   c                    Sn[        U R                  5      S:  as  [        U R                  S   U R                  5      (       a  US-  n[        U R                  5      S:  a-  [        U R                  S   U R                  5      (       a  US-  nUS:  a6  U R                  R	                  U R                  5       5        US-  nUS:  a  M6  U R                  R	                  U5        g )Nr   r   r]   r   )ry   r&  rf  r  rx   )r   item
num_spacess      r,   add_commentReformattedLines.add_comment?  s    
t{{a$++b/4;;77a
4;;!#dkk"ot{{;;!OJ1nKKt{{}-!OJ 1n 	4 r.   c                 X    U R                   R                  U R                  U5      5        g rx  )r&  rx   r  r  s     r,   
add_indentReformattedLines.add_indentM  s    4<<
34r.   c                     U R                   R                  U R                  5       5        U R                  [	        U5      5        g rx  )r&  rx   r#  r=  ry   )r   r   s     r,   add_line_breakReformattedLines.add_line_breakP  s+    4??,-F$r.   c                     U R                   R                  XR                  5       5        U R                   R                  US-   U R                  U5      5        g r  )r&  insertr#  r  )r   rv  r  s      r,   add_line_break_at"ReformattedLines.add_line_break_atT  s<    5//"34519dll:&>?r.   c                    U R                   (       a?  [        U R                   S   U R                  U R                  U R                  45      (       a  g [        U R                  5      nU R                  (       a  [        U R                  5      OSnU R                  R                  (       dQ  U R                  R                  (       d6  U R                  R                  (       d  U R                  R                  (       a  US   S;  d  US   S:X  a  U(       d  US:w  a  US   S:w  a  US:w  a  US   S	:w  a  US   S
;   a	  US   S;  d  US   S;   d{  U(       a  US:X  dn  U R                  (       a  US;  a  U R                  R                  (       d6  U R                  R                  (       d  U R                  R                  (       a1  US;   a*  U R                   R                  U R	                  5       5        g g g g g g g g g )Nr]   r2   r   z	([{.,:}])r  fromr  r  r^   r  z.,}])z:,z+-)r   r   r   r   r   r   z**r  )r&  rf  r#  r  r  rt   r(  r)  
is_keyword	is_stringis_name	is_numberrx   )r   	curr_textequal	prev_textprev_prev_texts        r,   add_space_if_needed$ReformattedLines.add_space_if_neededX  s   zB$//4<<!M O  O (	)-)=)=C$$%2 	 oo((DOO,E,Eoo%%)B)Bl+-|s"u &9R=C+?8# q\S  }%)A,g*E mt# c) $$$&&&..&&00&&00HHKKt{{}- I 1 ' % ! $ ,@&r.   c                     U R                   $ )z(Return the previous non-whitespace item.)r(  r  s    r,   previous_itemReformattedLines.previous_item  s    r.   c                 B    U R                  5       U-   U R                  :*  $ rx  )current_sizer%  )r   item_extents     r,   fits_on_current_line%ReformattedLines.fits_on_current_line  s!      "[0D4I4IIIr.   c                     Sn[        U R                  5       H.  nXR                  -  n[        X R                  5      (       d  M-    U$    U$ )z3The size of the current line minus the indentation.r   )rr   r&  r  rf  r#  )r   r  r8  s      r,   rV  ReformattedLines.current_size  sD    T[[)DIID$00 *
 r.   c                     U R                   =(       a/    [        U R                   S   U R                  U R                  45      $ )Nr]   )r&  rf  r#  r  r  s    r,   
line_emptyReformattedLines.line_empty  s5     <4;;r? OOT\\:<	=r.   c                     SnU R                    H?  n[        X R                  5      (       a  UR                  5       nXR	                  5       -  nMA     UR                  5       S-   $ )Nr2   r
   )r&  rf  r#  r}   r  )r   r  r8  s      r,   r  ReformattedLines.emit  sP    KKD$00iik!F  
 }}%%r.   c                    UR                   (       a  SU l        O3U R                  (       a"  U R                  R                  (       a  SU l        U R                  (       a  U R                  R                  (       ad  UR                  (       aS  U R
                  R                  U R                  5       5        U R
                  R                  U R                  U5      5        [        U5      nU R
                  (       a:  U R                  (       a)  U R                  X5        US;   a  U R                  X5        OU R
                  (       a  U R                  5       (       d  U R                  [        U5      5      (       a  U R!                  U5        OSU R
                  R                  U R                  5       5        U R
                  R                  U R                  U5      5        U R
                  R                  U5        XR                  sU l        U l        US;   a'  U R                  (       d  U =R                  S-  sl
        gUS;   a:  U R                  (       d(  U =R                  S-  sl
        U R                  S:  d   eggg)	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.

TFz.,)]}rj   r   r  r   N)is_fstring_startr*  r(  is_fstring_endrI  r&  rx   r#  r  rt   r'  &_prevent_default_initializer_splitting_split_after_delimiterr]  rX  ry   _enforce_spacer)  )r   r8  r  	item_texts       r,   r1  ReformattedLines._add_item  s      #D__!?!?$D??t88T^^KKt01KKt||J78I	;;4..77IG#++D=[[!2!2((Y88##D) ""4??#45""4<<
#;<4 04oo--d&6&61$%(8(81$&&!+++ )9r.   c                    US-   n[        U R                  5      S:w  a  U R                  5       (       d  U R                  UR                  U R
                  -   S-   5      (       d  [        U5      S   S:X  a#  U R                  R                  (       a  SnUS-   nOU(       d  [        U R                  5      S;  aU  U R                  R                  U R                  5       5        U R                  R                  U R                  U5      5        S	nOU R                  5       S-   nS	n[        U[        [        45      (       a  UnUR                  U S
U-  US9  g )Nr   r  r   r   r   Tr   rj   Fr.  )r4  )rt   r(  r]  rX  r  r'  rJ  r&  rx   r#  r  rV  rf  ListComprehensionIfExpressionreflow)r   	containerr  r4  actual_indents        r,   r2  ReformattedLines._add_container  s'   "Q  C'!!))!4!44q8: : 9~a C'DOO,C,C+/( *Q(DOO$E1
 ""4??#45""4<<
#;<+0( --/!3M',$i"3\!BCC&M 	s]22J 	 	Lr.   c                    [        U5      S:X  a  U R                  5         gU R                  (       a*  U R                  (       a  [        U R                  5      S:w  a  gU R                  5         U R                  R                  U R                  5      n[        U R                  US-
     U R                  5      (       d#  U R                  UR                  S-   5      (       a  g[        U R                  US-
     U R                  5      (       a  U R                  US-
  	 U R                  U R                  R                  U R                  5      U5        g)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   )rt   _delete_whitespacer(  r)  r&  rv  rf  r  rX  r  r  rD  )r   r8  r  prev_prev_indexs       r,   rd  7ReformattedLines._prevent_default_initializer_splitting  s    t9 ##%t';';DOO$+!++++D,@,@A t{{?Q#67FF%%dii!m44  dkk/A"56DDOa/0t{{001E1EF)	+r.   c                    U R                  5         U R                  UR                  5      (       a  gSn[        U R                  5       Hx  nU(       a(  [        U[        5      (       a  UR                  (       d    OJSn[        X@R                  5      (       a  Un[        X@R                  U R                  45      (       d  Mx    g   U(       d  gU R                  U R                  R                  U5      U5        g)z&Split the line only after a delimiter.N)rq  rX  r  rr   r&  rf  r0  is_colonr  r#  r  rD  rv  )r   r8  r  
last_spacecurrent_items        r,   re  'ReformattedLines._split_after_delimiter!	  s    !$$TYY//
$T[[1Ld33!**!
,44)
,$,,(GHH 2 t{{00<jIr.   c                    [        U R                  S   U R                  U R                  U R                  45      (       a  gU R
                  (       d  g[        U5      n[        U R
                  5      nUS:X  a  US:X  d  US:X  a  US:X  d  US:X  a1  US:X  a*  U R                  R                  U R                  5       5        ggg)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  rG  r  r   )rf  r&  r  r#  r  r(  rt   rx   )r   r8  rg  rN  s       r,   rf  ReformattedLines._enforce_space<	  s     dkk"o{{DOOT\\BD DI	(	
 #)v"5("yC'7#)x"7KKt{{}- #8r.   c                     [        U R                  S   U R                  U R                  U R                  45      (       aO  U R                  S	 [        U R                  S   U R                  U R                  U R                  45      (       a  MN  gg)z/Delete all whitespace from the end of the line.r]   N)rf  r&  r  r#  r  r  s    r,   rq  #ReformattedLines._delete_whitespaceV	  sm    R4;;+/<<+9 : :B R4;;+/<<+9 : :r.   )r'  r*  r&  r%  r(  r)  NF)r&   rR  rS  rT  rU  objectr  r  r#  r   r-  r
  r:  r=  r@  rD  rP  rS  rX  rV  r]  r  r1  r2  rd  re  rf  rq  rW  ru  r.   r,   r   r     s    $& $	 		V 	!G!5%@,.\J=
&,,\"LH%+NJ6.4 r.   r   c                       \ rS rSrSrS rS rS r   SS jrS r	\
S 5       r\
S	 5       r\
S
 5       r\
S 5       r\
S 5       r\
S 5       r\
S 5       r\
S 5       r\
S 5       rSrg)r0  i]	  z3The smallest unbreakable unit that can be reflowed.c                     Xl         g rx  _atom)r   atoms     r,   r   Atom.__init__a	  s    
r.   c                 .    U R                   R                  $ rx  r  r  r  s    r,   r-  Atom.__repr__d	  s    zz&&&r.   c                     U R                   $ rx  )r  r  s    r,   __len__Atom.__len__g	  s    yyr.   c                    U R                   R                  [        R                  :X  a  UR	                  U 5        g U(       a  UOU R
                  nU R                   R                  S;  a  US-  nUR                  5       nU(       d  UR                  U5      (       d  U(       a#  UR                  U R
                  S-   5      (       d_  UR                  5       (       dJ  U R                  (       d9  U(       a   UR                  (       a  [        U 5      S:X  d  UR                  U5        OUR                  [        U 5      5        UR                  U [!        U5      U5        g )Nz,:([{}])r   r   )r  r   rm   ru   r:  r  r  rS  rX  r]  ru  rJ  rt   r@  rP  r
  ry   )	r   reflowed_linescontinued_indentextentr4  is_list_comp_or_if_exprnext_is_dot
total_size	prev_items	            r,   rl  Atom.reflowj	  s     ::  H$4$44&&t,%V499
::""*4!OJ"002	'33J??44TYY]CC))++y00Tc! ))*:;..s4y94%5!63	5r.   c                 "    U R                  5       $ rx  )r-  r  s    r,   r  	Atom.emit	  s    }}r.   c                 V    [         R                  " U R                  R                  5      $ rx  )keyword	iskeywordr  r  r  s    r,   rH  Atom.is_keyword	  s      !8!899r.   c                 P    U R                   R                  [        R                  :H  $ rx  )r  r   rm   rv   r  s    r,   rI  Atom.is_string	      zz$$77r.   c                 h    [         (       d  gU R                  R                  [        R                  :H  $ NF)r  r  r   rm   r  r  s    r,   rb  Atom.is_fstring_start	  s&    ''zz$$(>(>>>r.   c                 h    [         (       d  gU R                  R                  [        R                  :H  $ r  )r  r  r   rm   r  r  s    r,   rc  Atom.is_fstring_end	  s&    ''zz$$(<(<<<r.   c                 P    U R                   R                  [        R                  :H  $ rx  )r  r   rm   rE  r  s    r,   rJ  Atom.is_name	  s    zz$$55r.   c                 P    U R                   R                  [        R                  :H  $ rx  )r  r   rm   NUMBERr  s    r,   rK  Atom.is_number	  r  r.   c                 4    U R                   R                  S:H  $ )Nr   r  r  s    r,   is_commaAtom.is_comma	      zz&&#--r.   c                 4    U R                   R                  S:H  $ )Nr^   r  r  s    r,   ru  Atom.is_colon	  r  r.   c                 @    [        U R                  R                  5      $ rx  )ry   r  r  r  s    r,   r  	Atom.size	  s    4::**++r.   r  N)FFF)r&   rR  rS  rT  rU  r   r-  r  rl  r  r  rH  rI  rb  rc  rJ  rK  r  ru  r  rW  ru  r.   r,   r0  r0  ]	  s    ='
 "' %	"5H : : 8 8 ? ?
 = =
 6 6 8 8 . . . . , ,r.   r0  c                       \ rS rSrSrS rS rS rS r SS jr	S r
\S	 5       r\S
 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rSrg)	Containeri	  z#Base class for all container types.c                     Xl         g rx  _items)r   r  s     r,   r   Container.__init__	  s    r.   c                 h   SnSnU R                    H  nUR                  (       a  US-  nOwUR                  (       a  US-  nO`[        U5      nU(       aJ  U(       d>  UR	                  [        S5      5      (       d$  UR                  [        S5      5      (       d  US-  nX-  nUR                  nM     U$ )Nr2   Fr   r%   z
([{,.:}]) z	([{,.:}])r.  )r  r  ru  rt   rk   tuplerS   rH  )r   r  last_was_keywordr8  item_strings        r,   r-  Container.__repr__	  s     KKD}}$$!$i% //%*=>>%00{1CDDcMF%#!  " r.   c              #   :   #    U R                    H  nUv   M	     g 7frx  r  )r   elements     r,   __iter__Container.__iter__	  s     {{GM #s   c                      U R                   U   $ rx  r  )r   rD   s     r,   __getitem__Container.__getitem__	  s    {{3r.   c           
         Sn[        U R                  5       GHT  u  pV[        U R                  US-   5      n[        U[        5      (       ax  [        U [
        [        45      nUR                  XU R                  U5      UU=(       a    [        U5      S:H  S9  U(       a"  UR                  (       a  UR                  U5        SnO7UR                  U[        U5      U5        [        U[
        [        45      (       + nU(       a  US:X  a}  [        U5      U R                  :X  ad  U(       a  [        U5      U R                  :w  aD  [        U R                  5      S:w  d  [        U[        5      (       d  UR                  U5        SnGMm  [        U R                  US-   5      n	[        U5      S;  d  GM  U(       d  GM  [        U[         5      (       a  GM  [        U5      S	:w  d  GM  U	(       d  GM  [        U	[        5      (       a  [        U5      S
:X  d  GM  UR#                  5       (       a  GM  UR%                  U R                  US-   5      S-   5      (       a  GMC  UR                  U5        GMW     g )NFr   r  )r  r  r   r"   r   )r  r   r  r^   not)r>   r  r  rf  r0  rj  rk  rl  _get_extentrt   r  r@  r
  ry   open_bracketr   r  r]  rX  )
r   r  r  r4  last_was_containerrv  r8  	next_itemr  next_next_items
             r,   rl  Container.reflow	  s   "&t{{3MU eai8I$%%t&7%FG (N ,,U34K)2 *?),Y3)>	  A
 &$--"112BC%*"""4-=)>#;=)3D;L;G;I *J &J" )UaZ D	T...#i.D4F4F"FT[[!Q&jD.I.I--.>?+0(!)$++uqy!AI%55IjI&F&F	Nc)"NJ~t,L,L(+I%(?&1133&;;((3a79 9 #112BCU 4r.   c                    Sn[        U R                  US-
  5      nU=(       a    [        U5      S:H  nU[        U R                  5      :  a  [        U R                  U5      nUS-  n[	        U[
        [        45      (       a   U$ [	        U[        5      (       a8  U(       a0  UR                  (       a  U(       a  US-  nOX%R                  -  nUnM  O4[        U5      S;  a%  UR                  (       d  UR                  (       d   U$ [        U5      S:X  a  SnX%R                  -  nUnU[        U R                  5      :  a  M  U$ )zRThe extent of the full element.

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

r   r   r  )r  r  r^   r  T)r  r  rt   ry   rf  rj  rk  r  rJ  r  rI  )r   rv  r  r  seen_dotr8  s         r,   r  Container._get_extent
  s    T[[%!)4	6Y3!6c$++&&DKK/DQJE$!2L ABB* ' $	**!2!2!))+ $Id)#99ll4>>  4yCiiFI1 c$++&&4 r.   c                     gr  ru  r  s    r,   rI  Container.is_string3
      r.   c                 4    [        U R                  5       5      $ rx  )ry   r-  r  s    r,   r  Container.size7
  s    4==?##r.   c                     gr  ru  r  s    r,   rH  Container.is_keyword;
  r  r.   c                     gr  ru  r  s    r,   rJ  Container.is_name?
  r  r.   c                     gr  ru  r  s    r,   r  Container.is_commaC
  r  r.   c                     gr  ru  r  s    r,   ru  Container.is_colonG
  r  r.   c                     g rx  ru  r  s    r,   r  Container.open_bracketK
      r.   c                     g rx  ru  r  s    r,   r   Container.close_bracketO
  r  r.   r  Nr}  )r&   rR  rS  rT  rU  r   r-  r  r  rl  r  r  rI  r  rH  rJ  r  ru  r  r   rW  ru  r.   r,   r  r  	  s    -.  ).-D^#J   $ $            r.   r  c                   8    \ rS rSrSr\S 5       r\S 5       rSrg)TupleiT
  z'A high-level representation of a tuple.c                     g)Nr   ru  r  s    r,   r  Tuple.open_bracketX
      r.   c                     g)Nr  ru  r  s    r,   r   Tuple.close_bracket\
  r  r.   ru  N	r&   rR  rS  rT  rU  r  r  r   rW  ru  r.   r,   r  r  T
  s+    1   r.   r  c                   8    \ rS rSrSr\S 5       r\S 5       rSrg)Listia
  z&A high-level representation of a list.c                     g)Nr   ru  r  s    r,   r  List.open_brackete
  r  r.   c                     g)N]ru  r  s    r,   r   List.close_bracketi
  r  r.   ru  Nr  ru  r.   r,   r  r  a
  s+    0   r.   r  c                   8    \ rS rSrSr\S 5       r\S 5       rSrg)	DictOrSetin
  z3A high-level representation of a dictionary or set.c                     g)Nr   ru  r  s    r,   r  DictOrSet.open_bracketr
  r  r.   c                     g)N}ru  r  s    r,   r   DictOrSet.close_bracketv
  r  r.   ru  Nr  ru  r.   r,   r  r  n
  s+    =   r.   r  c                   (    \ rS rSrSr\S 5       rSrg)rj  i{
  z4A high-level representation of a list comprehension.c                 |    SnU R                    H)  n[        U[        5      (       a    U$ XR                  -  nM+     U$ r  )r  rf  rk  r  )r   lengthr8  s      r,   r  ListComprehension.size
  s?    KKD$-- iiF   r.   ru  N)r&   rR  rS  rT  rU  r  r  rW  ru  r.   r,   rj  rj  {
  s    > r.   rj  c                       \ rS rSrSrSrg)rk  i
  z0A high-level representation of an if-expression.ru  N)r&   rR  rS  rT  rU  rW  ru  r.   r,   rk  rk  
  s    :r.   rk  c                 4   [        [        X   6 5      /nUS-  n[        U 5      nX:  Gan  [        X   6 nUR                  S;   a  US:X  a  [	        U5      US-
  4$ US:X  a  [        U5      US-
  4$ UR                  [        U5      5        UR                  S:X  a  [        U5      U4$ UR                  S:X  a  [        U5      U4$ UR                  S:X  a  [        U5      U4$ OUR                  S;   a  [        X5      u  paUR                  U5        OzUR                  S:X  a   [        XS5      u  paUR                  U5        OJUR                  S:X  a   [        XS5      u  paUR                  U5        OUR                  [        U5      5        US-  nX:  a  GMn  g	)
z9Parse a high-level container, such as a list, tuple, etc.r   z,)]}forri   r  r  r  rj   rQ  )r0  r  ry   r  rj  rk  rx   r  r  r  _parse_container)r~   rv  	for_or_ifr  
num_tokenstokrm  s          r,   r  r  
  s    %'()E	QJEVJ

V]#v%
 E!)%0%!)<<d"$U+UQY77 LLc# 3&ee,,!!S(UU++!!S(!%(%00 ) &!1&!@YLL#&!1&!GYLL#%!1&!FYLL# LLc#
] 
` r.   c                 ~   Sn/ n[        U 5      nX:  a  [        X   6 nUR                  [        R                  :w  d   eUR                  [
        R                  :X  a   U$ UR                  S;   a'  [        X5      u  pQU(       d  gUR                  U5        OUR                  [        U5      5        US-  nX:  a  M  U$ )zcParse the tokens.

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

r   rj   Nr   )ry   r  r   r  r  rm   ro   r  r  rx   r0  )r~   rv  parsed_tokensr  r  rm  s         r,   _parse_tokensr  
  s     EMVJ

V]#~~--->>X---  u$!1&!@Y  +  c+
! 
$ r.   c                    [        U S   5      S:X  a  US[        -  -   nOUS[        -  -   nU(       + n[        U5      nUR                  [	        UR                  S5      5      5        U(       d`  [        U S5      n[        U S5      nU(       aA  U(       a:  [        U5      S   S:X  a(  [	        U5      [	        U5      -   S-   [	        U5      :X  a  gU  Hf  n	UR                  [        U	5      S	S
9  Un
U(       a-  [        U	[        5      (       a  SnSUR                  5       S-   -  nU	R                  XdU5        U
nMh     UR                  5       $ )z'Reflow the lines so that it looks nice.r   defz  r.  r   r   r   NT)rM  F)rt   rl   r   r=  ry   r1  r  rP  rf  r  rV  rl  r  )r   r  r  start_on_prefix_liner  r4  linesfirst_tokensecond_tokenr8  save_continued_indents              r,   _reflow_linesr	  
  s<    =%&3F)FF&/B)BB#77_-E	S++F345 }a0q1 La C's;//!3s;K7LL!!#d)4!8 0JtY$?$?#( "e&8&8&:Q&>?E-EF0  ::<r.   c              #   6  #    X!-   v   [        U 5      nU(       a}  [        XBUSS9nU(       a+  [        [        UR	                  5       5      5      (       a  Uv   [        XBUSS9nU(       a-  [        [        UR	                  5       5      5      (       a  Uv   gggg7f)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	  r[  r  r1  )r~   r   r  r  r   rT  s         r,   r  r    s      
!&)M m/379\"5elln"EFFKm/38:\"5elln"EFFK G5 s   BBc                 d   / n[        [        U 5      5       GH  u  pxUu  n	n
nnU	[        R                  :w  d   eX;   a  SSSS.R	                  U
5      nU(       a0  [        U US-   SS/S9S   U:X  d  [        U US-   SS/S9S   U:X  a  Mt  US:  a  U
S	:X  a  XS-
     S   S
;   a  M  U[        U5      S-
  :  a  UR                  U5        M  M  [        XS-
  5      nU	[        R                  :X  d  M  U(       d  M  US   [        R                  :X  d  M  UR                  U5        GM     SnSn[        X5       HI  nU(       a2  USU-   U-   -  nS H  nUR                  U5      (       d  M  X-  nM!     M<  UnU(       a   eUnMK     Uc   e[        US:  a  [        U5      OU5      (       a  UU-   $ g)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.

r  r  r  r   r   r   r   Nr  r   r   z,(%[r   r
   rj   )r>   r  r  r  rs   r  ry   rx   rm   rv   split_at_offsetsrk   r[  r  )r~   r   r  r   r  r   offsetsrv  _tr   r  r  r  unwanted_next_tokenprevious_tokencurrent_indentrT  r+   symbols                      r,   r  r  0  s    G v!67 				U\\))), # #l+   #V"QY&*D\33469LM V"QY&*D\33469LM  	lc1qy!!$. CK!O+z* , &fai8Nhoo->!#4#G|,Y 8\ NE 1TN*T11E==(("1N  
 E%%%(N 2 !A~ (.+02 2U""r.   c              #      #    SnSnSnU  HD  nUS   nUS   nUS   u  pxUS   u  pX-  nX':X  a  X-  nUnU[        U5      -  nUUUU4v   U	nU
nMF     g7f)zYield tokens and offsets.r   r   r   r"   Nr  )r~   r  previous_end_rowprevious_end_columnr7  r   r  r  r  r  r  r  s               r,   r  r    s     JqT
t$%aD! !! 	"
(-J " 	c,''
 	
 #(/ s   AAc                 \   U R                  S5      (       a)  U R                  5       R                  S5      (       a  U S-   $ U R                  S5      (       a  SU -   $ U R                  S5      (       a  U S-   $ U R                  S5      (       a  U S-   $ U R                  S	5      (       a  U S-   $ U $ )
zjNormalize multiline-related code that will cause syntax error.

This is for purposes of checking syntax.

rR   r^   z passzreturn z	def _(): @zdef _(): passzclass )zif zelif for zwhile )rS   r}   rk   r^  s    r,   r  r    s     -..4;;=3I3I#3N3Ng~		#	#T!!			o%%		"	"g~	;	<	<g~Kr.   c                     U SU R                  S5      nXS R                  S5      nUR                  S5      (       a  U $ X2-   U-   $ )z3Replace whitespace at offset and return fixed line.Nri  r5  )r}   r1  rS   )r+   rL  rP  r  r  s        r,   rR  rR    sR     =,DM  -E%%r.   c                    ^  " U4S jS[         R                  5      m[         R                  " SUTS.U D6nUR                  5         UR                  R                  5       $ )z,Execute pycodestyle via python method calls.c                   D   >^  \ rS rSrSrUU 4S jrUU 4S jrS rSrU =r	$ )"_execute_pep8.<locals>.QuietReporti  z'Version of checker that does not print.c                 2   > [         TU ]  U5        / U l        g rx  )superr    _QuietReport__full_error_results)r   r   QuietReport	__class__s     r,   r   +_execute_pep8.<locals>.QuietReport.__init__  s    +t-g6(*D%r.   c                    > [         TU ]  UUUU5      nU(       a$  U R                  R                  UUUS-   US.5        gg)zCollect errors.r   )r   r+   r   r   N)r  r   r   rx   )r   line_numberrL  r   checkrp  r!  r"  s         r,   r   (_execute_pep8.<locals>.QuietReport.error  sR    d1+2826279D ))00(%z!#$ r.   c                     U R                   $ )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    r,   full_error_results5_execute_pep8.<locals>.QuietReport.full_error_results  s     ,,,r.   )__full_error_results)
r&   rR  rS  rT  rU  r   r   r)  rW  __classcell__)r"  r!  s   @r,   r!  r    s    5	+	$	- 	-r.   r!  )r  reporterr2   )r    
BaseReportChecker	check_allreportr)  )r*  r   checkerr!  s      @r,   r&  r&    sW    -k,, -< !! 2F[ 2$02G>>,,..r.   c                     U(       a.  U R                  S5      R                  [        [        -   5      S-   $ U R                  S5      $ )Nz 	r
   )r1  r}   r  r  )r+   with_rstrips     r,   _remove_leading_and_normalizer6    s7    {{7#**273d::;;wr.   c                   4    \ rS rSrSrSS jr\4S jrS rSr	g)	r  i  zReindents badly-indented code to uniformly use four-space indentation.

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

c                 X   [         R                  " U5      nUR                  5       n[        U5      U l        / U l        [        USS9 H  u  pVXPR                  ;   a  U R
                  R                  U5        M1  U[        U5      :g  nU(       a2  U R
                  R                  [        U5      [        Xg5      -   5        Mx  U R
                  R                  [        U5      R                  5       [        Xg5      -   5        M     U R
                  R                  SS 5        SU l        Xl        g )Nr   r   r   )r7   r   rO   multiline_string_linesstring_content_line_numbersr  r>   rx   ry   r9  r6  
expandtabsrC  rv  
input_text)r   r=  r  r   r  r%  r+   r5  s           r,   r   Reindenter.__init__  s    kk*%}}+A*+M(
 
!*<q!AK>>>

!!$' *S->>JJ%%(.5dHI
 JJ%%(.99;5dHI "B$ 	

!T"
$r.   c                 "   US:  a  U R                   $  [        [        R                  " U R                  5      5      nU R                  nUR                  [        U5      S45        0 n/ nUS   S   nUR                  USU 5        [        [        U5      S-
  5       GH  nX&   u  pxX&S-      S   n	[        X7   5      n
X-  nUS:  a  U
(       a  UR                  U
S5      nUS:  aE  [        US-   [        U5      S-
  5       H&  nX,   u  pUS:  d  M  U
[        X=   5      :X  a  X-  n  O   US:  aF  [        US-
  SS5       H2  nX,   u  pUS:  d  M  U
[        X]S-
     5      -   [        X=   5      -
  n  O   US:  a  U
nOSnUS:  d   eXU
'   X-
  nUS:X  d  U
S:X  a  UR                  X7U	 5        GM  [        X7U	 US9 H  u  nnUU R                  ;   a  UR                  U5        M)  US:  a2  US:X  a  UR                  U5        MH  UR                  SU-  U-   5        Ma  [!        [        U5      U* 5      nUR                  UUS 5        M     GM     SR#                  U5      $ ! [
        [        R                  4 a    U R                   s $ f = f)	zSFix indentation and return modified line numbers.

Line numbers are indexed at 1.

r   r   r]   r9  r
   r.  Nr2   )r=  _reindent_statsrm   rZ  getlinerK   r   r  rx   ry   extendr{   _leading_space_countrs   r>   r;  rj  r   )r   r  statsr  	have2wantafterr   thisstmt	thislevelnextstmthavewantjjlinejlevelr  r%  r+   removes                      r,   r  Reindenter.run  s    ???"	##H$<$<T\\$JKE 

c%j!_%	 !HQKU1QZ s5zA~&A"'(HU|AH'8D*Dax %==r2Dax!&q1uc%j1n!=A,1HME%{#'+?+M#M+1+?D % "> ax "'q1ub"!5A,1HME%{(,/C(-ai(80: ):(<U\(J)K !& "6 ax#D199"dO;DqyDAIUH56)25(3K9A*C%K"d&F&FFT*4<!LL.!LLtd):;!$%9$%?$!GT&']3*CU 'n wwu~K X001 	#??"	#s   )I% %&JJc                     U R                   [        U R                  5      :  a  SnU$ U R                  U R                      nU =R                   S-  sl         U$ )zLine-getter for tokenize.r2   r   )rv  ry   r  )r   r+   s     r,   rA  Reindenter.getlined  sH    ::TZZ(D  ::djj)DJJ!OJr.   )rv  r=  r  r;  Nr}  )
r&   rR  rS  rT  rU  r   rl   r  rA  rW  ru  r.   r,   r  r    s    %@ 2 Pdr.   r  c                    SnSn/ nU  H  nUS   nUS   S   nUS   nU[         R                  :X  a  SnM-  U[         R                  :X  a	  SnUS-  nMJ  U[         R                  :X  a	  SnUS-  nMg  U[         R                  :X  a  U(       a  UR                  US45        M  M  U[         R                  :X  a  M  U(       d  M  SnU(       d  M  UR                  Xb45        M     U$ )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]   )rm   ro   r  r  ru   rx   rn   )r~   	find_stmtlevelrD  r7  r   r#  r+   s           r,   r@  r@  n  s     IEEqT
!Qt))) I8??*IQJE8??*IQJE8+++eR[) 
 8;;&Y Ite^,E H Lr.   c                 t    SnU[        U 5      :  a&  X   S:X  a  US-  nU[        U 5      :  a
  X   S:X  a  M  U$ )z(Return number of leading spaces in line.r   r.  r   r  )r+   r   s     r,   rC  rC    s=    	A
c$i-DGsN	Q c$i-DGsNHr.   c                 R     [        U SSSS9$ ! [        [        [        4 a     gf = f)zReturn True if syntax is okay.z<string>execT)dont_inheritF)compilerK   	TypeErrorr  r  s    r,   r[  r[    s1    tZdCCJ/ s    &&c                 Z  ^	 [        [        R                  " X5      5      nU(       d  / $ US   R                  5       nSS0m	[	        [        R                  " SU5      S5       H!  u  pEUR                  5       nXc:  a    O	UT	U'   M#     U	4S jnU Vs/ s H  o" X5      S-   PM     sn$ s  snf )zzA 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                 P   > UR                  SSU R                  5       5      nTU   $ )zeGet the line number of string in a files contents.

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

r
   r   )rfindr   )rE   r   newline_offsetnewline_offsetss      r,   get_line_num,find_with_line_numbers.<locals>.get_line_num  s(     "a?~..r.   )r|   r  finditerr   r>   )
r  r   matchesr   line_numrK  rL  ra  rE   r`  s
            @r,   find_with_line_numbersrf    s    
 2;;w12G	
"+


C 	AO !UH!=qA<"*	 B/ <CC7%L)A-7CCCs   B(c                    [        [        U 5      n[        [        U 5      n[        [        R
                  " SU 5      5      S-   n0 nU H  nSXE'   M	     U H  nSXE'   M	     / nSnSn[        UR                  5       5       H7  u  pU
SL a  USL a  U	nSnM  U
SL d  M  USL d  M#  UR                  X45        SnM9     USL a  UR                  X45        U$ )zyReturns a list of tuples representing the disabled ranges.

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

r
   r   TFN)	rf  ENABLE_REGEXDISABLE_REGEXry   r  findallr   r  rx   )r   enable_line_numsdisable_line_numstotal_linesenable_commandsnumdisabled_rangescurrently_enableddisabled_startr+   commanded_enableds              r,   get_disabled_rangesrt    s     .lFC.}fEbjjv./!3KO#   $ ! ON#)/*?*?*A#B%*;t*C!N %$&+<+E""N#9: $ $C E!<=r.   c                 R    U S   nU H  nUS   Us=::  a  US   ::  d  M     g  M     g)z;Filter out reports based on tuple of disabled ranges.

    r+   r   r   FTru  )r   rp  r+   disabled_ranges       r,   filter_disabled_resultsrw    s;     &>D)!9q(99 : * r.   c              #     #    [        U SS9n[        U SS9n[        U 5      n[        U 5      nU(       a%  U Vs/ s H  n[        UU5      (       d  M  UPM     nn[	        S U 5       5      nU GH  n	U	S   R                  5       n
U	S   U;   a  U
R                  S5      (       a  M8  U	S   U;   a  U
S;   a  MI  U(       d$  U	S   S	-   U;   a  U
R                  S
5      (       a  Mt  US::  a  U
R                  S5      (       a  M  US	::  a  U
R                  S5      (       a  M  US::  a  U
R                  S5      (       a  M  U	S   U;   a  U
R                  S5      (       a  M  U(       a  U
R                  S5      (       a  GM  U	v   GM     gs  snf 7f)ztFilter out spurious reports from pycodestyle.

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

F)include_docstringsTc              3   L   #    U  H  oS    R                  5       S:H  v   M     g7f)r   e901N)r   )r"  r   s     r,   r$  !filter_results.<locals>.<genexpr>  s      Hf$<%%'61s   "$r   r+   )e1r  w191)r  r   )w29w39r   )e711e72w6)e712e713e714r   e704)e261r  r  )r}  e7N)r:  commented_out_code_linesrt  rw  r  r   rS   )r   r  r   !non_docstring_string_line_numbersall_string_line_numberscommented_out_code_line_numbersrp  r   has_e901r+  issue_ids              r,   r(  r(    s     )?5)*%44) '?v&F# *&1O!(
!(v,C-F 	 
 HHHHT7==?V999""#9::V9//8# qy1}1HH "">22?""#899?""#;<<?""F,,V977""#;<<
 ""<00U 
s   6FFFD4Fc           	         [        5       nSn[        R                  /n[        (       a>  UR	                  [        R
                  [        R                  [        R                  /5         [        U 5       H]  nUS   nUS   S   nUS   S   nXd;   a>  Xx:w  a9  U(       d  U[        R                  :w  a  U[        [        SU-   SU-   5      5      -  nUnM_     U$ ! [        [        R                  4 a     U$ f = f)zuReturn line numbers that are within multiline strings.

The line numbers are indexed at 1.

Docstrings are ignored.

r2   r   r   r"   r   )r   rm   rv   r  rB  r  FSTRING_MIDDLEr  rZ  r  r{   rK   r   )	r   ry  line_numbersprevious_token_type_check_target_tokensr7  r   r  r  s	            r,   r:  r:  E  s     5L$OO,##""##  %
 	
 (A1J!QId1gG1i6J&'8??: !Ca)mQ[(I$JJL", )$  ,,- s   (A,C C43C4c                 B   / n [        U 5       H  nUS   nUS   nUS   S   nUS   nUR                  5       R                  S5      (       d  M@  U[        R                  :X  d  MV  UR                  S5      R                  5       n[        R                  " 5          [        R                  " S[        S9  SU;   a'  SU;  a!  [        U5      (       a  UR                  U5        S	S	S	5        M     U$ ! , (       d  f       M  = f! [        [        R                  4 a     U$ f = f)
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   r5  r  )r(   r.  N)rZ  r1  rS   rm   ru   r  warningscatch_warningsfilterwarningsSyntaxWarningr[  rx   rK   r   )r   r  r7  r   r  r  r+   stripped_lines           r,   r  r  l  s    L (A1JQ4L!QIQ4D ;;=++C00X--- , 3 3C 8 > > @,,.
 ++H}M},=0$]33$++I6 /. )6  /. ,,- s1   AD  %4D  AC. D  .
C=	8D   DDc           	         [        U 5      U:  d   eU R                  5       n [        U 5      S-   n[        U[        U5      S-   5      nSn[        U 5      [        U R                  U S   5      5      -
  U:  a   U S   R	                  5       (       d  U SU S-   $ U(       aX  [
        R                  " SU 5      (       a<  [        R                  " U R                  S5      UUUS	S	S
9nSR                  U5      S-   $ U 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+ro  F)initial_indentsubsequent_indentwidthbreak_long_wordsbreak_on_hyphens)ry   r}   r9  rj  r  r  rE   textwrapwrapr1  r   )r+   r  r  r  MIN_CHARACTER_REPEATsplit_liness         r,   r  r    s     t9&&&;;=D #4(4/K/k*R/1O D	CDH-..2FFH $_%,,	"((>488mmDKK$73>6A*95:5:< yy%,,$;r.   c                     U  Vs/ s H  o"R                  S5      U-   PM     snnU(       a2  U S   U S   R                  S5      :X  a  US   R                  S5      US'   U$ s  snf )z[Return fixed line endings.

All lines will be modified to use the most common line ending.
z
r]   )r}   )r  r5   r+   s      r,   normalize_line_endingsr    sa    
 7<<edKK')e<Db	U2Y--f558??6*RK =s   A c                 T    UR                  U 5      =(       d    U R                  U5      $ rx  ry  )r  rg   s     r,   mutual_startswithr    s    <<?-all1o-r.   c                    U(       am  [        U[        5      (       a   eU Vs/ s H  o3R                  5       PM     sn H2  n[        U R	                  5       UR	                  5       5      (       d  M2    g   U(       an  [        U[        5      (       a   eU Vs/ s H  o3R                  5       PM     sn H2  n[        U R	                  5       UR	                  5       5      (       d  M2    g   ggs  snf s  snf )NFT)rf  rt   r  r  r   )rp  r  r  rk  ignored_codeselected_codes         r,   
code_matchr    s    fc****0671WWY7L |/A/A/CDD 8 fc****178Aggi8M }/B/B/DEE 9  8 9s   C+C0c                 *   [        X5      nUR                   Vs/ s H  oDR                  5       PM     snUl        UR                   Vs/ s H  oDR                  5       PM     snUl        UR                  n1 Sk[	        U5      -  (       d  UR                  R                  S5        [        U [        5      (       d"  U R                  U=(       d
    [        5       5      n [        R                  " U 5      n[        UR                  5       US9$ s  snf s  snf )z_Return fixed source code.

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

>   W50r   r   r  )r   )_get_optionsr  upperr  r   rx   rf  rt   decodeget_encodingr7   r   	fix_linesrO   )r   r   r4   apply_configopt
ignore_optr   s          r,   fix_coder    s     71G-4^^<^ciik^<GN-4^^<^ciik^<GN
 J"S_4e$fc""x9<>:
++f
CS]]_g66 =<s   D	Dc                    U (       d  [        S/US9$ [        U [        5      (       a  [        S/US9nU R                  5        H  u  p4[	        X#5      (       d  [        SR                  U5      5      e[        [        X#5      5      n[        U[        45      (       d0  [        U[        45      (       a  [        SR                  U5      5      e[        X#U5        M     U$ U nU$ )zReturn parsed options.r2   r  zNo such option '{}'z"Option '{}' should not be a string)
parse_argsrf  dictr  r   r  rU   typer  rt   setattr)raw_optionsr  r   namevalueexpected_types         r,   r  r    s    2$\::+t$$bT=&,,.KD7)) !6!=!=d!CDD !!78MmcW55ecW--$<CCDIK KG5) / N Nr.   c                 X   [        U 5      nSR                  [        U S5      5      n[        5       nUR                  (       a  UnO[        UUUS9nSn[        5       n[        U5      U;  a  UR                  S:  a  XqR                  :  a  ObUS-  nUR                  [        U5      5        [        R                  " U5      n[        UUUUS9n	U	R                  5       n[        U5      U;  a  M  [        R                  " U5      n
SR                  [        U
R                  5       U5      5      $ )zReturn fixed source code.r2   r
   r9   r   r   )r   r   )r-  r   r  r   r'  apply_global_fixeshashpep8_passesr
  r   r   r  r7   r   rO   )r  r   r9   original_newline
tmp_sourceprevious_hashesr  passesr   r  r   s              r,   r  r    s    $L1/dCDJ eO! ***13;= F U
|
O
3!#1D1D(D!D./YY|,
#9	; wwy |
O
3" ++l
#C77)#--/;KLMMr.   c                    U(       d  [        U /US9n[        U 5      nUnUR                  (       d  UR                  (       d  U(       a  [	        U 5      nU(       a  [        [        UWS95      n[        XQU S9nUR                  (       a  [        R                  " U5      nUR                  5       n[        XGU 5      nU(       a#  UR                  U5        UR                  5         U$ UR                  S:  a  UR                  W5      nU$ UR                  (       a  SR!                  U5      R#                  5       n	UR#                  5       n
U(       a  US   R%                  S5      S   OSnUR%                  S5      S   nX:w  d  X:w  a'  ['        U SWS9 nUR                  U5        S S S 5        U$ g U(       a!  UR                  U5        UR                  5         U$ ! , (       d  f       U$ = f)	Nr  rH   r  r   r2   r]   r
   w)r  rP   in_placer  r6   LineEndingWrapperr  r  r7   r   rO   r  writeflushjobsencoder   rm  r0  r:   )r9   r   outputr  r   r  r4   r  r  r  rT  original_source_last_linefixed_source_last_linefps                 r,   fix_filer  1  s   hZlC)(3O"L7<<6"8,";v#IJ\XFL||kk,'mmo_8<LLLLN  \\A;;x(D			77?+668'')3BOB%%d+B/ 	" ".!3!3D!9"!=%?#HcHE& FLL&LLN FEs   G
G'c               #      #    [        [        5       R                  5       5       HP  n [        R                  " U 5      (       d  M   [        U 5      nUSS S/:w  a  M7  [        U 5      nU(       d  MK  X 4v   MR     g7f)z'Yield multiple (code, function) tuples.Nr   r   )r|   globalsvaluesinspect
isfunctionr  extract_code_from_function)function	argumentsrp  s      r,   global_fixesr  `  se     ))+,h'''1I!}
*-h7Dt&& -s   >A9'A9/
A9c                    [         R                  R                  S:  aP  [        R                  " U 5      (       a  U R
                  n [        [        R                  " U 5      R                  5      $ [        R                  " U 5      S   $ )Nr"   r   )
r  version_infomajorr  ismethod__func__r|   	signature
parameters
getargspec)r  s    r,   r  r  m  sf    
" H%%((HG%%h/::;;!!(+A..r.   c           
        ^ Uc  / n[        U4S jS 5       5      (       a7  [        U TR                  [        STR                  TR
                  S9(       + S9n [        5        H  u  pV[        UTR                  TR
                  S9(       d  M+  TR                  (       a6  [        SR                  UUR                  5       5      [        R                  S9  U" U TR                  S9n M     U $ )	zRun global fixes on source code.

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

c              3   b   >#    U  H$  n[        UTR                  TR                  S 9v   M&     g7f)r  r  N)r  r  r  )r"  rp  r   s     r,   r$  %apply_global_fixes.<locals>.<genexpr>  s)      )'t d7>>'..I's   ,/)E101E111W191r  )r  r  z--->  Applying {} fix for {}r   )r   )r  r  r  r  r  r  r  r  r  rU   r  r  r	  r   )r   r   wherer9   codesrp  r  s    `     r,   r  r  {  s     }
 )') ) )++">>">>

 )Nd7>>'..II4;;E<@JJLJ::' f)0););=F + Mr.   c                     U R                   R                  S5      (       d  g[        R                  " SSU R                   5      nU(       d  g [	        USS 5        U$ ! [
         a     gf = f)z Return code handled by function.r   Nz^fix_r2   r   )r&   rS   r  r  r/  r  )r  rp  s     r,   r  r    sg    ''//66'2x001DDH K  s   A 
A*)A*c                  d    SR                  [        R                  5      /n SR                  U 5      $ )Nzpycodestyle: {}r   )rU   r    __version__r   )packagess    r,   _get_package_versionr    s*    !(()@)@ABH99Xr.   c            
         [         R                  " [        [        5      SS9n U R	                  SSSR                  [        [        5       5      S9  U R	                  SSS	S
SS9  U R	                  SSSSS9  U R	                  SSSSS9  U R	                  SS[        SR                  [        5      S9  U R	                  SSSS9  U R	                  SSSSS9  U R	                  SS[        S S!S"S#9  U R	                  S$S%S S&[        S'S(9  U R	                  S)S*S	S
S+S9  U R	                  S,SS-S9  U R	                  S.S/S0S19  U R	                  S2SS3S9  U R	                  S4S5S6S7R                  [        5      S9  U R	                  S8S5S6S9S9  U R	                  S:S S;[        S<S(9  U R	                  S=S>S?S@[        SASBSC9  U R	                  SD[        [        [         R                  SE9  U R	                  SFSSGS9  U R	                  SHSSIS9  U R	                  SJSKSLSM9  U $ )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-configr9   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)r  r   r  r  z-pz--pep8-passesr]   z<maximum number of additional pep8 passes (default: infinite))r   r  r  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--ignorerb  r2   z.do not fix these errors/warnings (default: {})z--selectz*fix only these errors/warnings (e.g. E4,W)z--max-line-lengthO   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  r  nargsr  z--indent-size)r  r  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_summaryrU  add_argumentrU   r  r  DEFAULT_CONFIGr/  DEFAULT_IGNORErl   SUPPRESS)parsers    r,   create_parserr    s   $$1B71K*46F
I 2 9 9')=)?!A  B k' !K  L h|B  D
l<=  ?
): .--3VN-C	  E
 /L  M mLF  G hS#qG  H os "3  4 nWaM  N (8  :
W5  6 |8  9 
Hb--3VN-C  E 
HbI  K
+S"36  7 	6 $3a=  >
 1D x'8'8  :
(H  J
lJ  K
 sE  G Mr.   c                 ,  ^  [        5       nSn[        U 4S j[         5       5      (       a  SnSU;   nSU;   nT  H  nUS:X  aT  U(       a  U(       a  UR                  1 Sk5        M,  U(       a  UR                  1 Sk5        MH  UR                  1 S	k5        M]  US
;   aS  U(       a  U(       a  UR                  S15        M  U(       a  UR                  SS15        M  UR                  SS15        M  US;   a	  U(       a  M  UR	                  U5        M     U$ )zexpand to individual E/W codesFc              3   P   >^#    U  H  m[        U4S  jT 5       5      v   M     g7f)c              3   F   >#    U  H  nTR                  U5      v   M     g 7frx  ry  )r"  rp  conflicting_codes     r,   r$  *_expand_codes.<locals>.<genexpr>.<genexpr>  s&      !D !++D11!r|  N)r  )r"  r  r  s    @r,   r$   _expand_codes.<locals>.<genexpr>  s4      
 %6 	  !   %6s   "&Tr   r   W>   W1W2W3W6W505>   r  r  r  r  r   r  >   r  r  r  r  r   r  )W5r  r  r   )r   allCONFLICTING_CODESr  r
  )r  ignore_codesretis_conflictis_ignore_w503is_ignore_w504rp  s   `      r,   _expand_codesr"    s    
%CK
 
 %6   |+N|+N3;.

;<

CD

CD]".

F8$

FF+,

FF+,**{{GGDM! $ Jr.   r  rp  msgr   c                 j    U R                  [        R                  5        U R                  X S35        g)z wrap parser.error with exit coder
   N)print_usager  r	  exit)r  rp  r#  s      r,   _parser_error_with_coder'  $  s(     szz"
KKRj!r.   c                 
  ^ [        5       nUR                  U 5      mTR                  (       d"  TR                  (       d  [	        U[
        S5        TR                   Vs/ s H  n[        U5      PM     snTl        U(       a^  [        TU5      n [        TU5      nU(       a  UnUR                  U 5      mTR                   Vs/ s H  n[        U5      PM     snTl        STR                  ;   a  [        TR                  5      S:  a  [	        U[
        S5        TR                  (       a  [	        U[
        S5        TR                  (       a  [	        U[
        S5        TR                  (       a  [	        U[
        S5        [        TR                  5      S:  a3  TR                  (       d"  TR                  (       d  [	        U[
        S	5        TR                  (       a3  TR                  (       d"  TR                  (       d  [	        U[
        S
5        TR                  (       a"  TR                  (       a  [	        U[
        S5        TR                  S::  a  [	        U[
        S5        TR                  S::  a  [	        U[
        S5        TR                   (       aJ  [#        [%        TR                   5      TR&                  (       a  [%        TR&                  5      O/ 5      Tl        TR&                  (       aX  [%        TR&                  5      Tl        [)        U4S j[*         5       5      (       a  TR&                  R-                  [*        5        O@TR                   (       d/  TR.                  (       a
  1 SkTl        O[%        [0        5      Tl        TR2                  (       a  [%        TR2                  5      Tl        O0 Tl        TR4                  S:  a  SSKnUR9                  5       Tl        TR4                  S:  a3  TR                  (       d"  TR                  (       d  [	        U[
        S5        TR:                  (       aU  TR:                  S   S::  a  [	        U[
        S5        TR:                  S   TR:                  S   :  a  [	        U[
        S5        [<        R>                  n[@        [<        l        TRB                  (       a  [<        RD                  " S[F        5        U[<        l        T$ s  snf ! [         a    Sn GN_f = fs  snf )zParse command-line options.zincorrect number of argumentsNr   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   n   >^#    U  H)  m[        U4S  jTR                   5       5      (       + v   M+     g7f)c              3   F   >#    U  H  nTR                  U5      v   M     g 7frx  ry  )r"  ignore_coder  s     r,   r$  'parse_args.<locals>.<genexpr>.<genexpr>  s&      '2 %//<<'2r|  N)r  r  )r"  r  argss    @r,   r$  parse_args.<locals>.<genexpr>  s=      

 ):$	  '+{{    ):s   15>   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 secondzL`experimental` option is deprecated and will be removed in a future version.)$r  r  r  
list_fixesr'  EXIT_CODE_ARGPARSE_ERRORdecode_filenameread_configread_pyproject_tomlrB   ry   r  r  	recursiver  r  r  r"  _split_comma_separatedr  r  r  r  r   r
  excluder  multiprocessing	cpu_countr'  r  formatwarningr-   r   warnDeprecationWarning)r  r  r  r  parser_with_pyproject_tomlr8  original_formatwarningr-  s          @r,   r  r  ,  s   _FY'D::doo,.M	
 59JJ?JD/$'J?DJT6*	.)<T6)J& &/F  +8<

C
od+
C

djjtzz?Q#(4 99#(; ==#(? >>#(@ 4::DMMTYY$@	
 ~~t}}		$@	
 }}$:	
 q $6	
 1$2	
 {{#"4;;/48KK#DKK0R

 {{,T[[9 

 ):
 
 
 KK01[[??7DK0@DK||-dll;yy1} 	#--/	yy1}dmmtyy$/	
 ??1"#(2
 ??1 22#(  &332H+	

 4HKc @  	.)-&	.
 Ds   S&S+ S>+S;:S;c              #     #    UR                  U5       H  u  pEUR                  S5      R                  SS5      nUR                  U5      (       d  M>  X6   nU[        L aJ  UR                  5       S:X  a$  U R                  (       a  [        SU SU 35        M  UR                  X$5      nO,U[        L a  UR                  X$5      nOUR                  X$5      nXdU4v   M     g 7f)Nr   r)   autozignore config: r  )r  r1  rW  rs   r/  r  r  r  getintrV  
getboolean)	r-  configsectionoption_listkvnorm_optopt_typer  s	            r,   _get_normalize_optionsrJ    s     ,,w'88C=((c2x(((s?wwyF"<<OA3as34MM'-E%%g1EJJw*E5  ! (s   CC c           	         [        5       n U R                  (       aR  [        R                  R	                  U R
                  5      (       a$  [        SR                  U R
                  5      5        UR                  U R
                  5        U R                  (       Gdp  U R                  =(       aF    [        R                  R                  [        R                  R                  U R                  5      5      =p4U(       Ga  UR                  [         Vs/ s H"  n[        R                  R                  X55      PM$     sn5      (       a  U R                  (       a  [         H  n[        R                  R                  X55      n[        R                  R	                  U5      (       d  MH  [        SR                  [        R                  R                  X55      5      5        M     O+[        R                  R                  U5      u  p4U(       a  GM  0 nUR                    Vs0 s H6  nUR"                  UR$                  =(       d    [%        UR&                  5      _M8     n	nS Ha  n
UR)                  U
5      (       d  M  [+        XX5       H6  u  pnU R                  (       a  [        SR                  XU5      5        XU'   M8     Mc     UR,                  " S0 UD6  U$ s  snf s  snf ! [.         a     U$ f = f)z5Read both user configuration and local configuration.zread config path: {})r!   r    flake8z+enable config: section={}, key={}, value={}ru  )SafeConfigParserr  ospathexistsglobal_configr  rU   rI   ignore_local_configr  abspathcommonprefixPROJECT_CONFIGr   r0  _actionsdestr  r  has_sectionrJ  set_defaultsr   )r-  r  rC  parenttailfnconfig_filedefaultsorE  rD  rH  rF  r  s                 r,   r3  r3    sA   F*<<BGGNN4+=+=>>(//0B0BCDD&&'''' JJ 2277??$$TZZ0,2 2F;;*8 :*8B !#V 8*8 : ; ;||"0B*,'',,v*BK#%77>>+#>#> (! 6 = =$&GGLL$<!"	 #1 !#v!6 $   &1 /1 vvqvv8aii8 / 	 1 9G%%g..&<g'"U <<GNNE+ ,%*"' 9 	'h'
 MG : 1  M	s8   DK  )K:CK  K  =KA;K  
K   
K.-K.c                 4   [         R                  S:  a  SSKnOSSKnSn[        R
                  R                  U R                  5      (       a0  [        U R                  S5       nUR                  U5      nSSS5        U R                  (       d  U R                  =(       aF    [        R
                  R                  [        R
                  R                  U R                  5      5      =pVU(       a  [        R
                  R                  US5      n[        R
                  R                  U5      (       a(  [        US5       nUR                  U5      n SSS5        O*[        R
                  R                  U5      u  pVU(       a  M  U(       d  gUR!                  S0 5      R!                  S5      c  gUR!                  S0 5      R!                  S5      n0 nUR"                   V	s0 s H6  n	U	R$                  U	R&                  =(       d    ['        U	R(                  5      _M8     n
n	SnUR+                  5        H  u  pUR-                  S	5      R/                  S	S
5      nU
R!                  U5      (       d  M>  ['        U5      [0        [2        4;   a  X;   a  SR                  U5      nOUnU R4                  (       a  [7        SR9                  X5      5        XU'   M     U(       a  UR:                  " S0 UD6  U$ ! , (       d  f       GN= f! , (       d  f       GN= fs  sn	f )z+Read pyproject.toml and load configuration.)r"      r   Nrbzpyproject.tomltoolr  )r  r  r   r)   r   z.enable pyproject.toml config: key={}, value={}ru  )r  r  tomllibtomlirN  rO  rP  rQ  r8   loadrR  r  rS  rT  r   r0  rs   rV  rW  r  r  r  r1  rW  r|   r  r  r  rU   rY  )r-  r  rd  rC  r  rZ  r[  pyproject_tomlr^  r_  rE  TUPLED_OPTIONSrF  rG  rH  r  s                   r,   r4  r4    sR   
7"F	ww~~d(())$$$d+r\\"%F , ##

 .rwwGG  ,(. 	.WW\\&2BCNww~~n--.$/2$\\"-F 0/  WW]]62NV d zz&"!!*-5ZZ#''
3FH"OO-+q 661664T!))_4+  - *N,,.88C=((c2x((7tUm#(BHHQKEE<< %%+VA%57" ! 'h'MY ,+ 0/-s   $K1 L"=L1
L 
Lc                     U R                  S5       Vs1 s H)  oR                  5       (       d  M  UR                  5       iM+     sn$ s  snf )zReturn a set of strings.r   )r0  r  )r  r   s     r,   r6  r6  J  s3    %+\\#%6G%6T**,LDJJL%6GGGs
   AAc                 x    [        U [        5      (       a  U $ U R                  [        R                  " 5       5      $ )zReturn Unicode filename.)rf  rt   r  r  getfilesystemencodingr  s    r,   r2  r2  O  s,    (C  ??344677r.   c               #   @  #    S[        [        R                  5      4v   [        SSSS9n [	        U 5       Hx  n[
        R                  " SU5      nU(       d  M#  UR                  S5      R                  5       [
        R                  " SS[        [        X5      R                  5      5      4v   Mz     [        [        5       5       HT  u  p#UR                  5       S	[        U5      -
  S-  -   [
        R                  " SS[        UR                  5      5      4v   MV     g7f)
zuYield pep8 error codes that autopep8 fixes.

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

r  Nr2   )r9   r   r   zfix_([ew][0-9][0-9][0-9])r   z\s+r.  r   )r  r  rU  r   dirr  rE   r  r  r  r  r   r  ry   )instance	attributerp  r  s       r,   supported_fixesrp  W  s      $X%5%56
77dR@H]	xx3Y?4

1##%vs()E)M)MNP  # #<>2zz|q3t9}33vvfc#4X5E5E#FGI 	I 3s   ADCDc                 <    U (       a  U R                  S5      S   $ S$ )zReturn summary of docstring.r
   r   r2   )r0  )	docstrings    r,   r  r  o  s    '09??4 #8b8r.   c                 J	  ^ U R                  5       (       d  gSnU R                  5       R                  S5      nSmUS   R                  5       R	                  S5      (       dt  US   R                  5       S   S;  aZ  S HT  u  pgUS   R                  U5      nUS   R                  U5      n	US:  d  M5  U	S:  d
  XS-   :w  d  ME  [        TSU-   5      mMV     [        U4S jU 5       5      n
US	[        SX-
  5      -  -  nU[        U5      -  nUS
[        S U 5       5      -  -  nSSSS.R                  US   S   5      n[        U5      S:  a3  U(       a,  US   R                  5       R	                  U5      (       a  US-  n[        U5       GH  u  pUR                  5       nUR	                  S5      (       a  M.  S H*  nUR	                  U5      (       a  US-  nX:X  d  M%  US-  nM,     UR                  S5      (       a  SU;   a  US-  nUR                  S5      (       a  [        U5      [        U5      ::  a  US-  nUR                  S5      (       a,  USS R                  5       R                  S5      (       a  US-  nUR                  S5      (       a5  [        U5      S:  a&  US   R                  5       (       d	  US   S;   a  US-  nUR                  S5      (       a  US-  n[        U5      (       a  US-  n[        R                  " SUR                  S5      5      (       a  US-  n[        R                  " SUR                  S5      5      (       a  US-  nUR                  S 5      (       a  US-  nUR	                  S!5      (       a  US"-  nUR                  S#5      (       a  [        U5      nUS-  nU[        U5      :  ah  U[        X\   5      -  nX\   R                  5       R	                  S5      (       a  UnO/X\   R                  S#5      (       d  OUS-  nU[        U5      :  a  Mh  X:  a  US$-  nOXC(       a  SOS-  nSU;   a  UR                  S%5      (       a  US$-  nUR                  S%5      (       a  US-  nUS$[!        U5      -  -  nGM
     [        SU5      $ )&z<Return rank of candidate.

This is for sorting candidates.

r   r
   r5  r]   rj   z()z[]z{}r   c              3   \   >#    U  H!  nT[        UR                  5       5      -   v   M#     g 7frx  )ry   r  )r"  r  rL  s     r,   r$  'line_shortening_rank.<locals>.<genexpr>  s      A5a&3qwwy>15s   ),r   r   c              3   8   #    U  H  n[        U5      v   M     g 7frx  r  r  s     r,   r$  rv    s     "?3t99r  r  r  r  r     )r  r   r   r   r   r  i  z': )r   r   r   r  r   Nr   r   r7  i,  r  z.*[(\[{]\s*[\-\+~]$z\ z.*lambda\s*\*$r   r  2   r  
   r^   )r  r}   r0  r1  rS   r   r  ry   standard_deviationrs   r>   rk   r  has_arithmetic_operatorr  rE   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_lenrL  s                   @r,   r  r  t  s    ??D$$T*EF!HOO((--a"U*"4W  (--0K(--0Ka?k1_&D [9F #5 A5AAOAA8999DCJD 	A""?"????D  #eAhrl# 
 5zA~!HOO(();<<BJD )% 0#))+""3''2I&&y11 ( 3 !!";<<\!DLD  !566< C$44 %%c**Sb!((*33C88 %%c**L!A%b!))++|B/?3/F $$S))&|44 88*L,?,?,FGGDLD88%|':':5'ABBDLD  !566BJD ""6**BJD  && L)IaKF3u:%S//	='')44S99 /I}--d33! 3u:% *
|2 ,<#8#8#=#=BJD   %%CKD.|<<< !1B q$<r.   c                    ^ [        U 5      n U (       d  g[        U 5      [        U 5      -  m[        U4S jU  5       5      [        U 5      -  S-  $ )zReturn standard deviation.r   c              3   2   >#    U  H  oT-
  S -  v   M     g7f)r   Nru  )r"  r  means     r,   r$  %standard_deviation.<locals>.<genexpr>  s     1ATas   g      ?)r|   r)  ry   )numbersr  s    @r,   r{  r{    sK    7mGw<#g,&D111L   r.   c                 @    [         R                   H
  nX;   d  M
    g   g)z6Return True if line contains any arithmetic operators.TF)r    ARITHMETIC_OP)r+   operators     r,   r|  r|    s     -- . r.   c                 ~    SnS H4  u  p#U[        U R                  U5      U R                  U5      -
  5      -  nM6     U$ )z/Return number of unmatched open/close brackets.r   rt  )rJ  r!  )r+   r!  r  r  s       r,   r}  r}    sA    E.TZZ(4::g+>>?? / Lr.   c                     / nSnSn[        U5       H:  nU[        U 5      :  a&  X4:w  a!  UR                  XU R                  5       5        UnM<     UR                  XS 5        U$ )z1Split line at offsets.

Return list of strings.

r   N)r   ry   rx   r  )r+   r  r   previous_offsetcurrent_offsets        r,   r  r  $  si     FON /CI%/*KMM$~>DDFG( *
 MM$'(Mr.   c                   *    \ rS rSrSrS rS rS rSrg)r  i8  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                     Xl         g rx  )_LineEndingWrapper__output)r   r  s     r,   r   LineEndingWrapper.__init__A  s    r.   c                 z    U R                   R                  UR                  SS5      R                  SS5      5        g )Nr   r
   r	   )r  r  rW  )r   ss     r,   r  LineEndingWrapper.writeD  s,    AIIfd3;;D$GHr.   c                 8    U R                   R                  5         g rx  )r  r  r  s    r,   r  LineEndingWrapper.flushG  s    r.   )__outputN)	r&   rR  rS  rT  rU  r   r  r  rW  ru  r.   r,   r  r  8  s    Ir.   r  c                 `   [         R                  R                  U 5      nUR                  S5      (       a  gU H=  n[        R                  " X#5      (       a    g[        R                  " X5      (       d  M=    g   [         R                  R                  U 5      (       d  [        U 5      (       d  gg)z4Return True if file is okay for modifying/recursing.r  FT)rN  rO  basenamerS   fnmatchisdiris_python_file)r9   r7  	base_namer  s       r,   
match_filer  K  s}      *IC  ??9..??8--	  77=="">(+C+Cr.   c              #     #    U (       GaE  U R                  S5      nU(       a  [        R                  R                  U5      (       a  [        R                  " U5       H  u  pEnX Vs/ s HR  n[        [        R                  R                  XG5      U5      (       d  M3  [        R                  R                  XG5      PMT     sn-  n U Vs/ s H5  n[        [        R                  R                  XH5      U5      (       d  M3  UPM7     snUSS& M     O5Sn	U H"  n
[        R                  " X:5      (       d  M   Sn	  O   U	(       d  Uv   U (       a  GMD  ggs  snf s  snf 7f)zYield filenames.r   NFT)rz   rN  rO  r  walkr  r   r  )	filenamesr5  r7  r  rootdirectorieschildrenfr   is_exclude_matchr  s              r,   
find_filesr  ^  s    
}}Qt,,/1wwt}+8X 6X!+BGGLL,A,3"5 4bggll43X 6 6	 .9 ":[%/T0E07&9 #$[ ":A	 0=  %"??411'+$ # $
# )6":s6   A%E'2E#E 	E	2E?E+E4EEc                     U S   R                   (       a*  [        SR                  U S   5      [        R                  S9   [        U 6 $ ! [         a(  n[        [        U5      [        R                  S9  UeSnAff = f)z>Helper function for optionally running fix_file() in parallel.r   z	[file:{}]r   r   N)r  r  rU   r  r	  r  IOErrorrt   )r  r   s     r,   	_fix_filer  t  sc    !}k  A/cjjA$$ c%jszz*s    A 
A:#A55A:c                 "   / n[        XR                  UR                  5      n UR                  S:  Ga  SSKnUR                  UR                  5      n/ nU  H,  nUR                  [        Xq445      nUR                  U5        M.     UR                  5         UR                  5         UR                  (       ab  U H\  n	[        R                  R                  U	R                  5       R!                  5       5        [        R                  R#                  5         M^     UR%                  U V
s/ s H  oc  M  U
R                  5       PM     sn
5        U$ U  H  n[        XqU45      nUc  M  UR                  (       a  US:w  a  UR                  U5        M?  MA  UR&                  (       a  UR                  U5        Me  [)        U5      nSR                  U5      R+                  5       UR+                  5       :w  d  M  UR                  U5        M     U$ s  sn
f )z7Fix list of files.

Optionally fix files recursively.

r   r   Nr2   )r  r5  r7  r  r8  Poolapply_asyncr  rx   closer   r  r  stdoutr  rs   r  r  rB  r  rP   rm  )r  r   r  r  r8  poolretsr  r  r+  r  r   s               r,   fix_multiple_filesr    s    G9&7&7II||a##GLL1D""9.@ACKK  	

		<<

  !12

  "  	?A?@ N DTF34C{||"9NN3' !!s#"5d";77?+668CNN<LLNN3'  N @s   )H3Hc                 X   U R                  S5      (       a  g [        U [        S9 nUR                  [        5      nU(       d
   SSS5        gUR	                  5       S   nSSS5        [        R                  W5      (       d  gg! , (       d  f       N*= f! [
        [        4 a     gf = f)z'Return True if filename is Python file.z.pyTr0   NFr   )	rk   r:   MAX_PYTHON_FILE_DETECTION_BYTESrI   rm  r  
IndexErrorPYTHON_SHEBANG_REGEXrE   )r9   r  r   
first_lines       r,   r  r    s    	!@BEF669:DB B *1-JB  %%j11B B Z  s:   B BB B!B 
BB B B)(B)c                 p    SU ;   =(       d+    SU ;   =(       d    U R                  5       R                  S5      $ )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.

ru  z'''r  )r}   rk   r^  s    r,   r  r    s5     	 	%	%t$r.   c                 |    [         R                  " U5      " [        U S5      (       a  U R                  5      $ U 5      $ )z&Return output with specified encoding.buffer)codecs	getwriterr   r  )r  r4   s     r,   r  r    s=    H%)0)B)B '-mm 3 3+13 3r.   c                  d    [         R                  " 5       =(       d    [        R                  " 5       $ )zReturn preferred encoding.)localegetpreferredencodingr  getdefaultencodingru  r.   r,   r  r    s    &&(DC,B,B,DDr.   c                    U c  [         R                  n  [        R                  " [        R                  [        R                  5         [        U SS US9nUR                  (       a:  [        [        5       5       H  u  p4[        SR                  X4S95        M     [        $ UR                  S/:X  a  UR                  (       a   e[         R                  R                   =(       d
    [#        5       n[         R                  R%                  5       n['        XbUS9n[)        [         R*                  US9R-                  U5        [/        U5      [/        U5      :w  a  UR0                  (       a  [2        $ ggUR                  (       d  UR4                  (       a$  [7        [9        UR                  5      5      Ul        O.[;        UR                  5      S:X  d   eUR<                  (       a   e[?        UR                  U[         R*                  5      nUR4                  (       a)  [A        U V	s/ s H  n	[;        U	5      S:g  PM     sn	5      n	O[A        U V	s/ s H  oSLPM     sn	5      n	UR0                  (       a  U	(       a  [2        $ gg! [
         a     GNEf = fs  sn	f s  sn	f ! [B         a	    [D        s $ [F         a	    [D        s $ f = f)	zCommand-line entry.Nr   r  z{code} - {description})rp  r  r   rH   r   )$r  argvsignalSIGPIPESIG_DFLr]  r  r0  r   rp  r  rU   EXIT_CODE_OKr  r  stdinr4   r  rI   r  r  r  r  r  	exit_codeEXIT_CODE_EXISTS_DIFFr  r|   r   ry   r5  r  r  r  EXIT_CODE_ERRORKeyboardInterrupt)
r  r  r-  rp  r  r4   
read_stdinfixed_stdinr  r  s
             r,   mainr    s   |xxfnnfnn5
)$qr(>??%+O,=%>!.55 6 8 9 &?  ::#}}$$yy));\^H)J":hGK 

X6<<[IJ4#44>>00 " 5 }}		!#djj/2
4::!+++>>))(T3::FGyyG<GS3s8q=G<= g>gsd?g>?~~#,, #&~Q  H = ?   sV   3J  	AJ !CJ 0B3J #J;J J$J  
JJ
J J?-J?>J?c                   $    \ rS rSrSrS rS rSrg)CachedTokenizeri  zrA one-element cache around tokenize.generate_tokens().

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

c                      S U l         S U l        g rx  	last_textlast_tokensr  s    r,   r   CachedTokenizer.__init__  s    r.   c                     XR                   :w  aJ  [        R                  " U5      n[        [        R
                  " UR                  5      5      U l        Xl         U R                  $ )z*A stand-in for tokenize.generate_tokens().)r  r7   r   r|   rm   rZ  readliner  )r   r   	string_ios      r,   rZ  CachedTokenizer.generate_tokens  sN    >>!D)I#((););< D "Nr.   r  N)r&   rR  rS  rT  rU  r   rZ  rW  ru  r.   r,   r  r    s      r.   r  __main__rx  )r+  Nr]   )r]   )r  r  r   FFr}  )r   Fr2   )r   r2   )T)NNFr.  )globalr2   N)NT)rU  rb  r   r   r   r   r  r  r  r   r  r  	importlibr  r7   r  r  r  rN  r  r  r  r  r  rm   r  rc  configparserr   rM  r   r    r  r  r  r  rZ  r  r  r  r  r  r  r~  rh  ri  r?   r  r  r  r  r  r1  	frozensetr  r
  rl   r  platformrO  
expanduserr	  r   getenvrP  rU  r  r  r  r-   r:   rt   rF   r6   rP   r[   r   reload_checksregister_checkr~  r   r  r  r  r  r  r  r   r  r  r  r  r  r-  r   r9  r  r   r  r  r,  
namedtupler  r   r0  r  r  r  r  rj  rk  r  r  r	  r  r  r  r  rR  r&  r6  r  r@  rC  r[  rf  rt  rw  r(  r:  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r"  r  r/  r'  r  rJ  r3  r4  r6  r2  rp  r  r  r{  r|  r}  r  r  r  r  r  r  r  r  r  r  r  r  _cached_tokenizerrZ  r&   r&  ru  r.   r,   <module>r     s  d	 '  % '         	    	 	  
     
 @   
	 zz"=> zzBC$JK !#,F!G JJ}- zz">? 

#=> zz34

565  ZZ6  ZZ:;
   $sese"#"#AB-.%   %  % <<7WW''(9:NWW\\")),="> #B"$''"4"4["A"/1N 
ww~~n%%
||w++J7bgg&8&8&EvN= #'   w#/ "
&=*|:B 
   '(I(IJ   / 0   0 1W6f W6t"Rj  =?BG-`878(4.'&HG(
(  H BD#N /1K*\* 	w )A 	B` v ` FZ,6 Z,zW Wt
I 

9 

	 
	 ;9 ;
8vB'T8L^)>(&#/L A AH0fDBDCL$N$N F."720'NT,^
'/ BD!!H"
FR#L"##"+."58"	"[|!(0f6rH
8I09 ',Qh ( &&,$N,3E
5p f  . $% #33 zHHTV r.   