mò
­fIc           @   sÝ   d  Z  d Z d k Z d k Z d k Z d k Z e e d ƒ p e d ƒ ‚ n d d d g Z d a	 d a
 d	 „  Z d
 „  Z d e f d „  ƒ  YZ d „  Z d f  d „  ƒ  YZ d „  Z d „  Z e d j o e ƒ  n d S(   s–  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.
t   6Nt   NLs4   tokenize.NL doesn't exist -- tokenize module too oldt   checkt   NannyNagt   process_tokensi    c          G   sK   d } x. |  D]& } t i i | t | ƒ ƒ d } q Wt i i d ƒ d  S(   Nt    t    s   
(   t   sept   argst   argt   syst   stderrt   writet   str(   R   R	   R   (    (    t%   /mit/python/lib/python2.4/tabnanny.pyt   errprint#   s     
c          C   sÞ   y# t  i  t i d d ƒ \ } } Wn& t  i j
 o } t | ƒ d  Sn XxJ | D]B \ } }  | d j o t
 d a
 n | d j o t d a qS qS W| p t d t i d d ƒ d  Sn x | D] } t | ƒ qÆ Wd  S(   Ni   t   qvs   -qs   -vs   Usage:i    s   [-v] file_or_directory ...(   t   getoptR
   t   argvt   optsR   t   errort   msgR   t   ot   at   filename_onlyt   verboseR	   R   (   R   R   R   R	   R   R   (    (    R   t   main*   s$     #
	  c           B   s2   t  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sg   
    Raised by tokeneater() if detecting an ambiguous indent.
    Captured and handled in check().
    c         C   s!   | | | |  _  |  _ |  _ d  S(   N(   t   linenoR   t   linet   self(   R   R   R   R   (    (    R   t   __init__A   s    c         C   s   |  i S(   N(   R   R   (   R   (    (    R   t
   get_linenoC   s    c         C   s   |  i S(   N(   R   R   (   R   (    (    R   t   get_msgE   s    c         C   s   |  i S(   N(   R   R   (   R   (    (    R   t   get_lineG   s    (   t   __name__t
   __module__t   __doc__R   R   R    R!   (    (    (    R   R   <   s
    			c   	      C   s2  t  i i |  ƒ oº t  i i |  ƒ o¦ t o d |  f GHn t  i |  ƒ } xu | D]m } t  i i	 |  | ƒ } t  i i | ƒ o t  i i | ƒ p t  i i | d ƒ d j o t | ƒ qT qT Wd Sn y t |  ƒ } Wn- t j
 o! } t d |  | f ƒ d Sn Xt d j o d |  GHn y t t i | i ƒ ƒ WnÓ t i j
 o! } t d |  | f ƒ d Sn¥ t j
 o˜ } | i ƒ  } | i ƒ  } t o* d	 |  | f GHd
 | f GH| i ƒ  GHnC d |  j o d |  d }  n t o	 |  GHn |  G| Gt | ƒ GHd Sn Xt o d |  f GHn d S(   s~  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.
    s   %r: listing directoryiýÿÿÿs   .pyNs   %r: I/O Error: %si   s   checking %r ...s   %r: Token Error: %ss)   %r: *** Line %d: trouble in tab city! ***s   offending line: %rR   t   "s   %r: Clean bill of health.(    t   ost   patht   isdirt   filet   islinkR   t   listdirt   namest   namet   joint   fullnamet   normcaseR   t   opent   ft   IOErrorR   R   R   t   tokenizet   generate_tokenst   readlinet
   TokenErrorR   t   nagR   t   badlineR!   R   R    R   t   repr(	   R)   R-   R2   R   R8   R9   R,   R   R/   (    (    R   R   J   sL     ' D	  		t
   Whitespacec           B   sS   t  Z d \ Z Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   Ns    	c   	      C   s  | |  _ t i t i } } g  } d } } } xª |  i D]Ÿ } | | j o | d } | d } q: | | j of | d } | d } | t | ƒ j o# | d g | t | ƒ d } n | | d | | <d } q: Pq: W| |  _ | |  _	 t | ƒ | f |  _ t | ƒ d j |  _ d  S(   Ni    i   (   t   wsR   t   rawR;   t   St   Tt   countt   bt   nt   ntt   cht   lent   tuplet   normt	   is_simple(	   R   R<   R@   RA   RB   R>   RD   R?   RC   (    (    R   R   —   s*    	
 


#
		c         C   s&   |  i \ } } t t | ƒ d | ƒ S(   Ni   (   R   RG   R@   t   trailingt   maxRE   (   R   R@   RI   (    (    R   t   longest_run_of_spaces°   s    c         C   s^   |  i \ } } d } x3 t | t | ƒ ƒ D] } | | | | | } q+ W| | | |  i	 S(   Ni    (
   R   RG   R@   RI   t   ilt   ranget   tabsizeRE   t   iRC   (   R   RN   R@   RO   RI   RL   (    (    R   t   indent_level´   s     c         C   s   |  i | i j S(   N(   R   RG   t   other(   R   RQ   (    (    R   t   equalË   s    c         C   s’   t  |  i ƒ  | i ƒ  ƒ d } g  } xf t d | d ƒ D]Q } |  i | ƒ | i | ƒ j o, | i	 | |  i | ƒ | i | ƒ f ƒ q9 q9 W| S(   Ni   (
   RJ   R   RK   RQ   RB   R   RM   t   tsRP   t   append(   R   RQ   R   RS   RB   (    (    R   t   not_equal_witnessÒ   s     0c         C   s«   |  i | i j o t Sn |  i o | i o |  i | i j Sn t |  i ƒ  | i ƒ  ƒ d } xB t d | d ƒ D]- } |  i
 | ƒ | i
 | ƒ j o t Sqv qv Wt S(   Ni   i   (   R   RB   RQ   t   FalseRH   RC   RJ   RK   RM   RS   RP   t   True(   R   RQ   RS   RB   (    (    R   t   lessê   s     c         C   s’   t  |  i ƒ  | i ƒ  ƒ d } g  } xf t d | d ƒ D]Q } |  i | ƒ | i | ƒ j o, | i	 | |  i | ƒ | i | ƒ f ƒ q9 q9 W| S(   Ni   (
   RJ   R   RK   RQ   RB   R   RM   RS   RP   RT   (   R   RQ   R   RS   RB   (    (    R   t   not_less_witnessû   s     0(   R"   R#   R>   R?   R   RK   RP   RR   RU   RX   RY   (    (    (    R   R;   €   s   						c         C   sN   t  d „  |  ƒ } d } t |  ƒ d j o | d } n | d d i | ƒ S(   Nc         C   s   t  |  d ƒ S(   Ni    (   R   t   tup(   RZ   (    (    R   t   <lambda>  s    s   at tab sizei   t   sR   s   , (   t   mapt   wt   firstst   prefixRE   R.   (   R^   R`   R_   (    (    R   t   format_witnesses  s
    c         C   s—  t  i } t  i } t  i } t  i t  i f } t d ƒ g } d } xN|  D]F\ } } } } } | | j o
 d } qI | | j ot d } t | ƒ } | d i | ƒ p= | d i | ƒ }	 d t |	 ƒ }
 t | d |
 | ƒ ‚ n | i | ƒ qI | | j o d } | d =qI | ot | | j og d } t | ƒ } | d i | ƒ p= | d i | ƒ }	 d t |	 ƒ }
 t | d |
 | ƒ ‚ qqI qI Wd  S(   NR   i    i   iÿÿÿÿs   indent not greater e.g. s   indent not equal e.g. (   R4   t   INDENTt   DEDENTt   NEWLINEt   COMMENTR   t   JUNKR;   t   indentst   check_equalt   tokenst   typet   tokent   startt   endR   t   thisguyRX   RY   t   witnessRa   R   R   RT   RR   RU   (   Ri   Rc   Rf   Rb   Rn   Rd   Rk   Rl   Rg   Ro   R   Rm   R   Rj   Rh   (    (    R   R     s8    			 

t   __main__(   R$   t   __version__R&   R
   R   R4   t   hasattrt
   ValueErrort   __all__R   R   R   R   t	   ExceptionR   R   R;   Ra   R   R"   (   R   R;   Rt   R   Ra   R   R
   R   R4   R   R   Rq   R&   (    (    R   t   ?   s&   							6†		7