o
    ·›îY�;  ã                   @   sü   d 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 ddl	m
Z
 ddlmZmZmZmZ ddlmZ ddlmZ dd	lmZ eeƒZd
ej ej e¡d¡gZddd„Zdd„ Zdd„ ZG dd„ deƒZG dd„ deƒZ dd„ Z!dd„ Z"dS )zHTML reporting for coverage.py.é    N)Úenv)Úiitems)Úflat_rootname)ÚCoverageExceptionÚfile_be_goneÚHasherÚisolate_module)ÚReporter)ÚNumbers)ÚTemplitez/usr/share/javascriptÚ	htmlfilesÚ c                 C   s‚   g }t D ]1}tj || ¡}tj |¡r|  S | |¡ |r5tj ||| ¡}tj |¡r0|  S | |¡ qtd| t ¡ |f ƒ‚)a  Return the path to a data file of ours.

    The file is searched for on `STATIC_PATH`, and the first place it's found,
    is returned.

    Each directory in `STATIC_PATH` is searched as-is, and also, if `pkgdir`
    is provided, at that sub-directory.

    z/Couldn't find static file %r from %r, tried: %r)ÚSTATIC_PATHÚosÚpathÚjoinÚexistsÚappendr   Úgetcwd)ÚfnameÚpkgdirÚtriedÚ
static_dirÚstatic_filename© r   ú?/var/www/html/env/lib/python3.10/site-packages/coverage/html.pyÚdata_filename!   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)r   Ú	data_filer   r   r   Ú	read_data=   s   $ÿr    c                 C   sB   t | dƒ�}| | dd¡¡ W d  ƒ dS 1 sw   Y  dS )z*Write `html` to `fname`, properly encoded.ÚwbÚasciiÚxmlcharrefreplaceN)r   ÚwriteÚencode)r   ÚhtmlÚfoutr   r   r   Ú
write_htmlC   s   "ÿr(   c                       sP   e Zd ZdZg d¢Z‡ fdd„Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
‡  ZS )ÚHtmlReporterzHTML reporting.)	)z	style.cssr   )zjquery.min.jsÚjquery)z"jquery.ba-throttle-debounce.min.jszjquery-throttle-debounce)zjquery.hotkeys.jszjquery-hotkeys)zjquery.isonscreen.jszjquery-isonscreen)zjquery.tablesorter.min.jszjquery-tablesorter)zcoverage_html.jsr   )zkeybd_closed.pngr   )zkeybd_open.pngr   c                    s¤   t t| ƒ ||¡ d | _| jj}tjr| d¡}t	t
|tjtjdœ| _ttdƒ| jƒ| _|| _g | _g | _| jj ¡ | _tƒ | _d | _tƒ | _tj ¡  d¡| _d S )NÚutf8)ÚescapeÚpairÚtitleÚ__url__Ú__version__zpyfile.htmlz%Y-%m-%d %H:%M)Úsuperr)   Ú__init__Ú	directoryÚconfigÚ
html_titler   ÚPY2Údecoder,   r-   Úcoverager/   r0   Útemplate_globalsr   r    Úsource_tmplÚfilesÚall_files_numsÚdataÚhas_arcsÚ
HtmlStatusÚstatusÚ	extra_cssr
   ÚtotalsÚdatetimeÚnowÚstrftimeÚ
time_stamp)ÚselfÚcovr4   r.   ©Ú	__class__r   r   r2   Z   s(   
ûzHtmlReporter.__init__c                 C   sº   | j jsJ dƒ‚| j | j j¡ tƒ }| | j ¡ | ¡ }| j ¡ |kr/| j ¡  | j 	|¡ | j j
r<tj | j j
¡| _
|  | j|| j j¡ | jsMtdƒ‚|  ¡  |  ¡  | jjo\| jjS )zcGenerate an HTML report for `morfs`.

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

        z(must give a directory for html reportingzNo data to report.)r4   Úhtml_dirr@   r   r   ÚupdateÚ	hexdigestÚsettings_hashÚresetÚset_settings_hashrA   r   r   ÚbasenameÚreport_filesÚ	html_filer<   r   Ú
index_fileÚmake_local_static_report_filesrB   Ún_statementsÚ
pc_covered)rG   ÚmorfsÚmÚthese_settingsr   r   r   Úreports   s    
zHtmlReporter.reportc                 C   sZ   | j D ]\}}t t||ƒtj | j|¡¡ q| jr+t | j	jtj | j| j¡¡ dS dS )z5Make local instances of static files for HTML report.N)
ÚSTATIC_FILESÚshutilÚcopyfiler   r   r   r   r3   rA   r4   )rG   Ústaticr   r   r   r   rU   –   s   þþÿz+HtmlReporter.make_local_static_report_filesc                 C   s*   t ƒ }| |¡ | jj |j|¡ | ¡ S )z@Compute a hash that changes if the file needs to be re-reported.)r   rL   r8   r=   Úadd_to_hashÚfilenamerM   )rG   ÚsourceÚfrrY   r   r   r   Ú	file_hash¦   s   
zHtmlReporter.file_hashc                    sþ  t | ¡ ƒ}|d }tj | j|¡}|j}| j |¡ | j	j
r3|jdk}|jdk}|r3|r3t|ƒ dS | ¡ }	|  |	 d¡|¡}
| j |¡}|
|krV| j | j |¡¡ dS | j ||
¡ | jrh| ¡ }| ¡ }d}d}d}d| }g }t| ¡ d	d
�D ]Ò\‰ }g }d}d}ˆ |jv r�| d¡ ˆ |jv r›| |¡ nwˆ |jv r¦| |¡ nl| j�rˆ |v �r| |¡ g }g }|ˆ  D ]}|dk rÈ| d¡ n| |¡ | | ˆ ||¡¡ q¼d‰d ‡ ‡fdd„|D ƒ¡}t|ƒd	krò|d }n dt|ƒd dd„ t|d	d
�D ƒ¡f }nˆ |jv �r| |¡ g }|D ]#\}}|dk�r(| t|ƒ¡ �qt|ƒ�p.d}| d||f ¡ �q| d |¡ˆ d |¡�pHd||dœ¡ q|| j  !||||| j| j"|||| j#dœ
¡}t$||ƒ ||| ¡ dœ}| j |¡ | j %||¡ dS )z*Generate an HTML file for one source file.z.htmlr   Nzutf-8zrun hide_runÚexcÚmiszpar é   )Ústartr   ÚstmÚexitz%s&#x202F;&#x219B;&#x202F;%sz,&nbsp;&nbsp; c                 3   s   � | ]	}ˆˆ |f V  qd S ©Nr   )Ú.0Úd©ÚlinenoÚ	short_fmtr   r   Ú	<genexpr>ð   s   € z)HtmlReporter.html_file.<locals>.<genexpr>z%d missed branches: %sz, c                 s   s    � | ]\}}d ||f V  qdS )z%d) %sNr   )rl   ÚnumÚann_longr   r   r   rq   ÷   s   € ÿÚwsz&nbsp;z<span class="%s">%s</span>ú Úpln)r&   ÚnumberÚclassÚannotateÚannotate_long)
Úc_excÚc_misÚc_parÚc_runr>   rA   rc   ÚnumsÚlinesrF   )r   Úhtml_filenameÚrelative_filename)&r   r‚   r   r   r   r3   Únumbersr<   r   r4   Úskip_coveredÚ	n_missingÚn_partial_branchesr   rb   rd   r%   r@   r;   Ú
index_infoÚset_file_hashr>   Úmissing_branch_arcsÚarcs_executedÚ	enumerateÚsource_token_linesÚ
statementsÚexcludedÚmissingÚmissing_arc_descriptionÚlenr,   r:   ÚrenderrA   rF   r(   Úset_index_info)rG   rc   ÚanalysisÚrootnamer�   Ú	html_pathr   Úno_missing_linesÚno_missing_branchesrb   Ú	this_hashÚ	that_hashr‰   rŠ   r~   r{   r|   r}   r€   ÚlineÚ
line_classÚannotate_htmlrz   ÚshortsÚlongsÚbr&   Útok_typeÚtok_textÚtok_htmlr‡   r   rn   r   rS   ­   s¶   










ÿþ


ÿ
û	ö
ýzHtmlReporter.html_filec                 C   sd   t tdƒ| jƒ}t| jƒ| _| | j| j| j	| j| j
dœ¡}ttj | jd¡|ƒ | j | j¡ dS )z*Write the index.html file for this report.z
index.html)r>   rA   r;   rB   rF   N)r   r    r9   Úsumr<   rB   r’   r>   rA   r;   rF   r(   r   r   r   r3   r@   r$   )rG   Ú
index_tmplr&   r   r   r   rT   )  s   ûzHtmlReporter.index_file)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r\   r2   r[   rU   rd   rS   rT   Ú__classcell__r   r   rI   r   r)   I   s    #|r)   c                   @   sh   e 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d„ Zdd„ ZdS )r?   z@The status information we keep to support incremental reporting.zstatus.jsonrg   c                 C   s   |   ¡  d S rk   )rO   ©rG   r   r   r   r2   _  s   zHtmlStatus.__init__c                 C   s   d| _ i | _dS )zInitialize to empty.r   N)Úsettingsr;   r«   r   r   r   rO   b  s   
zHtmlStatus.resetc              	   C   sî   d}z$t j || j¡}t|dƒ�}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 | _t|d ƒD ]\}}t|d d	 Ž |d d	< || j|< qT|d
 | _dS |  ¡  dS )z$Read the last status in `directory`.FÚrNTÚformatÚversionr;   Úindexr   r¬   )r   r   r   ÚSTATUS_FILEr   ÚjsonÚloadÚIOErrorÚ
ValueErrorÚSTATUS_FORMATr8   r0   r;   r   r
   r¬   rO   )rG   r3   ÚusableÚstatus_fileÚfstatusr@   ra   Úfileinfor   r   r   r   g  s,   ÿ€ÿzHtmlStatus.readc           	      C   sè   t j || j¡}i }t| jƒD ]\}}|d d  ¡ |d d< |||< q| jtj	| j
|dœ}t|dƒ�}tj||dd� W d  ƒ n1 sFw   Y  dt jv rrtt j |d	¡dƒ�}| d
¡ W d  ƒ dS 1 skw   Y  dS dS )z(Write the current status to `directory`.r°   r   )r®   r¯   r¬   r;   Úw)ú,ú:)Ú
separatorsNÚJENKINS_URLz
status.datz3https://issues.jenkins-ci.org/browse/JENKINS-28428
)r   r   r   r±   r   r;   Ú	init_argsr¶   r8   r0   r¬   r   r²   ÚdumpÚenvironr$   )	rG   r3   r¸   r;   ra   rº   r@   r'   Údatr   r   r   r$   €  s$   
üÿ
"ÿÿzHtmlStatus.writec                 C   s   | j S )z)Get the hash of the coverage.py settings.©r¬   r«   r   r   r   rN   ˜  s   zHtmlStatus.settings_hashc                 C   s
   || _ dS )z)Set the hash of the coverage.py settings.NrÄ   )rG   r¬   r   r   r   rP   œ  s   
zHtmlStatus.set_settings_hashc                 C   s   | j  |i ¡ dd¡S )z#Get the hash of `fname`'s contents.Úhashr   ©r;   Úget©rG   r   r   r   r   rd      ó   zHtmlStatus.file_hashc                 C   ó   || j  |i ¡d< dS )z#Set the hash of `fname`'s contents.rÅ   N©r;   Ú
setdefault)rG   r   Úvalr   r   r   rˆ   ¤  rÉ   zHtmlStatus.set_file_hashc                 C   s   | j  |i ¡ di ¡S )z/Get the information for index.html for `fname`.r°   rÆ   rÈ   r   r   r   r‡   ¨  rÉ   zHtmlStatus.index_infoc                 C   rÊ   )z/Set the information for index.html for `fname`.r°   NrË   )rG   r   Úinfor   r   r   r“   ¬  rÉ   zHtmlStatus.set_index_infoN)r¦   r§   r¨   r©   r±   r¶   r2   rO   r   r$   rN   rP   rd   rˆ   r‡   r“   r   r   r   r   r?   =  s    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)Útr   r   r   r,   ³  s   r,   c                 C   s   d|  S )zEFormat a pair of numbers so JavaScript can read them in an attribute.z%s %sr   )Úratior   r   r   r-   ½  s   r-   )r   )#r©   rC   r²   r   r]   r8   r   Úcoverage.backwardr   Úcoverage.filesr   Úcoverage.miscr   r   r   r   Úcoverage.reportr	   Úcoverage.resultsr
   Úcoverage.templiter   r   r   ÚdirnameÚ__file__r   r   r    r(   r)   Úobjectr?   r,   r-   r   r   r   r   Ú<module>   s2   û
	 uv
