
    L-Pht                        d Z ddlmZ ddlZddlZddl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mZ ddlmZmZ ddlmZ ddlZddlmZmZ ddlmZ dd	lmZ dd
lmZmZmZmZmZm Z m!Z!m"Z" ddl#m$Z$ ddl%m&Z&m'Z' ddl(m)Z) ddl*m+Z+m,Z, ddl-m.Z. erddlm/Z/ ddl0m1Z1  ee          Zd8dZ2d8dZ3d9dZ4e G d d                      Z5e G d d                      Z6e G d d                      Z7e G d  d!                      Z8 G d" d#          Z9 G d$ d%          Z:e
j;        e
j<        z   d&z   Z=ej>        d:d)            Z?d;d,Z@ G d- d.          ZAe G d/ d0                      ZB G d1 d2          ZCd<d4ZDd=d7ZEdS )>zHTML reporting for coverage.py.    )annotationsN)	dataclassfield)AnyTYPE_CHECKING)Iterable)CoverageDataadd_data_to_hash)NoDataError)flat_rootname)
ensure_dirfile_be_goneHasherisolate_moduleformat_local_datetimehuman_sortedpluralstdout_link)get_analysis_to_report)AnalysisNumbers)Templite)TLineNoTMorf)__url__)Coverage)FileReporterfnamestrreturnc                    t           j                            t           j                            t                    d          }t           j                            ||           }|S )z9Return the path to an "htmlfiles" data file of ours.
    	htmlfiles)ospathjoindirname__file__)r   
static_dirstatic_filenames      M/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/coverage/html.pydata_filenamer+   ,   sB     bgooh77EEJgll:u55O    c                    t          t          |           d          5 }|                                cddd           S # 1 swxY w Y   dS )z+Return the contents of a data file of ours.utf-8encodingN)openr+   read)r   	data_files     r*   	read_datar4   4   s    	mE""W	5	5	5  ~~                                   s   A  AAhtmlNonec                    t          j        dd|t           j                  dz   }t          | d          5 }|                    |                    dd                     ddd           dS # 1 swxY w Y   dS )	z*Write `html` to `fname`, properly encoded.z(\A\s+)|(\s+$) )flags
wbasciixmlcharrefreplaceN)resub	MULTILINEr1   writeencode)r   r5   fouts      r*   
write_htmlrD   :   s    6#RR\BBBTID	eT		 >d

4;;w(;<<===> > > > > > > > > > > > > > > > > >s   *A--A14A1c                      e Zd ZU dZded<   ded<   ded<   ded	<   ded
<   ded<   ded<   ded<   dZded<   dZded<   dZded<   dZded<   dZ	ded<   dS )LineDataz-The data for each source line of HTML output.zlist[tuple[str, str]]tokensr   numberr   categoryz	list[str]contextscontexts_labelcontext_listshort_annotationslong_annotationsr8   r5   Nz
str | Nonecontext_strannotateannotate_long	css_class)
__name__
__module____qualname____doc____annotations__r5   rO   rP   rQ   rR    r,   r*   rF   rF   A   s         77!!!!OOOMMM    DNNNN"K""""H $M$$$$Ir,   rF   c                  2    e Zd ZU dZded<   ded<   ded<   dS )	FileDataz-The data for each source file of HTML output.r   relative_filenamer   numszlist[LineData]linesNrS   rT   rU   rV   rW   rX   r,   r*   rZ   rZ   S   s9         77MMMr,   rZ   c                  `    e Zd ZU dZdZded<   dZded<   dZded<    ee	          Z
ded	<   d
S )	IndexItemz:Information for each index entry, to render an index page.r8   r   urlfiledescriptiondefault_factoryr   r\   N)rS   rT   rU   rV   ra   rW   rb   rc   r   r   r\   rX   r,   r*   r`   r`   [   sa         DDCMMMMDNNNNKE'222D222222r,   r`   c                  Z    e Zd ZU dZded<   ded<   ded<   ded<   ded	<   d
ed<   d
ed<   dS )	IndexPagezData for each index page.r   nounr   filenamezlist[IndexItem]	summariesr   totalsintskipped_covered_countskipped_empty_countNr^   rX   r,   r*   rg   rg   d   s`         ##IIIKKKMMMOOOr,   rg   c                  &    e Zd ZdZdZddZddZdS )HtmlDataGenerationz8Generate structured data to be turned into HTML reports.z(empty)covr   r    r6   c                ~   || _         | j         j        | _        | j                                         | _        | j                                        | _        | j        j        r8| j                                        dhk    r| j                             d           | j                            | j        j	                   d S )Nr8   zNo contexts were measured)
coverageconfigget_datadatahas_arcsshow_contextsmeasured_contexts_warnset_query_contextsreport_contexts)selfrq   s     r*   __init__zHtmlDataGeneration.__init__u   s    m*M**,,		**,,;$ 	Ay**,,44##$?@@@	$$T[%@AAAAAr,   frr   analysisr   rZ   c                     j         r|                                }|j        }ni }g } j        j        r j                            |j                  }g }|                                }t          |
                                d          D ]\  }}	d}
g }g }||j        v rd}
n||j        v rd}
n j         r||v rd}
||         }t          |          ||         d         k    r/|                    d           |                    d	| d
           n||         D ]j}|dk     r|                    d           n"|                    t          |                     |                    |                    |||                     kn||j        v rd}
g }d}g }|
rc j        j        rWt%           fd|                    |d          D                       }| j        gk    r j        }nt          |           d}|}|                    t+          |	||
|||||                     t-          |                                |j        |          }|S )z.Produce the data needed for one file's report.   )startr8   excmisparr   anywherezline z5 didn't jump anywhere: it always raised an exception.exitrunc              3  *   K   | ]}|pj         V  d S N)EMPTY).0cr}   s     r*   	<genexpr>z3HtmlDataGeneration.data_for_file.<locals>.<genexpr>   s)      'd'dATZ'd'd'd'd'd'dr,   rX   z ctx)rG   rH   rI   rJ   rK   rL   rM   rN   )r[   r\   r]   )rw   missing_branch_arcsarcs_executedrt   rx   rv   contexts_by_linenori   branch_stats	enumeratesource_token_linesexcludedmissinglenappendr   missing_arc_description
statementsr   getr   rF   rZ   r[   numbers)r}   r   r   r   r   r   r]   r   linenorG   rI   rM   rN   mbabrJ   rK   rL   	file_datas   `                  r*   data_for_filez HtmlDataGeneration.data_for_file   s   = 	"*">">"@"@$2MM"$M;$ 	Q!%!=!=h>O!P!P,,..'(=(=(?(?qIII 3	 3	NFFH "!*** 8+++  !6-@#@#@ )&1s88|F3A666%,,Z888$++]]]]    18  q55-44V<<<<-44SVV<<<(//66vq-PP    8... HNL ,DK5 ,''d'd'd'dASAWAWX^`bAcAc'd'd'ddd
|++%)ZNN(+H%;%;%;N#+LLL!!-)"3!1	 	 	 	 	 	 	  2244!
 
 
	 r,   Nrq   r   r    r6   )r   r   r   r   r    rZ   )rS   rT   rU   rV   r   r~   r   rX   r,   r*   rp   rp   p   sQ        BBEB B B BJ J J J J Jr,   rp   c                      e Zd ZdZd
dZd	S )FileToReportz#A file we're considering reporting.r   r   r   r   r    r6   c                    || _         || _        t          |                                          | _        | j        dz   | _        dx| _        | _        d S )Nz.htmlr8   )r   r   r   r[   rootnamehtml_filename	prev_html	next_html)r}   r   r   s      r*   r~   zFileToReport.__init__   sL     %b&:&:&<&<==!]W4*,,r,   N)r   r   r   r   r    r6   )rS   rT   rU   rV   r~   rX   r,   r*   r   r      s.        --- - - - - -r,   r   z!#$%'()*+,-./:;=?@[]^_`{|}~nrl   c                    | dk    rt           d         S g }| rGt          | t          t                               \  } }|                    t           |                    | Gd                    |          S )zACreate a short HTML-safe string from an integer, using HTML_SAFE.r   r8   )	HTML_SAFEdivmodr   r   r%   )r   rts      r*   
encode_intr      so     	Avv|
A
 aY((1	1   771::r,   srcdest_dirc                $   t          | d          5 }|                                }ddd           n# 1 swxY w Y   t                      }|                    |           |                                dd         }t
          j                            |           }|                    dd| d          }t          t
          j        	                    ||          d          5 }|
                    |           ddd           n# 1 swxY w Y   |S )zsCopy `src` to `dest_dir`, adding a hash to the name.

    Returns the updated destination file name with hash.
    rbN   ._cb_r;   )r1   r2   r   update	hexdigestr#   r$   basenamereplacer%   rA   )r   r   ftexth
cache_bustsrc_basedests           r*   copy_with_cache_bustr      s[   
 
c4 Avvxx              AHHTNNNrr"Jw$$HC!5
!5!5!566D	bgll8T**D	1	1 Q	              Ks   266#DD	D	c                  t    e Zd ZdZg dZd(dZd)dZd*dZd+dZd,d-dZ	d+dZ
d.dZd/dZd0d!Zd1d$Zd2d&Zd'S )3HtmlReporterzHTML reporting.)z	style.csszcoverage_html.jszkeybd_closed.pngzfavicon_32.pngrq   r   r    r6   c                ,   || _         | j         j        | _        | j        j        | _        | j        j        | _        | j        | j        j        | _        | j        j        | _        | j        | j        j        | _        | j        j        }t          | j        j
                  | _
        | j                                         | _        | j                                        | _        d|                     dd          i| _        t!          | j                  | _        t%          | j                   | _        d| _        d | _        d | _        t.          t0          t2          t4          t           j        |t9          t:          j                                                  | j
        | j        | j        j        i dddddd	| _         tC          tE          d
          | j                   | _#        tE          d          | _$        tC          | j$        | j                   | _%        d S )Nrb   filesFzexc show_exczmis show_miszpar run show_parr   )r   r   r   r   )escapepairr   r   __version__title
time_stamp	extra_cssrw   rx   staticsrI   
index.htmlzpyfile.html)&rs   rt   html_dir	directoryhtml_skip_coveredskip_coveredhtml_skip_empty
skip_empty
html_titleboolr   ru   rv   rw   new_index_pageindex_pagesIncrementalCheckerincrrp   datagendirectory_was_emptyfirst_frfinal_frr   r   r   r   r   r   datetimenowrx   template_globalsr   r4   
index_tmplpyfile_html_sourcesource_tmpl)r}   rq   r   s      r*   r~   zHtmlReporter.__init__  s   m*- K9$ $ 8D+5?""k4DO&dk344M**,,		**,, D''882
 't~66	)$-88#(   #//0A0E0E0G0GHH![6
 &%)	 %!
 !
2 #9\#:#:D<QRR"+M":":#D$;T=RSSr,   rh   r   plural_nounrg   c           	     t    t          |||dk    rdn| dg t          | j        j                  dd          S )z)Create an IndexPage for a kind of region.rb   r   z_index.html)	precisionr   )rh   r   ri   rj   rk   rm   rn   )rg   r   rt   r   )r}   rh   r   s      r*   r   zHtmlReporter.new_index_page;  sS    %)V^^\\D9M9M9MT[%:;;;"# !
 
 
 	
r,   morfsIterable[TMorf] | Nonefloatc                   | j                                          | j                             | j        | j                   g }d}t          | j        |          D ]\  }}d}t          ||          }|                     || j	        d                   r|
                    |           Nt          t          j                            | j        |j                             |st#          d          |                                  |                                  |rXt)          |dd         |dd                   D ]\  }}|j        |_        |j        |_        d|d	         _        d|d         _        |D ]]}|                     |           |j                                        D ],\  }	}
|	| j	        vr|                     |	|
          | j	        |	<   -^|r|d	         j        }|d         j        }ndx}}|                     ||           |                     |           | j	        d         j        j        o| j	        d         j        j        S )
zcGenerate an HTML report for `morfs`.

        `morfs` is a list of modules or file names.

        FTrb   zNo data to report.Nr   r   r   ) r   r2   check_global_datart   r   r   rs   r   should_reportr   r   r   r#   r$   r%   r   r   r   make_directorymake_local_static_report_fileszipr   r   write_html_pager   code_region_kindsr   write_file_index_pagewrite_region_index_pagesrk   n_statements
pc_covered)r}   r   files_to_report	have_datar   r   ftrftr1ftr2rh   r   
first_html
final_htmls                r*   reportzHtmlReporter.reportG  sy    			##DK1HIII 	24=%HH 	N 	NLBIr8,,C!!(D,<V,DEE N&&s++++RW\\$.#:KLLMMMM 	42333++--- 	9!/#2#"68KLL 4 4
d!%!3!%!3+7OA(,8OB)" 	T 	TC  %%%%(V%=%=%?%? T T!kt///-1-@-@{-S-SD$T*T
  	3(+9J(,:JJ&22J"":z::: 	%%o666 V$+8 ; (/:	
r,   c                r    t          | j                   t          j        | j                  s	d| _        dS dS )z'Make sure our htmlcov directory exists.TN)r   r   r#   listdirr   r}   s    r*   r   zHtmlReporter.make_directory  s>    4>"""z$.)) 	,'+D$$$	, 	,r,   r8   r   slugc                    t          || j                  }|s3t          j                            |                              dd          }|| j        d         |<   dS )z@Copy a static file into the output directory with cache busting.r   _r   N)r   r   r#   r$   r   r   r   )r}   r   r  r   s       r*   copy_static_filezHtmlReporter.copy_static_file  sX    #C88 	;7##C((00c::D15i(...r,   c                   | j         D ]$}|                     t          |                     %| j        r/| j        j        J |                     | j        j        d           | j        ret          t          j        	                    | j
        d          dd          5 }|                    d           ddd           dS # 1 swxY w Y   dS dS )	z5Make local instances of static files for HTML report.Nr   )r  z
.gitignorewr.   r/   z# Created by coverage.py
*
)STATIC_FILESr  r+   r   rt   r   r1   r#   r$   r%   r   rA   )r}   staticfgis      r*   r   z+HtmlReporter.make_local_static_report_files  s%    ' 	9 	9F!!-"7"78888 > 	K;(444!!$+"7k!JJJ
 # 	;bgll4><@@#PWXXX ;\_		9:::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;	; 	;s   CC	Cr   r   
index_pager   c                    |j         }|xj        |z  c_        | j        r,|j        dk    }|j        dk    }|r|r|xj        dz  c_        dS | j        r|j        dk    r|xj        dz  c_        dS dS )z.Determine if we'll report this file or region.r   r   FT)	r   rk   r   	n_missingn_partial_branchesrm   r   r   rn   )r}   r   r  r\   no_missing_linesno_missing_branchess         r*   r   zHtmlReporter.should_report  s     T! 	 $! 3#'#:a#? $7 00A500u? 	 A%%..!3..utr,   r   r   c           	        | j                             | j        |j        |j                  rD| j        d         j                            | j                             |j                             dS | j	        
                    |j        |j                  }t          j        d |j        D                       }d t          d |                                D                       D             r3t#          j        d                                 D             d          }nd}|j        D ]ڊg }j        D ][\  }}|d	k    r#|                    t+          |                     .t+          |          pd
}|                    d| d| d           \d                    |          _        j        rcfdj        D             }	t3          d |	D                       t5                    d                    fd|	D                       z   _        nd_        j        r,d                    fdj        D                       _        nd_        j        rOj        }
t?          |
          dk    s'J d|j                                          d|
             |
d         _!        nd_!        g }j"        r+|                    | j#        d         j"                            d                    |          pd_$        tJ          j&                            | j'        |j(                  }| j)        *                    i |j+        ||j,        |j-        d          }t]          ||           t_          |j(        t+          |j                                                   |j        j0                  }| j        d         j                            |           | j         1                    |j        |           dS )a   Generate an HTML page for one source file.

        If the page on disk is already correct based on our incremental status
        checking, then the page doesn't have to be generated, and this function
        only does page summary bookkeeping.

        rb   Nc              3  .   K   | ]}|j         D ]}|V  d S r   )rJ   )r   cliner   s      r*   r   z/HtmlReporter.write_html_page.<locals>.<genexpr>  s1      &^&^Uu~&^&^!q&^&^&^&^&^&^&^r,   c                    i | ]\  }}||	S rX   rX   )r   iys      r*   
<dictcomp>z0HtmlReporter.write_html_page.<locals>.<dictcomp>  s    \\\&1aA\\\r,   c              3  &   K   | ]}|d          V  dS )r   NrX   )r   xs     r*   r   z/HtmlReporter.write_html_page.<locals>.<genexpr>  s&      5[5[qad5[5[5[5[5[5[r,   c                4    i | ]\  }}t          |          |S rX   r   )r   kvs      r*   r  z0HtmlReporter.write_html_page.<locals>.<dictcomp>  s$    FFFfq!AFFFr,      )indentwsz&nbsp;z<span class="z">z</span>r8   c                :    g | ]}t          |                   S rX   r  )r   	c_contextcontext_codess     r*   
<listcomp>z0HtmlReporter.write_html_page.<locals>.<listcomp>  s3     $ $ $=FJ}Y788$ $ $r,   c              3  4   K   | ]}t          |          V  d S r   )r   )r   ecs     r*   r   z/HtmlReporter.write_html_page.<locals>.<genexpr>  s(       D DRR D D D D D Dr,   c              3  B   K   | ]}|                               V  d S r   )ljust)r   r(  
code_widths     r*   r   z/HtmlReporter.write_html_page.<locals>.<genexpr>  s/      NNrbhhz22NNNNNNr,   z,&nbsp;&nbsp; c              3  0   K   | ]}j          d | V  dS )z&#x202F;&#x219B;&#x202F;N)rH   )r   dldatas     r*   r   z/HtmlReporter.write_html_page.<locals>.<genexpr>  sG       7 7 |@@Q@@7 7 7 7 7 7r,   r   zHad long annotations in z: r   rI    pln)contexts_jsonr   r   )ra   rb   r\   )2r   can_skip_filerv   r   r   r   rj   r   
index_infor   r   r   collectionsCounterr]   r   most_commonjsondumpsitemsrG   r   r%   r5   rL   maxr   rO   rM   rP   rN   r   r[   rQ   rI   r   rR   r#   r$   r   r   r   render__dict__r   r   rD   r`   r   set_index_info)r}   r   r   rJ   r1  
html_partstok_typetok_texttok_htmlencoded_contextslongscss_classes	html_pathr5   r3  r+  r%  r.  s                  @@@r*   r   zHtmlReporter.write_html_page  se    9""49cfclCC 	V$.55di6J6J3<6X6XYYYF L..svs|DD	&&^&^io&^&^&^^^\\I5[5[HDXDXDZDZ5[5[5[,[,[\\\ 	! JFF0C0C0E0EFFF  MM
 !M_ 0	= 0	=EJ&+l U U"(t##%%fX&6&67777%h//;8H%%&Sh&S&S(&S&S&STTTT,,EJ! 
'$ $ $ $JOJ\$ $ $  ! D D3C D D DDD

OOggNNNN=MNNNNNO !!
 %'!& & "2!6!6 7 7 7 7"47 7 7 " "
 "&% 	+. 5zzQTsv/G/G/I/ITTUTT ' ',Ah##&*#K~ "")*5enE   "hh{33<uEOOGLL1BCC	&& (
 (
*	(
 (
 (
   	9d### ##&224455<'
 
 


 	 *11*===	  z:::::r,   r   r   c                   |                      | j        d         ||          }t          |dt          j                            |                     }| j                            d|            | j        	                                 dS )z*Write the file index page for this report.rb   )r   r   zfile://zWrote HTML report to N)
write_index_pager   r   r#   r$   abspathrs   _messager   rA   )r}   r   r   
index_file
print_hrefs        r*   r   z"HtmlReporter.write_file_index_page  s    **V$!! + 
 

 !-Trwz7R7R-T-TUU
CzCCDDD 		r,   r   Iterable[FileToReport]c                <   |D ]]}d |j                                         D             }t          |j                                                                                   }|j                                         }|D ]}| j        |         }t          t          d|dz                       }|D ]}	|	j	        |k    r||	j
        z  }|j                            |	j
                  }
|                     |
|          sO|	j                            d          d                             d          }|j                            t'          |j         d|	j         t-          |j                                                   dt-          |           dt-          |	j                  z   d	z   |
j        
                     |j                            |          }
|                     |
|          rp|j                            t'          |j        t-          |j                                                   ddt-          |           dz   d	z   |
j        
                     _| j                                        D ] \  }}|dk    r|                     |           !dS )z,Write the other index pages for this report.c                    g | ]
}|d          S )r   rX   )r   r   s     r*   r&  z9HtmlReporter.write_region_index_pages.<locals>.<listcomp>'  s    KKKDGKKKr,   r   r   r   r  z#tz<data value='z'>z</data>)ra   rb   rc   r\   z<data value=''>z<span class='no-noun'>(no z)</span>rb   N)r   r   r   source
splitlinescode_regionsr   setrangekindr]   r   narrowr   name
rpartitionlstriprj   r   r`   r   r   r   r[   r   r9  rG  )r}   r   r   region_nouns	num_linesregionsrh   	page_dataoutside_linesregionr   sorting_namer  s                r*   r   z%HtmlReporter.write_region_index_pages$  s   " '	 '	CKK0H0H0J0JKKKLCFMMOO668899If))++G$ " " ,T2	 #E!Y]$;$; < <%  F{d** !V\1M"|226<@@H--h	BB ! #);#9#9##>#>r#B#I#I##N#NL'..y"0BBFLBB#CF$<$<$>$>??DF<,@,@DDD$V[112'( &-	0 	0 	0 	 	 	 	 <..}==%%h	:: 
'..y-#CF$<$<$>$>??-Q6$<<QQQR'( &-	0 	0 	0 	 	 	3"H !% 0 6 6 8 8 	2 	2D*v~~%%j111	2 	2r,   kwargsc                B   dx}}j         x}r#t          |j        j                  }| d| d}j        x}r#t          |j        j                  }| d| d}fd| j                                        D             }j        j        j        j        dk    rj        nd| j        ||dd|d
}|	                    |           | j
                            |          }	t          j                            | j        j                  }
t#          |
|	           |
S )	z^Write an index page specified by `index_page`.

        Returns the filename created.
        r8   r/  z" skipped due to complete coverage.z empty z	 skipped.c                    g | ]D}|j                                         |j        j        k    r|j        nd |j        j        k    dES )r8   )labelra   current)r   r   rh   ri   )r   ipr  s     r*   r&  z1HtmlReporter.write_index_page.<locals>.<listcomp>`  sd     
 
 
 	 **&(g&@&@r{{b7jo5 
 
 
r,   rb   )
r[  rk   rh   region_nounr   skipped_covered_msgskipped_empty_msgr   r   index_buttons)rm   r   rh   rn   r   valuesrj   rk   r   r   r   r;  r#   r$   r%   r   ri   rD   )r}   r  r`  rg  rh  r   wordri  render_datar5   rJ  s    `         r*   rG  zHtmlReporter.write_index_pageS  si   
 354/001 	R!Z_j.?@@D%&"Q"Q"Q"Q"Q..1 	=!Z_j.?@@D#$ < <T < < <
 
 
 
 &--//
 
 
 "+ 'O.8o.G.G:??R -#6!2*
 
 	6"""%%k22W\\$.*2EFF
:t$$$r,   Nr   )rh   r   r   r   r    rg   )r   r   r    r   r    r6   )r8   )r   r   r  r   r    r6   )r   r   r  rg   r    r   )r   r   r    r6   )r   r   r   r   r    r6   )r   rL  r    r6   )r  rg   r`  r   r    r   )rS   rT   rU   rV   r
  r~   r   r   r   r  r   r   r   r   r   rG  rX   r,   r*   r   r      s         L7T 7T 7T 7Tr

 

 

 

9
 9
 9
 9
v, , , ,6 6 6 6 6; ; ; ;&   ,\; \; \; \;|   -2 -2 -2 -2^& & & & & &r,   r   c                  D    e Zd ZU dZdZded<    ee          Zded<   dS )	FileInfozHSummary of the information from last rendering, to avoid duplicate work.r8   r   hashrd   r`   indexN)	rS   rT   rU   rV   rp  rW   r   r`   rq  rX   r,   r*   ro  ro  |  sC         RRDNNNNuY777E777777r,   ro  c                  ^    e Zd ZdZdZdZdZdd	Zdd
ZddZ	ddZ
ddZddZd dZd!dZdS )"r   a  Logic and data to support incremental reporting.

    When generating an HTML report, often only a few of the source files have
    changed since the last time we made the HTML report.  This means previously
    created HTML pages can be reused without generating them again, speeding
    the command.

    This class manages a JSON data file that captures enough information to
    know whether an HTML page for a .py file needs to be regenerated or not.
    The data file also needs to store all the information needed to create the
    entry for the file on the index page so that if the HTML page is reused,
    the index page can still be created to refer to it.

    The data looks like::

        {
            "note": "This file is an internal implementation detail ...",
            // A fixed number indicating the data format.  STATUS_FORMAT
            "format": 5,
            // The version of coverage.py
            "version": "7.4.4",
            // A hash of a number of global things, including the configuration
            // settings and the pyfile.html template itself.
            "globals": "540ee119c15d52a68a53fe6f0897346d",
            "files": {
                // An entry for each source file keyed by the flat_rootname().
                "z_7b071bdc2a35fa80___init___py": {
                    // Hash of the source, the text of the .py file.
                    "hash": "e45581a5b48f879f301c0f30bf77a50c",
                    // Information for the index.html file.
                    "index": {
                        "url": "z_7b071bdc2a35fa80___init___py.html",
                        "file": "cogapp/__init__.py",
                        "description": "",
                        // The Numbers for this file.
                        "nums": { "precision": 2, "n_files": 1, "n_statements": 43, ... }
                    }
                },
                ...
            }
        }

    zstatus.json   zThis file is an internal implementation detail to speed up HTML report generation. Its format can change at any time. You might be looking for the JSON report: https://coverage.rtfd.io/cmd.html#cmd-jsonr   r   r    r6   c                <    || _         |                                  d S r   )r   _reset)r}   r   s     r*   r~   zIncrementalChecker.__init__  s    "r,   c                "    d| _         i | _        dS )z5Initialize to empty. Causes all files to be reported.r8   N)globalsr   r  s    r*   ru  zIncrementalChecker._reset  s    *,


r,   c                   	 t           j                            | j        | j                  }t          |d          5 }t          j        |          }ddd           n# 1 swxY w Y   |d         | j        k    rd}n5|d         t          j
        k    rd}nd}n# t          t          f$ r d}Y nw xY w|ri | _        |d                                         D ]Q\  }}|d	         }t          di |}t!          di |d
         |_        t%          |d         |          }	|	| j        |<   R|d         | _        dS |                                  dS )z)Read the information we stored last time.r.   r/   NformatFversionTr   rq  r\   rp  )rp  rq  rw  rX   )r#   r$   r%   r   STATUS_FILEr1   r7  loadSTATUS_FORMATrs   r   OSError
ValueErrorr   r9  r`   r   r\   ro  rw  ru  )
r}   status_filefstatusstatususableri   filedict	indexdict
index_itemfileinfos
             r*   r2   zIncrementalChecker.read  s   	',,t~t7GHHKkG444 ,7++, , , , , , , , , , , , , , , h4#555	"h&::: $ 	 	 	FFF	  	DJ&,Wo&;&;&=&= 0 0"($W-	&3333
")">">If,=">">
#!&)$   (0
8$$!),DLLLKKMMMMMs4   ;B AB A""B %A"&B B/.B/c                b   t           j                            | j        | j                  }| j        | j        t          j        | j	        d | j
                                        D             d}t          |dd          5 }t          j        ||d           ddd           dS # 1 swxY w Y   dS )	zWrite the current status.c                >    i | ]\  }}|t          j        |          S rX   )dataclassesasdict)r   r   finfos      r*   r  z,IncrementalChecker.write.<locals>.<dictcomp>  s9        E5 {)%00  r,   )notery  rz  rw  r   r	  r.   r/   ),:)
separatorsN)r#   r$   r%   r   r{  NOTEr}  rs   r   rw  r   r9  r1   r7  dump)r}   r  status_datarC   s       r*   rA   zIncrementalChecker.write  s
   gll4>43CDDI(+| $(J$4$4$6$6  	
 	
 +sW555 	@Ik4J????	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@s   ?B$$B(+B(rv   r   c                    t                      }|D ]}|                    |           |                                }| j        |k    r|                                  || _        dS dS )a  Check the global data that can affect incremental reporting.

        Pass in whatever global information could affect the content of the
        HTML pages.  If the global data has changed since last time, this will
        clear the data so that all files are regenerated.

        N)r   r   r   rw  ru  )r}   rv   mr-  these_globalss        r*   r   z$IncrementalChecker.check_global_data  sg     HH 	 	AHHQKKKK<=((KKMMM(DLLL )(r,   r	   r   r   r   r   c                `   t                      }|                    |                                                    d                     t	          ||j        |           |                                }| j                            |t                                }||j
        k    rdS ||_
        dS )a  Can we skip reporting this file?

        `data` is a CoverageData object, `fr` is a `FileReporter`, and
        `rootname` is the name being used for the file.

        Returns True if the HTML page is fine as-is, False if we need to recreate
        the HTML page.

        r.   TF)r   r   rO  rB   r
   ri   r   r   
setdefaultro  rp  )r}   rv   r   r   r  	this_hash	file_infos          r*   r2  z IncrementalChecker.can_skip_file  s     HH	##G,,---r{A...KKMM	J))(HJJ??		&&4 'IN5r,   r   r`   c                Z    | j                             |t                                j        S )z/Get the information for index.html for `fname`.)r   r   ro  rq  )r}   r   s     r*   r3  zIncrementalChecker.index_info  s    z~~eXZZ0066r,   infoc                ^    || j                             |t                                _        dS )z/Set the information for index.html for `fname`.N)r   r  ro  rq  )r}   r   r  s      r*   r=  z!IncrementalChecker.set_index_info  s&    9=
eXZZ00666r,   N)r   r   r    r6   rm  )rv   r   r    r6   )rv   r	   r   r   r   r   r    r   )r   r   r    r`   )r   r   r  r`   r    r6   )rS   rT   rU   rV   r{  r}  r  r~   ru  r2   rA   r   r2  r3  r=  rX   r,   r*   r   r     s        * *X  KM	M 	   - - - -
   @@ @ @ @ ) ) ) )    27 7 7 7> > > > > >r,   r   r   c                V    |                      dd                               dd          S )z\HTML-escape the text in `t`.

    This is only suitable for HTML text, not attributes.

    &z&amp;<z&lt;)r   )r   s    r*   r   r   %  s(     99S'""**3777r,   ratiotuple[int, int]c                     dj         |  S )zEFormat a pair of numbers so JavaScript can read them in an attribute.z{} {})ry  )r  s    r*   r   r   /  s    7>5!!r,   )r   r   r    r   )r   r   r5   r   r    r6   )r   rl   r    r   )r   r   r   r   r    r   )r   r   r    r   )r  r  r    r   )FrV   
__future__r   r4  r  r   	functoolsr7  r#   r>   stringr   r   typingr   r   collections.abcr   rs   coverage.datar	   r
   coverage.exceptionsr   coverage.filesr   coverage.miscr   r   r   r   r   r   r   r   coverage.report_corer   coverage.resultsr   r   coverage.templiter   coverage.typesr   r   coverage.versionr   r   coverage.pluginsr   r+   r4   rD   rF   rZ   r`   rg   rp   r   ascii_lettersdigitsr   cacher   r   r   ro  r   r   r   rX   r,   r*   <module>r     sz   & % " " " " " "               				 				  ( ( ( ( ( ( ( ( % % % % % % % % $ $ $ $ $ $  8 8 8 8 8 8 8 8 + + + + + + ( ( ( ( ( (                    8 7 7 7 7 7 . . . . . . . . & & & & & & ) ) ) ) ) ) ) ) $ $ $ $ $ $  .!!!!!!------ ^B          > > > >        "         3 3 3 3 3 3 3 3        Y Y Y Y Y Y Y Yx- - - - - - - -  6=03PP	
	 	 	 	   "C C C C C C C CL 8 8 8 8 8 8 8 8]> ]> ]> ]> ]> ]> ]> ]>D8 8 8 8" " " " " "r,   