U AT^,c@sdZdZddlZddlZddlZeeds2eddddgZdada d d Z d d Z Gd dde Z ddZGdddZddZddZedkre dS)aThe 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. Z6NNLz4tokenize.NL doesn't exist -- tokenize module too oldcheckNannyNagprocess_tokenscGs6d}|D]}tj|t|d}qtjddS)N Z )sysZstderrZwritestr)argsZsepargr /usr/lib64/python3.8/tabnanny.pyerrprint"s r c Csddl}z|tjddd\}}Wn2|jk rX}zt|WYdSd}~XYnX|D](\}}|dkrvtda|dkr^tdaq^|stdtjdddS|D] }t|qdS)NrZqvz-qz-vzUsage:z[-v] file_or_directory ...)getoptrZargvZerrorr filename_onlyverboser)rZoptsr msgZoar r r r main)s   rc@s0eZdZdZddZddZddZdd Zd S) rzk Raised by process_tokens() if detecting an ambiguous indent. Captured and handled in check(). cCs||||_|_|_dSN)linenorline)selfrrrr r r __init__BzNannyNag.__init__cC|jSr)rrr r r get_linenoDrzNannyNag.get_linenocCrr)rrr r r get_msgFrzNannyNag.get_msgcCrr)rrr r r get_lineHrzNannyNag.get_lineN)__name__ __module__ __qualname____doc__rrrrr r r r r=s c CsHtj|rtj|str*td|ft|}|D]J}tj||}tj|rbtj|rztj|dddkr8t |q8dSzt |}Wn8t k r}zt d||fWYdSd}~XYnXtdkrtd|z>ztt |jWn"t jk r@}z t d||fWY WdSd}~XYntk r|}zt d ||fWYWdSd}~XYntk r }z|}|}trtd ||ftd |ft|n6d |krd |d }trt|nt||t|WYWdSd}~XYnXW5|XtrDtd|fdS)a~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%r: listing directoryiNz.pyz%r: I/O Error: %srzchecking %r ...z%r: Token Error: %sz%r: Indentation Error: %sz)%r: *** Line %d: trouble in tab city! ***zoffending line: %rrz"z%r: Clean bill of health.)osZpathZisdirZislinkrZprintZlistdirjoinZnormcasertokenizeZopenZOSErrorr ZcloserZgenerate_tokensZreadlineZ TokenErrorZIndentationErrorrrrrrZrepr) ZfileZnamesZnameZfullnameZfrZnagZbadlinerr r r rKsX          c@sLeZdZd\ZZddZddZddZdd Zd d Z d d Z ddZ dS) Whitespacez c Cs||_tjtj}}g}d}}}|jD]v}||krH|d}|d}q*||kr|d}|d}|t|kr|dg|t|d}||d||<d}q*qq*||_||_t||f|_t|dk|_ dS)Nrr) Zrawr'STlennntZtuplenorm is_simple) rZwsr(r)countZbr+r,Zchr r r rs(    zWhitespace.__init__cCs|j\}}tt|d|SNr)r-maxr*)rr/trailingr r r longest_run_of_spacess z Whitespace.longest_run_of_spacescCsH|j\}}d}t|t|D]}|||||}q||||jS)Nr)r-ranger*r,)rZtabsizer/r2ZilZir r r indent_levels  zWhitespace.indent_levelcCs |j|jkSr)r-)rotherr r r equalrzWhitespace.equalcCsbt||d}g}td|dD]4}||||kr(||||||fq(|Sr0r1r3r4r5appendrr6r+rtsr r r not_equal_witnesszWhitespace.not_equal_witnesscCsp|j|jkrdS|jr(|jr(|j|jkSt||d}td|dD]}||||krLdSqLdS)NFriT)r+r.r,r1r3r4r5)rr6r+r;r r r lesss   zWhitespace.lesscCsbt||d}g}td|dD]4}||||kr(||||||fq(|Sr0r8r:r r r not_less_witnessr=zWhitespace.not_less_witnessN) r r!r"r(r)rr3r5r7r<r>r?r r r r r'sr'cCs8dd|D}d}t|dkr&|d}|dd|S)Ncss|]}t|dVqdS)rN)r)Z.0Ztupr r r Z sz#format_witnesses..z at tab sizerZsrz, )r*r%)ZwZfirstsZprefixr r r format_witnessess  r@cCstj}tj}tj}tjtjf}tdg}d}|D]\}}} } } ||krLd}q0||krd}t|} |d| s|d| } dt | }t | d|| | | q0||krd}|d=q0|r0||kr0d}t| } |d | s0|d | } dt | }t | d|| q0dS)Nrrrizindent not greater e.g. zindent not equal e.g. )r&INDENTDEDENTNEWLINEZCOMMENTrr'r>r?r@rr9r7r<)ZtokensrArBrCZJUNKZindentsZ check_equalZtypeZtokenZstartZendrZthisguyZwitnessrr r r rs6       Z__main__)r#Z __version__r$rr&ZhasattrZ ValueErrorZ__all__rrr rZ Exceptionrrr'r@rr r r r r Zs&  =7