B
    u9a,                 @   s   d Z ddlZddlZddlZeeds.eddddgZdadadd	 Z	d
d Z
G dd deZdd ZG dd dZdd Zdd Zedkre
  dS )6    NNLz4tokenize.NL doesn't exist -- tokenize module too oldcheckNannyNagprocess_tokensc              G   s:   d}x$| D ]}t j|t|  d}q
W t jd d S )N  
)sysstderrwritestr)argsseparg r   /usr/lib/python3.7/tabnanny.pyerrprint"   s
    
r   c           
   C   s   dd l } y|  tjdd  d\}}W n, | jk
rR } zt| d S d }~X Y nX x0|D ](\}}|dkrrtd a|dkrZtd aqZW |stdtjd d d S x|D ]}t| qW d S )Nr      Zqvz-qz-vzUsage:z[-v] file_or_directory ...)getoptr
   argverrorr   filename_onlyverboser   )r   Zoptsr   msgoar   r   r   r   main)   s     
r   c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
r   c             C   s   |||  | _ | _| _d S )N)linenor   line)selfr   r   r   r   r   r   __init__B   s    zNannyNag.__init__c             C   s   | j S )N)r   )r    r   r   r   
get_linenoD   s    zNannyNag.get_linenoc             C   s   | j S )N)r   )r    r   r   r   get_msgF   s    zNannyNag.get_msgc             C   s   | j S )N)r   )r    r   r   r   get_lineH   s    zNannyNag.get_lineN)__name__
__module____qualname__r!   r"   r#   r$   r   r   r   r   r   =   s   c       	   
   C   s&  t j| rt j| str*td| f  t | }xR|D ]J}t j| |}t j|rdt j|r|t j|dd  dkr:t	| q:W d S yt
| }W n2 tk
r } ztd| |f  d S d }~X Y nX tdkrtd|   zytt
|j W n t
jk
r2 } ztd| |f  d S d }~X Y n tk
rd } ztd| |f  d S d }~X Y n tk
r } z|| }| }trtd	| |f  td
|f  t|  n6d| krd|  d } trt|  nt| |t| d S d }~X Y nX W d |  X tr"td| f  d S )Nz%r: listing directoryz.pyz%r: I/O Error: %sr   zchecking %r ...z%r: Token Error: %sz%r: Indentation Error: %sz)%r: *** Line %d: trouble in tab city! ***zoffending line: %rr   "z%r: Clean bill of health.)ospathisdirislinkr   printlistdirjoinnormcaser   tokenizeopenOSErrorr   r   generate_tokensreadline
TokenErrorIndentationErrorr   r"   r$   r#   r   reprclose)	filenamesnamefullnamefr   Znagbadliner   r   r   r   r   K   sT    



  

c               @   sL   e Zd Zd\ZZdd Zdd Zdd Zdd	 Zd
d Z	dd Z
dd ZdS )
Whitespacez 	c       	      C   s   || _ tjtj }}g }d } }}x~| j D ]t}||krJ|d }|d }q,||kr|d }|d }|t|kr|dg|t| d   }|| d ||< d}q,P q,W || _|| _t||f| _t|dk| _	d S )Nr   r   )
rawrA   STlennnttuplenorm	is_simple)	r    ZwsrC   rD   countbrF   rG   Zchr   r   r   r!      s(    
zWhitespace.__init__c             C   s   | j \}}tt|d |S )Nr   )rI   maxrE   )r    rK   trailingr   r   r   longest_run_of_spaces   s    
z Whitespace.longest_run_of_spacesc             C   sL   | j \}}d}x*t|t|D ]}||| ||   }qW |||| j   S )Nr   )rI   rangerE   rG   )r    tabsizerK   rN   Zilir   r   r   indent_level   s
    
zWhitespace.indent_levelc             C   s   | j |j kS )N)rI   )r    otherr   r   r   equal   s    zWhitespace.equalc             C   sf   t |  | d }g }xFtd|d D ]4}| |||kr*||| |||f q*W |S )Nr   )rM   rO   rP   rS   append)r    rT   rF   r   tsr   r   r   not_equal_witness   s    zWhitespace.not_equal_witnessc             C   sr   | j |j krdS | jr(|jr(| j|jkS t|  | d }x.td|d D ]}| |||krNdS qNW dS )NFr      T)rF   rJ   rG   rM   rO   rP   rS   )r    rT   rF   rW   r   r   r   less   s    zWhitespace.lessc             C   sf   t |  | d }g }xFtd|d D ]4}| |||kr*||| |||f q*W |S )Nr   )rM   rO   rP   rS   rV   )r    rT   rF   r   rW   r   r   r   not_less_witness  s    zWhitespace.not_less_witnessN)r%   r&   r'   rC   rD   r!   rO   rS   rU   rX   rZ   r[   r   r   r   r   rA      s   rA   c             C   s8   dd | D }d}t | dkr&|d }|d d| S )Nc             s   s   | ]}t |d  V  qdS )r   N)r   ).0tupr   r   r   	<genexpr>  s    z#format_witnesses.<locals>.<genexpr>zat tab sizer   sr   z, )rE   r0   )wZfirstsprefixr   r   r   format_witnesses  s
    rb   c             C   s  t j}t j}t j}t jt jf}tdg}d}x| D ]\}}}	}
}||krNd}q2||krd}t|}|d |s|d |}dt	| }t
|	d |||| q2||krd}|d= q2|r2||kr2d}t|}|d |s2|d |}dt	| }t
|	d ||q2W d S )Nr   r   r   zindent not greater e.g. zindent not equal e.g. )r2   INDENTDEDENTNEWLINECOMMENTr   rA   rZ   r[   rb   r   rV   rU   rX   )tokensrd   re   rf   ZJUNKindentsZcheck_equaltypetokenstartendr   ZthisguyZwitnessr   r   r   r   r     s6    

__main__)__version__r*   r
   r2   hasattr
ValueError__all__r   r   r   r   	Exceptionr   r   rA   rb   r   r%   r   r   r   r   <module>   s$   

= 7