i f,@sdZdZddlZddlZddlZddlZeedsZedndddgZda da d d Z d d Z Gd dde ZddZGdddZddZddZedkre ndS)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/python34/lib64/python3.4/tabnanny.pyerrprint#s   rcCsy)tjtjddd\}}Wn6tjk ra}zt|dSWYdd}~XnXxF|D]>\}}|dkrtdan|dkritdaqiqiW|stdtjdddSx|D]}t|qWdS)NZqvz-qz-vzUsage:rz[-v] file_or_directory ...)getoptr argverrorr filename_onlyverboser)Zoptsrmsgoarrrrmain*s)     rc@sFeZdZdZddZddZddZdd Zd S) rzg Raised by tokeneater() 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|fntj|}xw|D]o}tjj||}tjj|rtjj| stjj|dddkrUt |qUqUWdSyt j |}Wn=t k r}zt d||fdSWYdd}~XnXtdkr<td|nzaytt j|jWn@t jk r}zt d||fdSWYdd}~Xntk r}zt d ||fdSWYdd}~Xntk r}z|j}|j}tr?td ||ftd |ft|jnFd |kr\d |d }ntrot|nt||t|dSWYdd}~XnXWd|jXtrtd|fndS)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}n||d||sz#format_witnesses..z at tab sizersrz, )rGr2)wZfirstsprefixrrrformat_witnesses s  rdcCstj}tj}tj}tjtjf}tdg}d}xA|D]9\}}} } } ||krsd}qI||krd}t|} |dj| s|dj| } dt | }t | d|| n|j | qI||kr d}|d=qI|rI||krId}t| } |d j | s|d j | } dt | }t | d|| qqIqIWdS) 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