B JO˻ @ s d Z dZddlZddlZddlZeeds2eddddgZdada d d Z dd ZG d d deZ dd ZG dd dZdd Zdd Zedkre dS )a The 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. 6 NNLz4tokenize.NL doesn't exist -- tokenize module too oldcheckNannyNagprocess_tokensc G s: d}x$| D ]}t j|t| d}q W t jd d S )N )sysstderrwritestr)argsseparg r -/opt/alt/python37/lib64/python3.7/tabnanny.pyerrprint" s r c C s dd l } y| tjdd d\}}W n, | jk rR } zt| d S d }~X Y nX x0|D ](\}}|dkrrtd a|dkrZtd aqZW |stdtjd d d S x|D ]}t| qW d S )Nr Zqvz-qz-vzUsage:z[-v] file_or_directory ...)getoptr argverrorr filename_onlyverboser )r Zoptsr msgoar r r r main) s r c @ s0 e Zd ZdZdd Zdd Zdd Zdd Zd S )r zk Raised by process_tokens() if detecting an ambiguous indent. Captured and handled in check(). c C s ||| | _ | _| _d S )N)linenor line)selfr r r r r r __init__B s zNannyNag.__init__c C s | j S )N)r )r r r r get_linenoD s zNannyNag.get_linenoc C s | j S )N)r )r r r r get_msgF s zNannyNag.get_msgc C s | j S )N)r )r r r r get_lineH s zNannyNag.get_lineN)__name__ __module____qualname____doc__r! r" r# r$ r r r r r = s c C s& t j| rt j| str*td| f t | }xR|D ]J}t j| |}t j|rdt j|r|t j|dd dkr:t | q:W dS yt | }W n2 tk r } zt d| |f dS d}~X Y nX tdkrtd| zytt |j W n t jk r2 } zt d| |f dS d}~X Y n tk rd } zt d | |f dS d}~X Y n tk r } z|| }| }trtd | |f td|f t| n6d| krd | d } trt| nt| |t| dS d}~X Y nX W d| X tr"td| f dS )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: %sr zchecking %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.)ospathisdirislinkr printlistdirjoinnormcaser tokenizeopenOSErrorr r generate_tokensreadline TokenErrorIndentationErrorr r" r$ r# r reprclose) filenamesnamefullnamefr Znagbadliner r r r r K sT c @ sL e Zd Zd\ZZdd Zdd Zdd Zdd Zd d Z dd Z dd ZdS ) Whitespacez c C s || _ tjtj }}g }d } }}x~| j D ]t}||krJ|d }|d }q,||kr|d }|d }|t|kr|dg|t| d }|| d ||<