
    g                    v    d Z ddlmZ ddlmZ ddlmZ ddlmZ  G d d      Z G d d	e      Z	 G d
 d      Z
y)z&Statistic collection logic for Flake8.    )annotations)	Generator)
NamedTuple)	Violationc                  >    e Zd ZdZddZddZd	dZ	 d
	 	 	 	 	 ddZy)
Statisticsz5Manager of aggregated statistics for a run of Flake8.c                    i | _         y)z8Initialize the underlying dictionary for our statistics.N)_storeselfs    T/var/www/html/brdwt/brdwt/brdwtenv/lib/python3.12/site-packages/flake8/statistics.py__init__zStatistics.__init__   s	    ,.    c                f    t        | j                  D ch c]  }|j                   c}      S c c}w )ziReturn all unique error codes stored.

        :returns:
            Sorted list of error codes.
        )sortedr
   code)r   keys     r   error_codeszStatistics.error_codes   s%     4;;7Csxx7887s   .c                    t         j                  |      }|| j                  vr"t        j                  |      | j                  |<   | j                  |   j	                          y)zAdd the fact that the error was seen in the file.

        :param error:
            The Violation instance containing the information about the
            violation.
        N)Keycreate_fromr
   	Statistic	increment)r   errorr   s      r   recordzStatistics.record   sL     ooe$dkk!(44U;DKKC""$r   Nc              #  ~   K   t        fd| j                  D              }|D ]  }| j                  |     yw)aB  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 prefix:
            The error class or specific error code to find statistics for.
        :param filename:
            (Optional) The filename to further filter results by.
        :returns:
            Generator of instances of :class:`Statistic`
        c              3  H   K   | ]  }|j                        s|  y wN)matches).0r   filenameprefixs     r   	<genexpr>z,Statistics.statistics_for.<locals>.<genexpr>>   s#      !
#++fh*GC!
s   ""N)r   r
   )r   r"   r!   matching_errors
error_codes    ``  r   statistics_forzStatistics.statistics_for%   sD     2 ! !
;;!
 
 * 	*J++j))	*s   9=returnNone)r(   z	list[str])r   r   r(   r)   r   )r"   strr!   
str | Noner(   z Generator[Statistic, None, None])__name__
__module____qualname____doc__r   r   r   r&    r   r   r   r   
   s6    ?/9
% 37**%/*	)*r   r   c                  @    e Zd ZU dZded<   ded<   edd       Zd	dZy)
r   zSimple 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.
    r*   r!   r   c                >     | |j                   |j                        S )z6Create a Key from :class:`flake8.violation.Violation`.r!   r   r3   clsr   s     r   r   zKey.create_fromP   s     ENN<<r   c                f    | j                   j                  |      xr |du xs | j                  |k(  S )a  Determine if this key matches some constraints.

        :param prefix:
            The error code prefix that this key's error code should start with.
        :param 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.
        N)r   
startswithr!   )r   r"   r!   s      r   r   zKey.matchesU   s6     yy##F+ 
9 9	
r   N)r   r   r(   r   )r"   r*   r!   r+   r(   bool)r,   r-   r.   r/   __annotations__classmethodr   r   r0   r   r   r   r   E   s*     M
I= =
r   r   c                  F    e Zd ZdZ	 	 	 	 	 	 	 	 	 	 ddZedd       ZddZy)	r   zSimple wrapper around the logic of each statistic.

    Instead of maintaining a simple but potentially hard to reason about
    tuple, we create a class which has attributes and a couple
    convenience methods on it.
    c                <    || _         || _        || _        || _        y)zInitialize our Statistic.Nr%   r!   messagecount)r   r%   r!   r>   r?   s        r   r   zStatistic.__init__n   s      % 
r   c                V     | |j                   |j                  |j                  d      S )z>Create a Statistic from a :class:`flake8.violation.Violation`.r   r=   )r   r!   textr4   s     r   r   zStatistic.create_fromw   s)     zz^^JJ	
 	
r   c                .    | xj                   dz  c_         y)zAIncrement the number of times we've seen this error in this file.   N)r?   r   s    r   r   zStatistic.increment   s    

a
r   N)
r%   r*   r!   r*   r>   r*   r?   intr(   r)   )r   r   r(   r   r'   )r,   r-   r.   r/   r   r:   r   r   r0   r   r   r   r   f   sM    ),7:CF	 
 
r   r   N)r/   
__future__r   typingr   r   flake8.violationr   r   r   r   r0   r   r   <module>rH      s6    , "   &8* 8*v
* 
B r   