
    F\h-                         S r SrSSKrSSKrSSKr/ SQrSqSqS rS r	 " S S\
5      rS	 r " S
 S5      rS rS rS r\S:X  a  \	" 5         gg)a  The Tab Nanny despises ambiguous indentation.  She knows no mercy.

tabnanny -- Detection of ambiguous indentation

For the time being this module is intended to be called as a script.
However it is possible to import it into an IDE and use the function
check() described below.

Warning: The API provided by this module is likely to change in future
releases; such changes may not be backward compatible.
6    N)checkNannyNagprocess_tokensc                      SnU  H0  n[         R                  R                  U[        U5      -   5        SnM2     [         R                  R                  S5        [         R                  " S5        g )N  
   )sysstderrwritestrexit)argssepargs      /usr/lib/python3.13/tabnanny.pyerrprintr       sO    
C

s3x(  JJTHHQK    c                  p   SS K n  U R                  [        R                  SS  S5      u  pW H%  u  pEUS:X  a	  [
        S-   qUS:X  d  M  [        S-   qM'     W(       d  [	        S[        R                  S   S5        U H  n[        U5        M     g ! U R                   a  n[	        U5         S nANS nAff = f)Nr   r   qvz-qz-vzUsage:z[-v] file_or_directory ...)getoptr   argverrorr   filename_onlyverboser   )r   optsr   msgoar   s          r   mainr"   (   s    ]]388AB<6
 9)A-M9kG	 
 388A;(DEc
  << s   %B B5 B00B5c                   0    \ rS rSrSrS rS rS rS rSr	g)	r   :   z_
Raised by process_tokens() if detecting an ambiguous indent.
Captured and handled in check().
c                 .    XUsU l         U l        U l        g N)linenor   line)selfr'   r   r(   s       r   __init__NannyNag.__init__?   s    +1(TXtyr   c                     U R                   $ r&   )r'   r)   s    r   
get_linenoNannyNag.get_linenoA   s    {{r   c                     U R                   $ r&   )r   r-   s    r   get_msgNannyNag.get_msgC   s    xxr   c                     U R                   $ r&   )r(   r-   s    r   get_lineNannyNag.get_lineE   s    yyr   )r(   r'   r   N)
__name__
__module____qualname____firstlineno____doc__r*   r.   r1   r4   __static_attributes__ r   r   r   r   :   s    =r   r   c                    [         R                  R                  U 5      (       a  [         R                  R                  U 5      (       d  [        (       a  [        U < S35        [         R                  " U 5      nU H  n[         R                  R                  X5      n[         R                  R                  U5      (       a$  [         R                  R                  U5      (       a(  [         R                  R                  USS 5      S:X  d  M  [        U5        M     g [        R                  " U 5      n[        S:  a  [        SU -  5         [        [        R                  " UR                   5      5         UR%                  5         [        (       a  [        U < S35        gg! [         a  n[        U < SU< 35         SnAgSnAff = f! [        R"                   a,  n[        U < SU< 35         SnAUR%                  5         gSnAf[&         a,  n[        U < S	U< 35         SnAUR%                  5         gSnAf[(         a,  n[        U < S
U< 35         SnAUR%                  5         gSnAf[*         a  nUR-                  5       nUR/                  5       n[        (       a8  [        SX4-  5        [        SU< 35        [        UR1                  5       5        O:SU ;   a  SU -   S-   n [2        (       a  [        U 5        O[        X[5        U5      5         SnAUR%                  5         gSnAff = f! UR%                  5         f = f)af  check(file_or_dir)

If file_or_dir is a directory and not a symbolic link, then recursively
descend the directory tree named by file_or_dir, checking all .py files
along the way. If file_or_dir is an ordinary Python source file, it is
checked for whitespace related problems. The diagnostic messages are
written to standard output using the print statement.
z: listing directoryNz.pyz: I/O Error: r   zchecking %r ...z: Token Error: z: Indentation Error: z: Syntax Error: z)%r: *** Line %d: trouble in tab city! ***zoffending line: r	   "z: Clean bill of health.)ospathisdirislinkr   printlistdirjoinnormcaser   tokenizeopenOSErrorr   r   generate_tokensreadline
TokenErrorcloseIndentationErrorSyntaxErrorr   r.   r4   r1   r   repr)	filenamesnamefullnamefr   nagbadliner(   s	            r   r   r   H   sP    
ww}}T277>>$#7#77T34

4 Dww||D/Hh''GGNN8,,  bc+u4h  	MM$
 {$&'x//

;<8 	
	wT34 M  c23  $450 	
	-  c:;( 	
	%  456  	
	  .."||~7=OP$01#++- d{3:#3D}eDktDz2 	
	 	
	sy   F# )G #
G	-GG	L3 H2L6 L3H;&L6 ;L3I/L6 /L3<BL.L6 .L33L6 6Mc                   H    \ rS rSrSu  rrS rS rS rS r	S r
S rS	 rS
rg)
Whitespace   z 	c                    Xl         [        R                  [        R                  p2/ nS=n=pgU R                    HW  nX:X  a  US-   nUS-   nM  X:X  a>  US-   nUS-   nU[	        U5      :  a  US/U[	        U5      -
  S-   -  -   nXE   S-   XE'   SnMW    O   X`l        Xpl        [        U5      U4U l        [	        U5      S:*  U l	        g )Nr   r   )
rawrZ   STlennnttuplenorm	is_simple)	r)   wsr^   r_   countbra   rb   chs	            r   r*   Whitespace.__init__   s    ||Z\\1A((BwEEE!VE
?!QC1s5z>A+=$>>E 8a<  %L!O	Uqr   c                 N    U R                   u  p[        [        U5      S-
  U5      $ Nr   )rd   maxr`   )r)   rg   trailings      r   longest_run_of_spaces Whitespace.longest_run_of_spaces   s"    ))3u:a<**r   c                     U R                   u  p#Sn[        U[        U5      5       H  nXEU-  X%   -  -   nM     X1X@R                  -   -  -   $ )Nr   )rd   ranger`   rb   )r)   tabsizerg   rn   ilis         r   indent_levelWhitespace.indent_level   sP     ))wE
+Aj58++B ,R''\222r   c                 4    U R                   UR                   :H  $ r&   )rd   )r)   others     r   equalWhitespace.equal   s    yyEJJ&&r   c                 <   [        U R                  5       UR                  5       5      S-   n/ n[        SUS-   5       H[  nU R                  U5      UR                  U5      :w  d  M)  UR	                  UU R                  U5      UR                  U5      45        M]     U$ rl   rm   ro   rr   rv   appendr)   ry   ra   r!   tss        r   not_equal_witnessWhitespace.not_equal_witness       **,++-/1231Q3-B  $(:(:2(>>2,,R0 --b13 5  
 r   c                 ~   U R                   UR                   :  a  gU R                  (       a*  UR                  (       a  U R                  UR                  :*  $ [        U R	                  5       UR	                  5       5      S-   n[        SUS-   5       H)  nU R                  U5      UR                  U5      :  d  M)    g   g)NFr      T)ra   re   rb   rm   ro   rr   rv   )r)   ry   ra   r   s       r   lessWhitespace.less   s    66UWW>>eoo77ehh&&**,++-/123 1Q3-B  $(:(:2(>>   r   c                 <   [        U R                  5       UR                  5       5      S-   n/ n[        SUS-   5       H[  nU R                  U5      UR                  U5      :  d  M)  UR	                  UU R                  U5      UR                  U5      45        M]     U$ rl   r}   r   s        r   not_less_witnessWhitespace.not_less_witness  r   r   )re   ra   rd   rb   r]   N)r6   r7   r8   r9   r^   r_   r*   ro   rv   rz   r   r   r   r;   r<   r   r   rZ   rZ      s.    DAq*)2+3.'	0"	r   rZ   c                 n    S U  5       nSn[        U 5      S:  a  US-   nUS-   SR                  U5      -   $ )Nc              3   >   #    U  H  n[        US    5      v   M     g7f)r   N)r   ).0tups     r   	<genexpr>#format_witnesses.<locals>.<genexpr>  s     'Qcc#a&kkQs   zat tab sizer   sr	   z, )r`   rF   )wfirstsprefixs      r   format_witnessesr     s=    'Q'FF
1vz#C<$))F+++r   c                      [        U 5        g ! [         a0  n[        UR                  UR                  UR
                  5      eS nAff = fr&   )_process_tokensTabErrorr   r'   r   text)tokenses     r   r   r     s:    0 0qxx//0s    
A+AAc                    [         R                  n[         R                  n[         R                  n[         R                  [         R
                  4n[        S5      /nSnU  H  u  pxpnXs:X  a  SnM  Xq:X  aj  Sn[        U5      nUS   R                  U5      (       d1  US   R                  U5      nS[        U5      -   n[        U	S   X5      eUR                  U5        M  Xr:X  a  SnUS	 M  U(       d  M  Xt;  d  M  Sn[        U5      nUS   R                  U5      (       a  M  US   R                  U5      nS[        U5      -   n[        U	S   X5      e   g )Nr   r   r   zindent not greater e.g. zindent not equal e.g. )rH   INDENTDEDENTNEWLINECOMMENTNLrZ   r   r   r   r   r~   rz   r   )r   r   r   r   JUNKindentscheck_equaltypetokenstartendr(   thisguywitnessr   s                  r   r   r     sD   __F__FGX[[(D"~GK+1'e$? K^K 'G2;##G,,!"+66w?03CG3LLuQx33NN7#^ K[T- K &G2;$$W--!"+77@.1A'1JJuQx33Y ,2r   __main__)r:   __version__r@   r   rH   __all__r   r   r   r"   	Exceptionr   r   rZ   r   r   r   r6   r<   r   r   <module>r      sv   
$  	 
 
1
$y ?5BD DL,044n zF r   