ó
è¾bc           @   så   d  Z  d Z d d l Z d d l Z d d l Z d d l Z e e d ƒ sZ e d ƒ ‚ n  d d d g Z d	 a	 d	 a
 d
 „  Z d „  Z d e f d „  ƒ  YZ d „  Z d d d „  ƒ  YZ d „  Z d „  Z e d k rá 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   6iÿÿÿÿNt   NLs4   tokenize.NL doesn't exist -- tokenize module too oldt   checkt   NannyNagt   process_tokensi    c          G   sK   d } x. |  D]& } t  j j | t | ƒ ƒ d } q Wt  j j d ƒ d  S(   Nt    t    s   
(   t   syst   stderrt   writet   str(   t   argst   sept   arg(    (    s   /usr/lib/python2.7/tabnanny.pyt   errprint#   s
    
c          C   sÐ   y# t  j  t j d d ƒ \ }  } Wn! t  j k
 rF } t | ƒ d  SXxF |  D]> \ } } | d k rs t d a n  | d k rN t d a qN qN W| s± t d t j d d ƒ d  Sx | D] } t | ƒ q¸ Wd  S(   Ni   t   qvs   -qs   -vs   Usage:i    s   [-v] file_or_directory ...(   t   getoptR   t   argvt   errorR   t   filename_onlyt   verboseR   (   t   optsR   t   msgt   ot   aR   (    (    s   /usr/lib/python2.7/tabnanny.pyt   main*   s    #
c           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sk   
    Raised by process_tokens() if detecting an ambiguous indent.
    Captured and handled in check().
    c         C   s!   | | | |  _  |  _ |  _ d  S(   N(   t   linenoR   t   line(   t   selfR   R   R   (    (    s   /usr/lib/python2.7/tabnanny.pyt   __init__A   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s   /usr/lib/python2.7/tabnanny.pyt
   get_linenoC   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s   /usr/lib/python2.7/tabnanny.pyt   get_msgE   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s   /usr/lib/python2.7/tabnanny.pyt   get_lineG   s    (   t   __name__t
   __module__t   __doc__R   R   R   R    (    (    (    s   /usr/lib/python2.7/tabnanny.pyR   <   s
   			c   	      C   s4  t  j j |  ƒ rÁ t  j j |  ƒ rÁ t r: d |  f GHn  t  j |  ƒ } xq | D]i } t  j j |  | ƒ } t  j j | ƒ r t  j j | ƒ s¬ t  j j | d ƒ d k rP t | ƒ qP qP Wd Sy t	 |  ƒ } Wn( t
 k
 rû } t d |  | f ƒ d SXt d k rd |  GHn  y t t j | j ƒ ƒ Wnê t j k
 r[} t d |  | f ƒ d St k
 r‚} t d	 |  | f ƒ d St k
 r} | j ƒ  } | j ƒ  } t rØd
 |  | f GHd | f GH| j ƒ  GHn> d |  k rõd |  d }  n  t r|  GHn |  G| Gt | ƒ GHd SXt r0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: Indentation Error: %ss)   %r: *** Line %d: trouble in tab city! ***s   offending line: %rR   t   "s   %r: Clean bill of health.(   t   ost   patht   isdirt   islinkR   t   listdirt   joint   normcaseR   t   opent   IOErrorR   R   t   tokenizet   generate_tokenst   readlinet
   TokenErrort   IndentationErrorR   R   R    R   R   t   repr(	   t   filet   namest   namet   fullnamet   fR   t   nagt   badlineR   (    (    s   /usr/lib/python2.7/tabnanny.pyR   J   sR    
%  t
   Whitespacec           B   sS   e  Z d  \ Z Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(   s    	c   	      C   s  | |  _  t j t j } } g  } d } } } x¤ |  j  D]™ } | | k rc | d } | d } q: | | k rÒ | d } | d } | t | ƒ k r· | d g | t | ƒ d } n  | | d | | <d } q: Pq: W| |  _ | |  _ t | ƒ | f |  _ t | ƒ d k |  _	 d  S(   Ni    i   (
   t   rawR;   t   St   Tt   lent   nt   ntt   tuplet   normt	   is_simple(	   R   t   wsR=   R>   t   countt   bR@   RA   t   ch(    (    s   /usr/lib/python2.7/tabnanny.pyR   ›   s(    	


"			c         C   s&   |  j  \ } } t t | ƒ d | ƒ S(   Ni   (   RC   t   maxR?   (   R   RF   t   trailing(    (    s   /usr/lib/python2.7/tabnanny.pyt   longest_run_of_spaces´   s    c         C   s^   |  j  \ } } d } x3 t | t | ƒ ƒ D] } | | | | | } q+ W| | | |  j S(   Ni    (   RC   t   rangeR?   RA   (   R   t   tabsizeRF   RJ   t   ilt   i(    (    s   /usr/lib/python2.7/tabnanny.pyt   indent_level¸   s
    c         C   s   |  j  | j  k S(   N(   RC   (   R   t   other(    (    s   /usr/lib/python2.7/tabnanny.pyt   equalÏ   s    c         C   s   t  |  j ƒ  | j ƒ  ƒ d } g  } xd t d | d ƒ D]O } |  j | ƒ | j | ƒ k r9 | j | |  j | ƒ | j | ƒ f ƒ q9 q9 W| S(   Ni   (   RI   RK   RL   RP   t   append(   R   RQ   R@   R   t   ts(    (    s   /usr/lib/python2.7/tabnanny.pyt   not_equal_witnessÖ   s    	c         C   s›   |  j  | j  k r t S|  j r8 | j r8 |  j | j k St |  j ƒ  | j ƒ  ƒ d } x= t d | d ƒ D]( } |  j | ƒ | j | ƒ k rk t Sqk Wt S(   Ni   i   (	   R@   t   FalseRD   RA   RI   RK   RL   RP   t   True(   R   RQ   R@   RT   (    (    s   /usr/lib/python2.7/tabnanny.pyt   lessî   s    c         C   s   t  |  j ƒ  | j ƒ  ƒ d } g  } xd t d | d ƒ D]O } |  j | ƒ | j | ƒ k r9 | j | |  j | ƒ | j | ƒ f ƒ q9 q9 W| S(   Ni   (   RI   RK   RL   RP   RS   (   R   RQ   R@   R   RT   (    (    s   /usr/lib/python2.7/tabnanny.pyt   not_less_witnessÿ   s    	(   R!   R"   R=   R>   R   RK   RP   RR   RU   RX   RY   (    (    (    s   /usr/lib/python2.7/tabnanny.pyR;   „   s   						c         C   sL   t  d „  |  ƒ } d } t |  ƒ d k r7 | d } n  | d d j | ƒ S(   Nc         S   s   t  |  d ƒ S(   Ni    (   R
   (   t   tup(    (    s   /usr/lib/python2.7/tabnanny.pyt   <lambda>  R   s   at tab sizei   t   sR   s   , (   t   mapR?   R*   (   t   wt   firstst   prefix(    (    s   /usr/lib/python2.7/tabnanny.pyt   format_witnesses
  s
    c         C   sŠ  t  j } t  j } t  j } t  j t  j f } t d ƒ g } d } xA|  D]9\ } } }	 }
 } | | k rs d } qI | | k rð d } t | ƒ } | d j | ƒ sà | d j | ƒ } d t	 | ƒ } t
 |	 d | | ƒ ‚ n  | j | ƒ qI | | k rd } | d =qI | rI | | k rI d } t | ƒ } | d j | ƒ s‚| d j | ƒ } 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. (   R.   t   INDENTt   DEDENTt   NEWLINEt   COMMENTR   R;   RX   RY   Ra   R   RS   RR   RU   (   t   tokensRb   Rc   Rd   t   JUNKt   indentst   check_equalt   typet   tokent   startt   endR   t   thisguyt   witnessR   (    (    s   /usr/lib/python2.7/tabnanny.pyR     s6    				

t   __main__(    (   R#   t   __version__R%   R   R   R.   t   hasattrt
   ValueErrort   __all__R   R   R   R   t	   ExceptionR   R   R;   Ra   R   R!   (    (    (    s   /usr/lib/python2.7/tabnanny.pyt   <module>   s&   			:†		7