ó
„¾^Yc           @   s%  d  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 d d l m Z d d l m	 Z	 d f Z
 e j e ƒ Z d e j f d „  ƒ  YZ d	 e j f d
 „  ƒ  YZ d e j f d „  ƒ  YZ e j d d d d d d d g ƒ Z d e f d „  ƒ  YZ d „  Z d „  Z d S(   s0   Implementation of the StyleGuide used by Flake8.iÿÿÿÿN(   t   defaults(   t
   statistics(   t   utilst
   StyleGuidet   Selectedc           B   s   e  Z d  Z d Z d Z RS(   s<   Enum representing an explicitly or implicitly selected code.s   explicitly selecteds   implicitly selected(   t   __name__t
   __module__t   __doc__t
   Explicitlyt
   Implicitly(    (    (    s2   /tmp/pip-build-EndXZ2/flake8/flake8/style_guide.pyR      s   t   Ignoredc           B   s   e  Z d  Z d Z d Z RS(   s;   Enum representing an explicitly or implicitly ignored code.s   explicitly ignoreds   implicitly ignored(   R   R   R   R   R	   (    (    (    s2   /tmp/pip-build-EndXZ2/flake8/flake8/style_guide.pyR
      s   t   Decisionc           B   s   e  Z d  Z d Z d Z RS(   s?   Enum representing whether a code should be ignored or selected.s   ignored errors   selected error(   R   R   R   R
   R   (    (    (    s2   /tmp/pip-build-EndXZ2/flake8/flake8/style_guide.pyR   "   s   t   Errort   codet   filenamet   line_numbert   column_numbert   textt   physical_linec           B   st   e  Z d  Z d „  Z d „  Z d „  Z e j d „  ƒ Z d „  Z	 d „  Z
 d „  Z d „  Z d d	 „ Z d
 „  Z RS(   s#   Manage a Flake8 user's style guide.c         C   sÅ   | |  _  | |  _ | |  _ t j ƒ  |  _ t | j ƒ |  _ t t	 | j
 d t ƒƒ |  _ t | j ƒ |  _ t t	 |  j |  j d t ƒƒ |  _ t t	 | j d t ƒƒ |  _ i  |  _ i  |  _ d S(   sS   Initialize our StyleGuide.

        .. todo:: Add parameter documentation.
        t   reverseN(   t   optionst   listenert	   formatterR   t
   Statisticst   statst   tuplet   selectt	   _selectedt   sortedt   extended_default_selectt   Truet   _extended_selectedt   enable_extensionst   _enabled_extensionst   _all_selectedt   ignoret   _ignoredt   _decision_cachet   _parsed_diff(   t   selfR   t   listener_trieR   (    (    s2   /tmp/pip-build-EndXZ2/flake8/flake8/style_guide.pyt   __init__9   s    					c         C   sU   |  j  r" | j |  j  ƒ r" t j S|  j  rN |  j rN | j |  j ƒ rN t j St j S(   s¨  Determine if the code has been selected by the user.

        :param str code:
            The code for the check that has been run.
        :returns:
            Selected.Implicitly if the selected list is empty,
            Selected.Explicitly if the selected list is not empty and a match
            was found,
            Ignored.Implicitly if the selected list is not empty but no match
            was found.
        (   R"   t
   startswithR   R   R   R	   R
   (   R'   R   (    (    s2   /tmp/pip-build-EndXZ2/flake8/flake8/style_guide.pyt   is_user_selectedP   s    
	c         C   s)   |  j  r" | j |  j  ƒ r" t j St j S(   s¤  Determine if the code has been ignored by the user.

        :param str code:
            The code for the check that has been run.
        :returns:
            Selected.Implicitly if the ignored list is empty,
            Ignored.Explicitly if the ignored list is not empty and a match was
            found,
            Selected.Implicitly if the ignored list is not empty but no match
            was found.
        (   R$   R*   R
   R   R   R	   (   R'   R   (    (    s2   /tmp/pip-build-EndXZ2/flake8/flake8/style_guide.pyt   is_user_ignoredj   s    c         c   s)   |  j  j | ƒ |  V|  j  j | ƒ d S(   s9   Record the fact that we're processing the file's results.N(   R   t	   beginningt   finished(   R'   R   (    (    s2   /tmp/pip-build-EndXZ2/flake8/flake8/style_guide.pyt   processing_file|   s    c         C   sä   t  | |  j ƒ } t  | |  j ƒ } t  | |  j ƒ } | rO | rO t | | ƒ S| rh | rh t | | ƒ S| s† | r |  j t j k r t j	 S| d  k r¸ | d  k r¸ | d  k	 r¸ t j S|  j t j k rÝ | d  k rÝ t j St j	 S(   N(   t   find_first_matchR"   R   R$   t   find_more_specificR   R    t   SELECTR   R   t   NoneR
   (   R'   R   R   t   extra_selectR#   (    (    s2   /tmp/pip-build-EndXZ2/flake8/flake8/style_guide.pyt   _decision_forƒ   s    $c         C   s:  |  j  j | ƒ } | d k r6t j d | ƒ |  j | ƒ } |  j | ƒ } t j d | | | ƒ | t j k s€ | t j	 k r› | t j	 k r› t
 j } nx | t j k r¹ | t j k s× | t j	 k ré | t j	 k ré |  j | ƒ } n* | t j	 k s| t j k rt
 j } n  | |  j  | <t j d | | ƒ n  | S(   s˜  Determine if the error code should be reported or ignored.

        This method only cares about the select and ignore rules as specified
        by the user in their configuration files and command-line flags.

        This method does not look at whether the specific line is being
        ignored in the file itself.

        :param str code:
            The code for the check that has been run.
        s#   Deciding if "%s" should be reporteds)   The user configured "%s" to be "%s", "%s"s   "%s" will be "%s"N(   R%   t   getR3   t   LOGt   debugR+   R,   R   R   R	   R   R
   R5   (   R'   R   t   decisiont   selectedt   ignored(    (    s2   /tmp/pip-build-EndXZ2/flake8/flake8/style_guide.pyt   should_report_error•   s,    	c         C   s  | j  } |  j j r t S| d k r@ t j | j | j ƒ } n  t	 j
 j | ƒ } | d k rr t j d | ƒ t S| j ƒ  d } | d k r¢ t j d | ƒ t St t j | ƒ ƒ } | j | k sÞ | j j t | ƒ ƒ rõ t j d | | ƒ t St j d | | ƒ t S(   s;   Determine if an comment has been added to ignore this line.s   %r is not inline ignoredt   codess%   %r is ignored by a blanket ``# noqa``s5   %r is ignored specifically inline with ``# noqa: %s``s,   %r is not ignored inline with ``# noqa: %s``N(   R   R   t   disable_noqat   FalseR3   t	   linecachet   getlineR   R   R    t   NOQA_INLINE_REGEXPt   searchR7   R8   t	   groupdictR   t   setR   t   parse_comma_separated_listR   R*   R   (   R'   t   errorR   t
   noqa_matcht	   codes_strR=   (    (    s2   /tmp/pip-build-EndXZ2/flake8/flake8/style_guide.pyt   is_inline_ignored»   s,    	'	
	
c         C   s9   |  j  s t S|  j  j | j ƒ } | s, t S| j | k S(   s—  Determine if an error is included in a diff's line ranges.

        This function relies on the parsed data added via
        :meth:`~StyleGuide.add_diff_ranges`. If that has not been called and
        we are not evaluating files in a diff, then this will always return
        True. If there are diff ranges, then this will return True if the
        line number in the error falls inside one of the ranges for the file
        (and assuming the file is part of the diff data). If there are diff
        ranges, this will return False if the file is not part of the diff
        data or the line number of the error is not in any of the ranges of
        the diff.

        :returns:
            True if there is no diff or if the error is in the diff's line
            number ranges. False if the error's line number falls outside
            the diff's line number ranges.
        :rtype:
            bool
        (   R&   R   R6   R   R?   R   (   R'   RG   t   line_numbers(    (    s2   /tmp/pip-build-EndXZ2/flake8/flake8/style_guide.pyt
   is_in_diffÚ   s    	c         C   s½   | s d } n  t  | | | | d | | ƒ } |  j | j ƒ t j k } |  j | ƒ t k }	 |  j | ƒ }
 | r¹ |	 r¹ |
 r¹ |  j j	 | ƒ |  j
 j | ƒ |  j j | j | ƒ d Sd S(   s6  Handle an error reported by a check.

        :param str code:
            The error code found, e.g., E123.
        :param str filename:
            The file in which the error was found.
        :param int line_number:
            The line number (where counting starts at 1) at which the error
            occurs.
        :param int column_number:
            The column number (where counting starts at 1) at which the error
            occurs.
        :param str text:
            The text of the error message.
        :param str physical_line:
            The actual physical line causing the error.
        :returns:
            1 if the error was reported. 0 if it was ignored. This is to allow
            for counting of the number of errors found that were not ignored.
        :rtype:
            int
        i    i   (   R   R<   R   R   R   RJ   R?   RL   R   t   handleR   t   recordR   t   notify(   R'   R   R   R   R   R   R   RG   t   error_is_selectedt   is_not_inline_ignoredt   is_included_in_diff(    (    s2   /tmp/pip-build-EndXZ2/flake8/flake8/style_guide.pyt   handle_errorþ   s    		c         C   s   | |  _  d S(   s-  Update the StyleGuide to filter out information not in the diff.

        This provides information to the StyleGuide so that only the errors
        in the line number ranges are reported.

        :param dict diffinfo:
            Dictionary mapping filenames to sets of line number ranges.
        N(   R&   (   R'   t   diffinfo(    (    s2   /tmp/pip-build-EndXZ2/flake8/flake8/style_guide.pyt   add_diff_ranges*  s    	N(   R   R   R   R)   R+   R,   t
   contextlibt   contextmanagerR/   R5   R<   RJ   RL   R3   RS   RU   (    (    (    s2   /tmp/pip-build-EndXZ2/flake8/flake8/style_guide.pyR   6   s   					&		%+c         C   s)   |  j  | ƒ r" |  | k r" t j St j S(   N(   R*   R   R   R
   (   R:   R;   (    (    s2   /tmp/pip-build-EndXZ2/flake8/flake8/style_guide.pyR1   6  s    c         C   s2   |  j  } x" | D] } | | ƒ r Pq q Wd  S| S(   N(   R*   R3   (   t
   error_codet	   code_listR*   R   (    (    s2   /tmp/pip-build-EndXZ2/flake8/flake8/style_guide.pyR0   <  s    	(   R   t   collectionsRV   t   enumR@   t   loggingt   flake8R    R   R   t   __all__t	   getLoggerR   R7   t   EnumR   R
   R   t
   namedtupleR   t   objectR   R1   R0   (    (    (    s2   /tmp/pip-build-EndXZ2/flake8/flake8/style_guide.pyt   <module>   s2   	ÿ 	