ó
4¶†\c           @€  sô   d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m	 Z	 m
 Z
 d d l m Z d d d d	 d
 g Z e j d ƒ Z d d „ Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d d d „ Z d S(   s,   
API for the command-line I{pyflakes} tool.
iÿÿÿÿ(   t   with_statementN(   t   checkert   __version__(   t   reportert   checkt	   checkPatht   checkRecursivet   iterSourceCodet   mains   ^#!.*\bpython[23w]?\b\s*$c         C€  sì  | d
 k r t j ƒ  } n  y t j |  d | ƒ} WnGt k
 r\t j ƒ  d } | j d } | j	 | j
 | j } } } t j r | d
 k r|  j ƒ  }	 t |	 ƒ | k r|	 | d } t j d k rt | t ƒ ry | j d ƒ } Wqt k
 r	d
 } qXqqn  | d 8} n  | d
 k r?| j | d ƒ n | j | | | | | ƒ d St k
 r}| j | d ƒ d SXt j |  ƒ }
 t j | d |
 d | ƒ} | j j d d	 „  ƒ x | j D] } | j | ƒ qÈWt | j ƒ S(   s³  
    Check the Python source given by C{codeString} for flakes.

    @param codeString: The Python source to check.
    @type codeString: C{str}

    @param filename: The name of the file the source came from, used to report
        errors.
    @type filename: C{str}

    @param reporter: A L{Reporter} instance, where errors and warnings will be
        reported.

    @return: The number of warnings emitted.
    @rtype: C{int}
    t   filenamei   i    i   t   asciis   problem decoding sourcet   file_tokenst   keyc         S€  s   |  j  S(   N(   t   lineno(   t   m(    (    s+   lib/python2.7/site-packages/pyflakes/api.pyt   <lambda>K   s    N(   i   (   t   Nonet   modReportert   _makeDefaultReportert   astt   parset   SyntaxErrort   syst   exc_infot   argsR   t   offsett   textR   t   PYPYt
   splitlinest   lent   version_infot
   isinstancet   bytest   decodet   UnicodeDecodeErrort   unexpectedErrort   syntaxErrort	   Exceptiont   make_tokenst   Checkert   messagest   sortt   flake(   t
   codeStringR	   R   t   treet   valuet   msgR   R   R   t   linesR   t   wt   warning(    (    s+   lib/python2.7/site-packages/pyflakes/api.pyR      s@    	c         C€  s   | d k r t j ƒ  } n  y( t |  d ƒ  } | j ƒ  } Wd QXWn9 t k
 r~ t j ƒ  d } | j |  | j	 d ƒ d SXt
 | |  | ƒ S(   sÒ   
    Check the given path, printing out any warnings detected.

    @param reporter: A L{Reporter} instance, where errors and warnings will be
        reported.

    @return: the number of warnings printed
    t   rbNi   (   R   R   R   t   opent   readt   IOErrorR   R   R#   R   R   (   R	   R   t   ft   codestrR.   (    (    s+   lib/python2.7/site-packages/pyflakes/api.pyR   Q   s    	c         C€  s“   |  j  d ƒ r t S|  j  d ƒ r& t Sd } y5 t |  d ƒ   } | j | ƒ } | sZ t SWd QXWn t k
 ru t SX| j ƒ  d } t j | ƒ S(   s0   Return True if filename points to a Python file.s   .pyt   ~i€   R2   Ni    (	   t   endswitht   Truet   FalseR3   R4   R5   R   t   PYTHON_SHEBANG_REGEXt   match(   R	   t	   max_bytesR6   R   t
   first_line(    (    s+   lib/python2.7/site-packages/pyflakes/api.pyt   isPythonFilef   s    c         c€  sŒ   x… |  D]} } t  j j | ƒ r xb t  j | ƒ D]I \ } } } x7 | D]/ } t  j j | | ƒ } t | ƒ rE | VqE qE Wq/ Wq | Vq Wd S(   sç   
    Iterate over all Python source files in C{paths}.

    @param paths: A list of paths.  Directories will be recursed into and
        any .py files found will be yielded.  Any non-directories will be
        yielded as-is.
    N(   t   ost   patht   isdirt   walkt   joinR@   (   t   pathsRB   t   dirpatht   dirnamest	   filenamesR	   t	   full_path(    (    s+   lib/python2.7/site-packages/pyflakes/api.pyR   }   s    c         C€  s4   d } x' t  |  ƒ D] } | t | | ƒ 7} q W| S(   s;  
    Recursively check all source files in C{paths}.

    @param paths: A list of paths to Python source files and directories
        containing Python source files.
    @param reporter: A L{Reporter} where all of the warnings and errors
        will be reported to.
    @return: The number of warnings found.
    i    (   R   R   (   RF   R   t   warningst
   sourcePath(    (    s+   lib/python2.7/site-packages/pyflakes/api.pyR      s    
c         €  so   d d l  } y t | |  ƒ } Wn t k
 r3 d SX‡  f d †  } y | j  | | ƒ Wn t k
 rj n Xd S(   s¥   Handles a signal with sys.exit.

    Some of these signals (SIGPIPE, for example) don't exist or are invalid on
    Windows. So, ignore errors that might arise.
    iÿÿÿÿNc         €  s   t  j ˆ  ƒ d  S(   N(   R   t   exit(   t   sigR6   (   t   message(    s+   lib/python2.7/site-packages/pyflakes/api.pyt   handler°   s    (   t   signalt   getattrt   AttributeErrort
   ValueError(   t   sigNameRO   RQ   t	   sigNumberRP   (    (   RO   s+   lib/python2.7/site-packages/pyflakes/api.pyt   _exitOnSignal    s    c           C€  s   d t  t j ƒ  t j ƒ  f S(   sQ   
    Retrieve and format package version along with python version & OS used
    s   %s Python %s on %s(   R   t   platformt   python_versiont   system(    (    (    s+   lib/python2.7/site-packages/pyflakes/api.pyt   _get_version»   s    c         C€  s®   d d l  } t d d ƒ t d d ƒ | j d |  d t ƒ  ƒ } | j d	 | ƒ \ } } t j ƒ  } | r} t | | ƒ } n t t	 j
 j ƒ  d
 | ƒ } t | d k ƒ ‚ d S(   s&   Entry point for the script "pyflakes".iÿÿÿÿNt   SIGINTs   ... stoppedt   SIGPIPEi   t   progt   versionR   s   <stdin>i    (   t   optparseRW   t   OptionParserR[   t
   parse_argsR   R   R   R   R   t   stdinR4   t
   SystemExit(   R^   R   R`   t   parsert   __R   RK   (    (    s+   lib/python2.7/site-packages/pyflakes/api.pyR   Ã   s    (   t   __doc__t
   __future__R    R   RA   RX   t   reR   t   pyflakesR   R   R   R   t   __all__t   compileR<   R   R   R   R@   R   R   RW   R[   R   (    (    (    s+   lib/python2.7/site-packages/pyflakes/api.pyt   <module>   s$   =					