ó
„¾^Yc           @€  s»   d  Z  d d l m 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 d d „ Z d 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   mainc         C€  s×  | d	 k r t j ƒ  } n  y t |  | d t j ƒ } 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 rB| j | d ƒ n | j | | | | | ƒ d St k
 r€| j | d ƒ d SXt j | | ƒ }
 |
 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   execi   i    i   t   asciis   problem decoding sourcet   keyc         S€  s   |  j  S(   N(   t   lineno(   t   m(    (    s.   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/api.pyt   <lambda>F   s    N(   i   (   t   Nonet   modReportert   _makeDefaultReportert   compilet   _astt   PyCF_ONLY_ASTt   SyntaxErrort   syst   exc_infot   argsR   t   offsett   textR   t   PYPYt
   splitlinest   lent   version_infot
   isinstancet   bytest   decodet   UnicodeDecodeErrort   unexpectedErrort   syntaxErrort	   Exceptiont   Checkert   messagest   sortt   flake(   t
   codeStringt   filenameR   t   treet   valuet   msgR   R   R   t   linest   wt   warning(    (    s.   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/api.pyR      s>    	c         C€  sê   | d k r t j ƒ  } n  yb t j d	 k  r6 d } n d } t |  | ƒ  } | j ƒ  } Wd QXt j d
 k  r| | d 7} n  WnZ t k
 r¡ | j |  d ƒ d S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
    i   i   t   rUt   rbNs   
s   problem decoding sourcei   (   i   i   (   i   i   (   R   R   R   R   R   t   opent   readt   UnicodeErrorR#   t   IOErrorR   R   R   (   R+   R   t   modet   ft   codestrR.   (    (    s.   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/api.pyR   L   s$    		c         c€  s‰   x‚ |  D]z } t  j j | ƒ r| x_ t  j | ƒ D]F \ } } } x4 | D], } | j d ƒ rE t  j j | | ƒ 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.
    s   .pyN(   t   ost   patht   isdirt   walkt   endswitht   join(   t   pathsR<   t   dirpatht   dirnamest	   filenamesR+   (    (    s.   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/api.pyR   o   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   (   RA   R   t   warningst
   sourcePath(    (    s.   /tmp/pip-build-EndXZ2/pyflakes/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   sigR9   (   t   message(    s.   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/api.pyt   handler¡   s    (   t   signalt   getattrt   AttributeErrort
   ValueError(   t   sigNameRI   RK   t	   sigNumberRJ   (    (   RI   s.   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/api.pyt   _exitOnSignal‘   s    c         C€  s«   d d l  } t d d ƒ t d d ƒ | j d |  d t ƒ } | j d	 | ƒ \ } } t j ƒ  } | rz 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   optparseRQ   t   OptionParserR   t
   parse_argsR   R   R   R   R   t   stdinR5   t
   SystemExit(   RT   R   RV   t   parsert   __R   RE   (    (    s.   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/api.pyR   ¬   s    (   t   __doc__t
   __future__R    R   R;   R   t   pyflakesR   R   R   R   t   __all__R   R   R   R   R   RQ   R   (    (    (    s.   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/api.pyt   <module>   s   <#			