o
    gy[                     @  s0  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 ddlmZmZmZmZmZmZmZ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# dd
l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/m0Z0 ddl1m2Z2 erddlm3Z3 ddl4m5Z5 ddlm6Z6 G dd de6Z7G dd de6Z8e"eZd;ddZ9d;ddZ:d<d d!Z;eG d"d# d#Z<eG d$d% d%Z=G d&d' d'Z>G d(d) d)Z?e
j@e
jA d* ZBejCdd+d=d.d/ZDG d0d1 d1ZEG d2d3 d3ZFd>d5d6ZGd?d9d:ZHdS )@zHTML reporting for coverage.py.    )annotationsN)	dataclass)AnyDictIterableListOptionalTupleTYPE_CHECKINGcast)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)	TypedDictc                   @  s*   e Zd ZU dZded< ded< ded< dS )IndexInfoDictz4Information for each file, to render the index file.r   numsstrhtml_filenamerelative_filenameN__name__
__module____qualname____doc____annotations__ r-   r-   M/var/www/html/bloggers_ems/venv/lib/python3.10/site-packages/coverage/html.pyr"   )   s
   
 r"   c                   @  s"   e Zd ZU dZded< ded< dS )FileInfoDictzHSummary of the information from last rendering, to avoid duplicate work.r$   hashr"   indexNr'   r-   r-   r-   r.   r/   /   s   
 r/   fnamer$   returnc                 C  s(   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__)r2   
static_dirstatic_filenamer-   r-   r.   data_filename8   s   r<   c                 C  s8   t t| }| W  d   S 1 sw   Y  dS )z+Return the contents of a data file of ours.N)openr<   read)r2   	data_filer-   r-   r.   	read_data@   s   $r@   htmlNonec                 C  sZ   t jdd|t jdd }t| d}||dd W d   dS 1 s&w   Y  dS )	z*Write `html` to `fname`, properly encoded.z(\A\s+)|(\s+$) )flags
wbasciixmlcharrefreplaceN)resub	MULTILINEr=   writeencode)r2   rA   foutr-   r-   r.   
write_htmlF   s   "rO   c                   @  s   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
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$   categorybool	statementz	List[str]contextscontexts_labelcontext_listshort_annotationslong_annotationsrC   rA   NzOptional[str]context_strannotateannotate_long	css_class)
r(   r)   r*   r+   r,   rA   r[   r\   r]   r^   r-   r-   r-   r.   rP   M   s    
 rP   c                   @  s*   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$   r&   r   r#   zList[LineData]linesNr'   r-   r-   r-   r.   r_   `   s
   
 r_   c                   @  s(   e Zd ZdZdZdddZdddZdS )HtmlDataGenerationz8Generate structured data to be turned into HTML reports.z(empty)covr   r3   rB   c                 C  sX   || _ | j j| _| j  }| | _| jjr#| dhkr#| j d || jj d S )NrC   zNo contexts were measured)	coverageconfigget_datahas_arcsshow_contextsmeasured_contexts_warnset_query_contextsreport_contexts)selfrb   datar-   r-   r.   __init__m   s   


zHtmlDataGeneration.__init__frr    analysisr   r_   c                   sv   j r| }| } jjr|j|j}g }t|	 ddD ]\}}d}	g }
g }||j
v r2d}	n;||jv r:d}	n3 j rf||v rfd}	|| D ]}|dk rS|
d n|
t| ||||| qGn||jv rmd	}	g }d}g }|	r jjrt fd
d||dD }| jgkr j}n	t| d}|}|t|||	||jv ||||
|d	 q t| |j|d}|S )z.Produce the data needed for one file's report.   startrC   excmisparr   exitrunc                 3  s    | ]}|p j V  qd S N)EMPTY).0crl   r-   r.   	<genexpr>       z3HtmlDataGeneration.data_for_file.<locals>.<genexpr>r-   z ctx)	rQ   rR   rS   rU   rV   rW   rX   rY   rZ   )r&   r#   r`   )rf   missing_branch_arcsarcs_executedrd   rg   rm   contexts_by_linenofilename	enumeratesource_token_linesexcludedmissingappendr$   missing_arc_description
statementsr   getrz   lenrP   r_   r&   numbers)rl   ro   rp   r   r   r   r`   linenorQ   rS   rY   rZ   brV   rW   rX   	file_datar-   r}   r.   data_for_filew   sd   



z HtmlDataGeneration.data_for_fileNrb   r   r3   rB   )ro   r    rp   r   r3   r_   )r(   r)   r*   r+   rz   rn   r   r-   r-   r-   r.   ra   h   s
    

ra   c                   @  s   e Zd ZdZddd	Zd
S )FileToReportz#A file we're considering reporting.ro   r    rp   r   r3   rB   c                 C  s*   || _ || _t| | _| jd | _d S )Nz.html)ro   rp   r   r&   rootnamer%   )rl   ro   rp   r-   r-   r.   rn      s   zFileToReport.__init__N)ro   r    rp   r   r3   rB   )r(   r)   r*   r+   rn   r-   r-   r-   r.   r      s    r   z!#$%'()*+,-./:;=?@[]^_`{|}~)maxsizenintc                 C  sF   | dkrt d S g }| rt| tt \} }|t |  | sd|S )zACreate a short HTML-safe string from an integer, using HTML_SAFE.r   rC   )	HTML_SAFEdivmodr   r   r7   )r   rtr-   r-   r.   
encode_int   s   
r   c                   @  s^   e Zd ZdZg dZd!ddZd"ddZd#ddZd#ddZd$ddZ	d%ddZ
d&ddZd S )'HtmlReporterzHTML reporting.)z	style.csszcoverage_html.jszkeybd_closed.pngzkeybd_open.pngzfavicon_32.pngrb   r   r3   rB   c                 C  sH  || _ | j j| _| jj| _| jj| _| jd u r| jj| _| jj| _| jd u r+| jj| _d| _d| _	| jj
}|  | jjrEtj| jj| _nd | _| j  | _| j | _g | _g | _t| j| _t| j | _t| jjd| _d| _d | _d | _ttt t!t j"|t#t$j$% | j| j| jj&dddddd	| _'t(d
| _)t*| j)| j'| _+d S )Nr   )	precisionFzexc show_exczmis show_miszpar run show_parrx   )rt   ru   rv   rx   )escapepairr   r   __version__title
time_stamp	extra_cssrf   rg   rS   zpyfile.html),rc   rd   html_dir	directoryhtml_skip_coveredskip_coveredhtml_skip_empty
skip_emptyskipped_covered_countskipped_empty_count
html_titler   r5   r6   basenamere   rm   rf   file_summariesall_files_numsIncrementalCheckerincrra   datagenr   r   totalsdirectory_was_emptyfirst_frfinal_frr   r   r   r   r   r   datetimenowrg   template_globalsr@   pyfile_html_sourcer   source_tmpl)rl   rb   r   r-   r-   r.   rn      sX   








zHtmlReporter.__init__morfsOptional[Iterable[TMorf]]floatc                 C  s6  | j   | j | j| j g }t| j|D ]!\}}t||}| |}|r,|	| qt
tj| j|j qt|D ]+\}}|dkrGd}n||d  j}|t|d krYd}	n||d  j}	| |||	 q<| jsotdttt| j| _|r|d j}
|d j}nd }
}| |
| |   | jjo| jjS )zcGenerate an HTML report for `morfs`.

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

        r   
index.htmlrq   zNo data to report.)r   r>   check_global_datard   r   r   rc   r   should_report_filer   r   r5   r6   r7   r   r%   r   r   write_html_filer   r   r   r   sumr   
index_filemake_local_static_report_filesn_statements
pc_covered)rl   r   files_to_reportro   rp   ftrshouldi	prev_html	next_html
first_html
final_htmlr-   r-   r.   report  s6   



zHtmlReporter.reportc                 C  s$   t | j t| jsd| _dS dS )z'Make sure our htmlcov directory exists.TN)r   r   r5   listdirr   r}   r-   r-   r.   make_directoryK  s   

zHtmlReporter.make_directoryc                 C  s   | j D ]}tt|tj| j| q| jr7t	tj| jdd}|
d W d   n1 s2w   Y  | jrS| jjdusBJ t| jjtj| j| j dS dS )z5Make local instances of static files for HTML report.z
.gitignorewz# Created by coverage.py
*
N)STATIC_FILESshutilcopyfiler<   r5   r6   r7   r   r   r=   rL   r   rd   )rl   staticfgir-   r-   r.   r   Q  s   
"z+HtmlReporter.make_local_static_report_filesr   r   rT   c                 C  sn   |j j}| j| | jr$|jdk}|jdk}|r$|r$|  jd7  _dS | jr5|j	dkr5|  j
d7  _
dS dS )z$Determine if we'll report this file.r   rq   FT)rp   r   r   r   r   	n_missingn_partial_branchesr   r   r   r   )rl   r   r#   no_missing_linesno_missing_branchesr-   r-   r.   r   c  s   


zHtmlReporter.should_report_filer   r$   r   c                   s  |    | j| j|j|jr| j| j|j dS | j	
|j|j}tdd |jD }dd tdd | D D rQtjdd  D dd	}nd}|jD ]g }jD ]"\}}	|d
krm|t|	 q]t|	prd}
|d| d|
 d q]d|_jrfddjD }tdd |D  t d fdd|D  _nd_jrdfddjD _nd_jrj}t|dkr|d _ nd!t|ddd t|ddD _ nd_ g }j"r|| j#d j"  d|p	d_$qVt%j&| j'|j(}| j)*i |j+|||d}t,|| |jj-|j(|j. d }| j| | j/|j| dS )!z*Generate an HTML file for one source file.Nc                 s  s     | ]}|j D ]}|V  qqd S ry   )rV   )r{   cliner|   r-   r-   r.   r~     s    z/HtmlReporter.write_html_file.<locals>.<genexpr>c                 S  s   i | ]\}}||qS r-   r-   )r{   r   yr-   r-   r.   
<dictcomp>  s    z0HtmlReporter.write_html_file.<locals>.<dictcomp>c                 s  s    | ]}|d  V  qdS )r   Nr-   )r{   xr-   r-   r.   r~         c                 S  s   i | ]	\}}t ||qS r-   r   )r{   kvr-   r-   r.   r     s       )indentwsz&nbsp;z<span class="z">z</span>rC   c                   s   g | ]}t  | qS r-   r   )r{   	c_context)context_codesr-   r.   
<listcomp>  s    z0HtmlReporter.write_html_file.<locals>.<listcomp>c                 s  s    | ]}t |V  qd S ry   )r   r{   ecr-   r-   r.   r~     r   c                 3  s    | ]}|  V  qd S ry   )ljustr   )
code_widthr-   r.   r~     r   z,&nbsp;&nbsp; c                 3  s     | ]} j  d | V  qdS )z&#x202F;&#x219B;&#x202F;N)rR   )r{   d)ldatar-   r.   r~     s
    
rq   r   z{:d} missed branches: {}z, c                 s  s$    | ]\}}|d d| V  qdS )r   z) Nr-   )r{   numann_longr-   r-   r.   r~     s
    
rr   rS    pln)contexts_jsonr   r   )r#   r%   r&   )0r   r   can_skip_filerm   ro   r   r   r   
index_infor   r   rp   collectionsCounterr`   r   most_commonjsondumpsitemsrQ   r   r7   rA   rX   maxr$   r[   rY   r\   rZ   r   r]   formatrS   r   r^   r5   r6   r   r%   r   render__dict__rO   r   r&   set_index_info)rl   r   r   r   r   rV   r   
html_partstok_typetok_texttok_htmlencoded_contextslongscss_classes	html_pathrA   r   r-   )r   r   r   r.   r   z  s    





zHtmlReporter.write_html_filer   r   c           
   	   C  s   |    ttd| j}d }}| jr | j}| dt| d}| jr0| j}| dt| d}|| j| j	||||d}t
j| jd}t|| t|dt
j| }	| jd	|	  | j  d
S )z*Write the index.html file for this report.r   rC   z filez" skipped due to complete coverage.z empty filez	 skipped.)filesr   skipped_covered_msgskipped_empty_msgr   r   zfile://zWrote HTML report to N)r   r   r@   r   r   r   r   r  r   r   r5   r6   r7   r   rO   r   abspathrc   _messager   rL   )
rl   r   r   
index_tmplr  r  r   rA   r   
print_hrefr-   r-   r.   r     s,   	
zHtmlReporter.index_fileNr   )r   r   r3   r   r3   rB   )r   r   r3   rT   )r   r   r   r$   r   r$   r3   rB   )r   r$   r   r$   r3   rB   )r(   r)   r*   r+   r   rn   r   r   r   r   r   r   r-   r-   r-   r.   r      s    

=
2


^r   c                   @  s   e Zd ZdZdZdZdZd)d	d
Zd*ddZd*ddZ	d*ddZ
d+ddZd,ddZd-ddZd.d d!Zd/d#d$Zd0d&d'Zd(S )1r   z0Logic and data to support incremental reporting.zstatus.jsonr   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$   r3   rB   c                 C  s   || _ |   d S ry   )r   reset)rl   r   r-   r-   r.   rn     s   zIncrementalChecker.__init__c                 C  s   d| _ i | _dS )z5Initialize to empty. Causes all files to be reported.rC   N)globalsr  r}   r-   r-   r.   r  "  s   
zIncrementalChecker.resetc              	   C  s   d}z$t j| j| j}t|}t|}W d   n1 s w   Y  W n tt	fy3   d}Y nw d}|d | j
kr@d}n	|d tjkrId}|rqi | _|d  D ]\}}t|d d  |d d< || j|< qT|d	 | _dS |   dS )
z)Read the information we stored last time.FNTr  versionr  r1   r#   r  )r5   r6   r7   r   STATUS_FILEr=   r   loadOSError
ValueErrorSTATUS_FORMATrc   r   r  r   r   r  r  )rl   usablestatus_filefstatusstatusr   fileinfor-   r-   r.   r>   '  s,   
zIncrementalChecker.readc                 C  s   t j| j| j}i }| j D ]\}}|d }|d  |d< |||< q| j| j	t
j| j|d}t|d}tj||dd W d   dS 1 sJw   Y  dS )zWrite the current status.r1   r#   )noter  r  r  r  r   ),:)
separatorsN)r5   r6   r7   r   r  r  r   	init_argsNOTEr  rc   r   r  r=   r   dump)rl   r  r  r   r!  r1   r   rN   r-   r-   r.   rL   @  s   
"zIncrementalChecker.writerm   r   c                 G  sB   t  }|D ]}|| q| }| j|kr|   || _dS dS )z<Check the global data that can affect incremental reporting.N)r   update	hexdigestr  r  )rl   rm   mr   these_globalsr-   r-   r.   r   S  s   

z$IncrementalChecker.check_global_datar   ro   r    r   rT   c                 C  sV   t  }|| d t||j| | }| |}||kr#dS | || dS )zCan we skip reporting this file?

        `data` is a CoverageData object, `fr` is a `FileReporter`, and
        `rootname` is the name being used for the file.
        zutf-8TF)	r   r)  sourcerM   r   r   r*  	file_hashset_file_hash)rl   rm   ro   r   r+  	this_hash	that_hashr-   r-   r.   r   ]  s   
z IncrementalChecker.can_skip_filer2   c                 C  s   | j |i ddS )z#Get the hash of `fname`'s contents.r0   rC   r  r   rl   r2   r-   r-   r.   r.  q     zIncrementalChecker.file_hashvalc                 C     || j |i d< dS )z#Set the hash of `fname`'s contents.r0   Nr  
setdefault)rl   r2   r5  r-   r-   r.   r/  u  r4  z IncrementalChecker.set_file_hashr"   c                 C  s   | j |i di S )z/Get the information for index.html for `fname`.r1   r2  r3  r-   r-   r.   r   y  r4  zIncrementalChecker.index_infoinfoc                 C  r6  )z/Set the information for index.html for `fname`.r1   Nr7  )rl   r2   r9  r-   r-   r.   r  }  r4  z!IncrementalChecker.set_index_infoN)r   r$   r3   rB   r  )rm   r   r3   rB   )rm   r   ro   r    r   r$   r3   rT   r2   r$   r3   r$   )r2   r$   r5  r$   r3   rB   )r2   r$   r3   r"   )r2   r$   r9  r"   r3   rB   )r(   r)   r*   r+   r  r  r'  rn   r  r>   rL   r   r   r.  r/  r   r  r-   r-   r-   r.   r     s     
!








r   r   c                 C  s   |  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;)replace)r   r-   r-   r.   r     s   r   ratioTuple[int, int]c                 C  s   d|  S )zEFormat a pair of numbers so JavaScript can read them in an attribute.z%s %sr-   )r>  r-   r-   r.   r     s   r   r:  )r2   r$   rA   r$   r3   rB   )r   r   r3   r$   )r   r$   r3   r$   )r>  r?  r3   r$   )Ir+   
__future__r   r   r   	functoolsr   r5   rI   r   stringdataclassesr   typingr   r   r   r   r   r	   r
   r   rc   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!   r"   r/   r<   r@   rO   rP   r_   ra   r   ascii_lettersdigitsr   	lru_cacher   r   r   r   r   r-   r-   r-   r.   <module>   sb   (


O	
  + 

