ó
„¾^Yc           @   sj   d  Z  d d l Z d e f d „  ƒ  YZ d e j d d d g ƒ f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d S(   s&   Statistic collection logic for Flake8.iÿÿÿÿNt
   Statisticsc           B   s5   e  Z d  Z d „  Z d „  Z d „  Z d d „ Z RS(   s5   Manager of aggregated statistics for a run of Flake8.c         C   s   i  |  _  d S(   s8   Initialize the underlying dictionary for our statistics.N(   t   _store(   t   self(    (    s1   /tmp/pip-build-EndXZ2/flake8/flake8/statistics.pyt   __init__   s    c         C   s)   t  t t d „  |  j j ƒ  Dƒ ƒ ƒ ƒ S(   s   Return all unique error codes stored.

        :returns:
            Sorted list of error codes.
        :rtype:
            list(str)
        c         s   s   |  ] } | j  Vq d  S(   N(   t   code(   t   .0t   key(    (    s1   /tmp/pip-build-EndXZ2/flake8/flake8/statistics.pys	   <genexpr>   s    (   t   listt   sortedt   setR   t   keys(   R   (    (    s1   /tmp/pip-build-EndXZ2/flake8/flake8/statistics.pyt   error_codes   s    c         C   sL   t  j | ƒ } | |  j k r7 t j | ƒ |  j | <n  |  j | j ƒ  d S(   sÚ   Add the fact that the error was seen in the file.

        :param error:
            The Error instance containing the information about the violation.
        :type error:
            flake8.style_guide.Error
        N(   t   Keyt   create_fromR   t	   Statistict	   increment(   R   t   errorR   (    (    s1   /tmp/pip-build-EndXZ2/flake8/flake8/statistics.pyt   record   s    c         #   sI   t  ‡  ‡ f d †  |  j j ƒ  Dƒ ƒ } x | D] } |  j | Vq/ Wd S(   sJ  Generate statistics for the prefix and filename.

        If you have a :class:`Statistics` object that has recorded errors,
        you can generate the statistics for a prefix (e.g., ``E``, ``E1``,
        ``W50``, ``W503``) with the optional filter of a filename as well.

        .. code-block:: python

            >>> stats = Statistics()
            >>> stats.statistics_for('E12',
                                     filename='src/flake8/statistics.py')
            <generator ...>
            >>> stats.statistics_for('W')
            <generator ...>

        :param str prefix:
            The error class or specific error code to find statistics for.
        :param str filename:
            (Optional) The filename to further filter results by.
        :returns:
            Generator of instances of :class:`Statistic`
        c         3   s'   |  ] } | j  ˆ ˆ  ƒ r | Vq d  S(   N(   t   matches(   R   R   (   t   filenamet   prefix(    s1   /tmp/pip-build-EndXZ2/flake8/flake8/statistics.pys	   <genexpr>:   s    N(   R   R   R
   (   R   R   R   t   matching_errorst
   error_code(    (   R   R   s1   /tmp/pip-build-EndXZ2/flake8/flake8/statistics.pyt   statistics_for#   s    (N(   t   __name__t
   __module__t   __doc__R   R   R   t   NoneR   (    (    (    s1   /tmp/pip-build-EndXZ2/flake8/flake8/statistics.pyR       s
   		
	R   R   R   c           B   s,   e  Z d  Z d Z e d „  ƒ Z d „  Z RS(   sä   Simple key structure for the Statistics dictionary.

    To make things clearer, easier to read, and more understandable, we use a
    namedtuple here for all Keys in the underlying dictionary for the
    Statistics object.
    c         C   s   |  d | j  d | j ƒ S(   s4   Create a Key from :class:`flake8.style_guide.Error`.R   R   (   R   R   (   t   clsR   (    (    s1   /tmp/pip-build-EndXZ2/flake8/flake8/statistics.pyR   J   s    	c         C   s+   |  j  j | ƒ o* | d k p* |  j | k S(   s  Determine if this key matches some constraints.

        :param str prefix:
            The error code prefix that this key's error code should start with.
        :param str filename:
            The filename that we potentially want to match on. This can be
            None to only match on error prefix.
        :returns:
            True if the Key's code starts with the prefix and either filename
            is None, or the Key's filename matches the value passed in.
        :rtype:
            bool
        N(   R   t
   startswithR   R   (   R   R   R   (    (    s1   /tmp/pip-build-EndXZ2/flake8/flake8/statistics.pyR   R   s    (    (   R   R   R   t	   __slots__t   classmethodR   R   (    (    (    s1   /tmp/pip-build-EndXZ2/flake8/flake8/statistics.pyR   @   s   R   c           B   s/   e  Z d  Z d „  Z e d „  ƒ Z d „  Z RS(   sä   Simple wrapper around the logic of each statistic.

    Instead of maintaining a simple but potentially hard to reason about
    tuple, we create a namedtuple which has attributes and a couple
    convenience methods on it.
    c         C   s(   | |  _  | |  _ | |  _ | |  _ d S(   s   Initialize our Statistic.N(   R   R   t   messaget   count(   R   R   R   R    R!   (    (    s1   /tmp/pip-build-EndXZ2/flake8/flake8/statistics.pyR   m   s    			c      	   C   s(   |  d | j  d | j d | j d d ƒ S(   s<   Create a Statistic from a :class:`flake8.style_guide.Error`.R   R   R    R!   i    (   R   R   t   text(   R   R   (    (    s1   /tmp/pip-build-EndXZ2/flake8/flake8/statistics.pyR   t   s
    			c         C   s   |  j  d 7_  d S(   sA   Increment the number of times we've seen this error in this file.i   N(   R!   (   R   (    (    s1   /tmp/pip-build-EndXZ2/flake8/flake8/statistics.pyR   ~   s    (   R   R   R   R   R   R   R   (    (    (    s1   /tmp/pip-build-EndXZ2/flake8/flake8/statistics.pyR   e   s   	
(   R   t   collectionst   objectR    t
   namedtupleR   R   (    (    (    s1   /tmp/pip-build-EndXZ2/flake8/flake8/statistics.pyt   <module>   s   ;(%