Yf,@sdZdZddlZddlZddlZddlZeedsWeddddgZda da d d Z d d Z Gd dde ZddZGdddZddZddZedkre 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_tokenscGsKd}x.|D]&}tjj|t|d}q WtjjddS)N  )sysstderrwritestr)argssepargr-/opt/alt/python35/lib64/python3.5/tabnanny.pyerrprint#s   rcCsy)tjtjddd\}}Wn6tjk ra}zt|dSWYdd}~XnXx@|D]8\}}|dkrtda|dkritdaqiW|stdtjdddSx|D]}t|qWdS)NZqvz-qz-vzUsage:rz[-v] file_or_directory ...)getoptr argverrorr filename_onlyverboser)Zoptsrmsgoarrrrmain*s)     rc@sFeZdZdZddZddZddZdd Zd S) rzk Raised by process_tokens() if detecting an ambiguous indent. Captured and handled in check(). cCs!||||_|_|_dS)N)linenorline)selfrrrrrr__init__AszNannyNag.__init__cCs|jS)N)r)r rrr get_linenoCszNannyNag.get_linenocCs|jS)N)r)r rrrget_msgEszNannyNag.get_msgcCs|jS)N)r)r rrrget_lineGszNannyNag.get_lineN)__name__ __module__ __qualname____doc__r!r"r#r$rrrrr<s    c %Cstjj|rtjj| rtr<td|ftj|}xt|D]l}tjj||}tjj|rtjj| stjj|dddkrRt |qRWdSyt j |}Wn=t k r}zt d||fdSWYdd}~XnXtdkr3td|z^ytt j|jWn=t jk r}zt d||fdSWYdd}~Xntk r}zt d ||fdSWYdd}~Xntk r}z|j}|j}tr6td ||ftd |ft|jnCd |krPd |d }trct|nt||t|dSWYdd}~XnXWd|jXtrtd|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.)ospathisdirislinkrprintlistdirjoinnormcasertokenizeopenOSErrorrrgenerate_tokensreadline TokenErrorIndentationErrorrr"r$r#rreprclose) filenamesnamefullnamefrZnagbadlinerrrrrJsT % "      c@speZdZd\ZZddZddZddZdd Zd d Z d d Z ddZ dS) Whitespacez c Cs||_tjtj}}g}d}}}x|jD]}||krc|d}|d}q:||kr|d}|d}|t|kr|dg|t|d}||d||sz#format_witnesses..z at tab sizersrz, )rGr2)wZfirstsprefixrrrformat_witnesses s  rdcCstj}tj}tj}tjtjf}tdg}d}x8|D]0\}}} } } ||krsd}qI||krd}t|} |dj| s|dj| } dt | }t | d|| |j | qI||kr d}|d=qI|rI||krId}t| } |d j | sI|d j | } dt | }t | d|| qIWdS) Nrrrzindent not greater e.g. zindent not equal e.g. rererere)r4INDENTDEDENTNEWLINECOMMENTrrCr\r]rdrrXrWrZ)tokensrfrgrhZJUNKindentsZ check_equaltypetokenstartendrZthisguyZwitnessrrrrrs6          __main__)r( __version__r,r rr4hasattr ValueError__all__rrrr ExceptionrrrCrdrr%rrrr s&        =  7