o w[e#,@sdZdZddlZddlZddlZgdZdadaddZddZ Gd d d e Z d d Z Gd ddZ ddZddZedkrDe dSdS)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. 6N)checkNannyNagprocess_tokenscGs6d}|D]}tj|t|d}qtjddS)N  )sysstderrwritestr)argssepargr/usr/lib/python3.10/tabnanny.pyerrprint s rc Csddl}z|tjddd\}}Wn|jy+}z t|WYd}~dSd}~ww|D]\}}|dkr:tda|dkrBtdaq.|sPtdtjdddS|D]}t|qRdS)Nrqvz-qz-vzUsage:z[-v] file_or_directory ...)getoptr argverrorr filename_onlyverboser)roptsr msgoarrrrmain's(  rc@s0eZdZdZddZddZddZdd Zd S) rzk Raised by process_tokens() if detecting an ambiguous indent. Captured and handled in check(). cCs||||_|_|_dSN)linenorline)selfr rr!rrr__init__@szNannyNag.__init__cC|jSr)r r"rrr get_linenoBzNannyNag.get_linenocCr$r)rr%rrrget_msgDr'zNannyNag.get_msgcCr$r)r!r%rrrget_lineFr'zNannyNag.get_lineN)__name__ __module__ __qualname____doc__r#r&r(r)rrrrr;s  rc CsNtj|rDtj|sDtrtd|ft|}|D]%}tj||}tj|r1tj|r=tj|dddkrAt |qdSzt |}Wnt yf}zt d||fWYd}~dSd}~wwtdkrqtd|zz tt |jWnt jy}zt d||fWYd}~W|dSd}~wty}zt d ||fWYd}~W|dSd}~wty }zE|}|}trtd ||ftd |ft|nd |vrd |d }trt|nt||t|WYd}~W|dSd}~wwW|n|wtr%td|fdSdS)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.)ospathisdirislinkrprintlistdirjoinnormcasertokenizeopenOSErrorrrgenerate_tokensreadline TokenErrorcloseIndentationErrorrr&r)r(rrepr) filenamesnamefullnamefrnagbadliner!rrrrIsj           rc@sLeZdZd\ZZddZddZddZdd Zd d Z d d Z ddZ dS) Whitespacez c Cs||_tjtj}}g}d}}}|jD]9}||kr$|d}|d}q||krN|d}|d}|t|krC|dg|t|d}||d||<d}q||_||_t||f|_t|dk|_ dS)Nrr) rawrHSTlennnttuplenorm is_simple) r"wsrJrKcountbrMrNchrrrr#s(    zWhitespace.__init__cCs|j\}}tt|d|SNr)rPmaxrL)r"rStrailingrrrlongest_run_of_spacess z Whitespace.longest_run_of_spacescCsH|j\}}d}t|t|D] }|||||}q||||jS)Nr)rPrangerLrN)r"tabsizerSrXilirrr indent_levels zWhitespace.indent_levelcCs |j|jkSr)rP)r"otherrrrequals zWhitespace.equalcCsbt||d}g}td|dD]}||||kr.||||||fq|SrVrWrYrZr^appendr"r_rMrtsrrrnot_equal_witnesszWhitespace.not_equal_witnesscCsp|j|jkrdS|jr|jr|j|jkSt||d}td|dD]}||||kr5dSq&dS)NFrT)rMrQrNrWrYrZr^)r"r_rMrdrrrlesss   zWhitespace.lesscCsbt||d}g}td|dD]}||||kr.||||||fq|SrVrarcrrrnot_less_witnessrfzWhitespace.not_less_witnessN) r*r+r,rJrKr#rYr^r`rerhrirrrrrHs rHcCs8dd|D}d}t|dkr|d}|dd|S)Ncss|] }t|dVqdS)rN)r ).0tuprrr sz#format_witnesses..z at tab sizersrz, )rLr6)wfirstsprefixrrrformat_witnesses s  rqcCstj}tj}tj}tjtjf}tdg}d}|D]l\}}} } } ||kr&d}q||krRd}t|} |d| sL|d| } dt | }t | d|| | | q||kr\d}|d=q|r||vrd}t| } |d | s|d | } dt | }t | d|| qdS)Nrrrzindent not greater e.g. zindent not equal e.g. )r8INDENTDEDENTNEWLINECOMMENTNLrHrhrirqrrbr`re)tokensrsrtruJUNKindents check_equaltypetokenstartendr!thisguywitnessrrrrrs:       r__main__)r- __version__r0r r8__all__rrrr ExceptionrrrHrqrr*rrrrs&=7