U AT^,@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. 6NNLz4tokenize.NL doesn't exist -- tokenize module too oldcheckNannyNagprocess_tokenscGs6d}|D]}tj|t|d}qtjddS)N  )sysstderrwritestr)argssepargr /usr/lib64/python3.8/tabnanny.pyerrprint"s rc 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 ...)getoptr argverrorr filename_onlyverboser)rZoptsrmsgoarrrrmain)s   rc@s0eZdZdZddZddZddZdd Zd S) rzk Raised by process_tokens() if detecting an ambiguous indent. Captured and handled in check(). cCs||||_|_|_dSN)linenorline)selfrrr rrr__init__BszNannyNag.__init__cCs|jSr)rr!rrr get_linenoDszNannyNag.get_linenocCs|jSr)rr#rrrget_msgFszNannyNag.get_msgcCs|jSr)r r#rrrget_lineHszNannyNag.get_lineN)__name__ __module__ __qualname____doc__r"r$r%r&rrrrr=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 directoryNz.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: %rr"z%r: Clean bill of health.)ospathisdirislinkrprintlistdirjoinnormcasertokenizeopenOSErrorrclosergenerate_tokensreadline TokenErrorIndentationErrorrr$r&r%rrepr) filenamesnamefullnamefrZnagbadliner rrrrKsX          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) rawrDSTlennnttuplenorm is_simple) r!wsrFrGcountbrIrJZchrrrr"s(    zWhitespace.__init__cCs|j\}}tt|d|SNr)rLmaxrH)r!rOtrailingrrrlongest_run_of_spacess z Whitespace.longest_run_of_spacescCsH|j\}}d}t|t|D]}|||||}q||||jS)Nr)rLrangerHrJ)r!tabsizerOrSZilirrr indent_levels  zWhitespace.indent_levelcCs |j|jkSr)rL)r!otherrrrequalszWhitespace.equalcCsbt||d}g}td|dD]4}||||kr(||||||fq(|SrQrRrTrUrXappendr!rYrIrtsrrrnot_equal_witnessszWhitespace.not_equal_witnesscCsp|j|jkrdS|jr(|jr(|j|jkSt||d}td|dD]}||||krLdSqLdS)NFrT)rIrMrJrRrTrUrX)r!rYrIr^rrrlesss   zWhitespace.lesscCsbt||d}g}td|dD]4}||||kr(||||||fq(|SrQr[r]rrrnot_less_witnessszWhitespace.not_less_witnessN) r'r(r)rFrGr"rTrXrZr_rarbrrrrrDsrDcCs8dd|D}d}t|dkr&|d}|dd|S)Ncss|]}t|dVqdS)rN)r ).0tuprrr sz#format_witnesses..z at tab sizersrz, )rHr3)wZfirstsprefixrrrformat_witnessess  ricCstj}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)Nrrrzindent not greater e.g. zindent not equal e.g. )r5INDENTDEDENTNEWLINECOMMENTrrDrarbrirr\rZr_)tokensrkrlrmZJUNKindentsZ check_equaltypetokenstartendr ZthisguyZwitnessrrrrrs6       __main__)r* __version__r-r r5hasattr ValueError__all__rrrr ExceptionrrrDrirr'rrrrs&  =7