
    >/i~                     ,    S SK r S SKJr   " S S5      rg)    N)	constantsc                   Z    \ rS rSrSrS rS rSS jrSS jrS r	S r
S	 r\S
 5       rSrg)Metrics
   aM  Bandit metric gathering.

This class is a singleton used to gather and process metrics collected when
processing a code base with bandit. Metric collection is stateful, that
is, an active metric block will be set when requested and all subsequent
operations will effect that metric block until it is replaced by a setting
a new one.
c                     [        5       U l        SSSS.U R                  S'   [        R                   H4  n[        R                   H  nSU R                  S   US    SU 3'   M     M6     g )Nr   locnosecskipped_tests_totals.)dictdatar   RANKINGCRITERIA)selfrankcriterias      M/home/james-whalen/.local/lib/python3.13/site-packages/bandit/core/metrics.py__init__Metrics.__init__   sh    F	 
		) %%D%..@A		)$}AdV%<= / &    c                 R    SSSS.U R                   U'   U R                   U   U l        g)zBegin a new metric block.

This starts a new metric collection name "fname" and makes is active.
:param fname: the metrics unique name, normally the file name.
r   r   N)r   current)r   fnames     r   beginMetrics.begin!   s/     
		%
 yy'r   c                 2    U R                   S==   U-  ss'   g)z~Note a "nosec" comment.

Increment the currently active metrics nosec count.
:param num: number of nosecs seen, defaults to 1
r
   Nr   r   nums     r   
note_nosecMetrics.note_nosec.   s     	W$r   c                 2    U R                   S==   U-  ss'   g)zNote a "nosec BXXX, BYYY, ..." comment.

Increment the currently active metrics skipped_tests count.
:param num: number of skipped_tests seen, defaults to 1
r   Nr   r    s     r   note_skipped_testMetrics.note_skipped_test6   s     	_%,%r   c                 `   ^ S mU R                   S==   [        U4S jU 5       5      -  ss'   g)zCount lines of code.

We count lines that are not empty and are not comments. The result is
added to our currently active metrics loc count (normally this is 0).

:param lines: lines in the file to process
c                 r    U R                  5       n[        U=(       a    UR                  S5      (       + 5      $ )N   #)stripbool
startswith)linetmps     r   proc Metrics.count_locs.<locals>.procG   s)    **,C8CNN4$8 899r   r	   c              3   4   >#    U  H  nT" U5      v   M     g 7fN ).0r-   r/   s     r   	<genexpr>%Metrics.count_locs.<locals>.<genexpr>K   s     "@%$4::%s   N)r   sum)r   linesr/   s     @r   
count_locsMetrics.count_locs>   s)    	: 	Us"@%"@@@r   c                 X    U R                   R                  U R                  U5      5        g r2   )r   update_get_issue_counts)r   scoress     r   count_issuesMetrics.count_issuesM   s    D226:;r   c                     [         R                  " 5       nU R                   H!  nUR                  U R                  U   5        M#     [	        U5      U R                  S'   g)z Do final aggregation of metrics.r   N)collectionsCounterr   r<   r   )r   cr   s      r   	aggregateMetrics.aggregateP   sE    !YYEHHTYYu%& #Aw		)r   c                    0 nU  Hw  n[         R                   H`  u  p4[        [         R                  5       H>  u  pVU SU 3nXq;  d  M  SX'   X#   U   [         R                  U   -  nX==   U-  ss'   M@     Mb     My     U$ )zGet issue counts aggregated by confidence/severity rankings.

:param scores: list of scores to aggregate / count
:return: aggregated total (count) of issues identified
r   r   )r   r   	enumerater   RANKING_VALUES)	r>   issue_countsscorer   _ir   labelcounts	            r   r=   Metrics._get_issue_countsW   s     E(11():):;GA'j$0E0./+!OA.(77=>  %+u4+  <  2  r   )r   r   N)   )__name__
__module____qualname____firstlineno____doc__r   r   r"   r%   r9   r?   rE   staticmethodr=   __static_attributes__r3   r   r   r   r   
   s@    B(%-A<'  r   r   )rB   bandit.corer   r   r3   r   r   <module>rZ      s   
  !` `r   