o
    ·ËdZâB  ã                   @   s–   d Z ddlZddlZddlZddlZddlmZmZmZ ddl	m
Z
mZmZ eeƒZG dd„ dejƒZdgZdgZd	d
gZG dd„ deƒZdd„ ZdS )zConfig file for coverage.pyé    N)ÚconfigparserÚiitemsÚstring_class)ÚcontractÚCoverageExceptionÚisolate_modulec                   @   sX   e 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S )ÚHandyConfigParserz#Our specialization of ConfigParser.c                 C   s,   t j | ¡ dg| _|r| j d¡ dS dS )zÞCreate the HandyConfigParser.

        `our_file` is True if this config file is specifically for coverage,
        False if we are examining another config file (tox.ini, setup.cfg)
        for possible settings.
        z	coverage:Ú N)r   ÚRawConfigParserÚ__init__Úsection_prefixesÚappend)ÚselfÚour_file© r   úA/var/www/html/env/lib/python3.10/site-packages/coverage/config.pyr      s
   ÿzHandyConfigParser.__init__c                 C   s,   i }t jdkrd|d< tjj| |fi |¤ŽS )z-Read a file name as UTF-8 configuration data.)é   é   zutf-8Úencoding)ÚsysÚversion_infor   r
   Úread)r   Ú	filenamesÚkwargsr   r   r   r   !   s   
zHandyConfigParser.readc                 C   s4   | j D ]}|| }tj | ||¡}|r|  S qdS ©NF)r   r   r
   Ú
has_option)r   ÚsectionÚoptionÚsection_prefixÚreal_sectionÚhasr   r   r   r   (   s   
ÿzHandyConfigParser.has_optionc                 C   s2   | j D ]}|| }tj | |¡}|r|  S qdS r   )r   r   r
   Úhas_section)r   r   r   r   r    r   r   r   r!   0   s   
ÿzHandyConfigParser.has_sectionc                 C   s:   | j D ]}|| }tj | |¡rtj | |¡  S qtj‚©N)r   r   r
   r!   ÚoptionsÚNoSectionError)r   r   r   r   r   r   r   r#   8   s   
ÿzHandyConfigParser.optionsc                 C   s(   i }|   |¡D ]
}|  ||¡||< q|S )z/Get the contents of a section, as a dictionary.)r#   Úget)r   r   ÚdÚoptr   r   r   Úget_section?   s   zHandyConfigParser.get_sectionc           
      O   sj   | j D ]}|| }tj | ||¡r nqtj‚tjj| ||g|¢R i |¤Ž}dd„ }d}	t |	||¡}|S )a   Get a value, replacing environment variables also.

        The arguments are the same as `RawConfigParser.get`, but in the found
        value, ``$WORD`` or ``${WORD}`` are replaced by the value of the
        environment variable ``WORD``.

        Returns the finished value.

        c                 S   s0   t dd„ |  ¡ D ƒƒ}|dkrdS tj |d¡S )zCalled for each $replacement.c                 s   s   � | ]	}|d ur|V  qd S r"   r   )Ú.0Úwr   r   r   Ú	<genexpr>[   s   € z@HandyConfigParser.get.<locals>.dollar_replace.<locals>.<genexpr>ú$r	   )ÚnextÚgroupsÚosÚenvironr%   )ÚmÚwordr   r   r   Údollar_replaceX   s   z-HandyConfigParser.get.<locals>.dollar_replacea$  (?x)   # Use extended regex syntax
            \$(?:                   # A dollar sign, then
            (?P<v1>\w+) |           #   a plain word,
            {(?P<v2>\w+)} |         #   or a {-wrapped word,
            (?P<char>[$])           #   or a dollar sign.
            )
            )r   r   r
   r   ÚNoOptionErrorr%   ÚreÚsub)
r   r   r   Úargsr   r   r   Úvr3   Údollar_patternr   r   r   r%   F   s   

ÿ	zHandyConfigParser.getc                 C   sJ   |   ||¡}g }| d¡D ]}| d¡D ]}| ¡ }|r!| |¡ qq|S )zâRead a list of strings.

        The value of `section` and `option` is treated as a comma- and newline-
        separated list of strings.  Each value is stripped of whitespace.

        Returns the list of strings.

        Ú
ú,)r%   ÚsplitÚstripr   )r   r   r   Ú
value_listÚvaluesÚ
value_lineÚvaluer   r   r   Úgetlistk   s   	
€ýzHandyConfigParser.getlistc                 C   sv   |   ||¡}g }| ¡ D ],}| ¡ }zt |¡ W n tjy0 } z
td||||f ƒ‚d}~ww |r8| |¡ q|S )zàRead a list of full-line regexes.

        The value of `section` and `option` is treated as a newline-separated
        list of regexes.  Each value is stripped of whitespace.

        Returns the list of strings.

        zInvalid [%s].%s value %r: %sN)r%   Ú
splitlinesr=   r5   ÚcompileÚerrorr   r   )r   r   r   Ú	line_listr>   rA   Úer   r   r   Úgetregexlist}   s    	ÿ€ÿ
€zHandyConfigParser.getregexlistN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r!   r#   r(   r%   rB   rH   r   r   r   r   r      s    %r   z3#\s*(pragma|PRAGMA)[:\s]?\s*(no|NO)\s*(cover|COVER)z5#\s*(pragma|PRAGMA)[:\s]?\s*(no|NO)\s*(branch|BRANCH)zwhile (True|1|False|0):zif (True|1|False|0):c                   @   sd   e Zd ZdZdd„ Zg d¢Zdd„ Zeed�dd	„ ƒZ	g d
¢Z
ddd„Zdd„ Zdd„ Zdd„ ZdS )ÚCoverageConfigzŠCoverage.py configuration.

    The attributes of this class are the various settings that control the
    operation of coverage.py.

    c                 C   sè   g | _ g | _d| _d| _d| _d| _d| _d| _g | _g | _	d| _
d| _g | _d| _d| _d| _d| _tdd… | _d| _d| _d| _d| _tdd… | _tdd… | _d| _d| _d| _d| _d| _d| _ d| _!d	| _"i | _#i | _$dS )
z:Initialize the configuration attributes to their defaults.NFz	.coverageg        r   ÚhtmlcovzCoverage reportzcoverage.xmléc   )%Úattempted_config_filesÚconfig_filesÚ_includeÚ_omitÚbranchÚconcurrencyÚcover_pylibÚ	data_fileÚdebugÚdisable_warningsÚnoteÚparallelÚpluginsÚsourceÚrun_includeÚrun_omitÚtimidÚDEFAULT_EXCLUDEÚexclude_listÚ
fail_underÚignore_errorsÚreport_includeÚreport_omitÚDEFAULT_PARTIAL_ALWAYSÚpartial_always_listÚDEFAULT_PARTIALÚpartial_listÚ	precisionÚshow_missingÚskip_coveredÚ	extra_cssÚhtml_dirÚ
html_titleÚ
xml_outputÚxml_package_depthÚpathsÚplugin_options)r   r   r   r   r   ¯   sD   
zCoverageConfig.__init__)rX   rU   r\   rf   re   r_   r^   c                 K   sD   t |ƒD ]\}}|dur|| jv rt|tƒr|g}t| ||ƒ qdS )z!Read config values from `kwargs`.N)r   ÚMUST_BE_LISTÚ
isinstancer   Úsetattr)r   r   Úkr8   r   r   r   Ú	from_argsé   s   €üzCoverageConfig.from_args)Úfilenamec              
   C   sž  | j  |¡ t|ƒ}z| |¡}W n tjy& } ztd||f ƒ‚d}~ww |s+dS | j |¡ d}z| j	D ]}| j
|g|¢R Ž }|rFd}q7W n ty\ } ztd||f ƒ‚d}~ww t t¡}	| j	D ]}|d  d¡\}
}|	|
  |¡ qet|	ƒD ]\}
}| |
¡}|r›t| |
¡ƒ| D ]
}td|||f ƒ‚q|| d¡r´| d¡D ]}| d|¡| j|< d}q¦| jD ]}| |¡rÈ| |¡| j|< d}q·|rÍdS |S )	a…  Read configuration from a .rc file.

        `filename` is a file name to read.

        `our_file` is True if this config file is specifically for coverage,
        False if we are examining another config file (tox.ini, setup.cfg)
        for possible settings.

        Returns True or False, whether the file could be read, and it had some
        coverage.py settings in it.

        z Couldn't read config file %s: %sNFTé   ú:z0Unrecognized option '[%s] %s=' in config file %srs   )rP   r   r   r   r   ÚErrorr   rQ   ÚextendÚCONFIG_FILE_OPTIONSÚ_set_attr_from_config_optionÚ
ValueErrorÚcollectionsÚdefaultdictÚsetr<   Úaddr   r!   r#   rB   rs   r\   r(   rt   )r   rz   r   ÚcpÚ
files_readÚerrÚany_setÚoption_specÚwas_setÚall_optionsr   r   r#   r   ÚunknownÚpluginr   r   r   Ú	from_fileñ   sb   €ÿ
€ý€ÿ


ÿÿ€


€zCoverageConfig.from_file))rT   z
run:branchÚboolean)rU   zrun:concurrencyÚlist)rV   zrun:cover_pylibr�   )rW   zrun:data_file)rX   z	run:debugr‘   )rY   zrun:disable_warningsr‘   )rZ   zrun:note)r[   zrun:parallelr�   )r\   zrun:pluginsr‘   )r^   zrun:includer‘   )r_   zrun:omitr‘   )r]   z
run:sourcer‘   )r`   z	run:timidr�   )rb   zreport:exclude_linesÚ	regexlist)rc   zreport:fail_underÚfloat)rd   zreport:ignore_errorsr�   )rh   zreport:partial_branches_alwaysr’   )rj   zreport:partial_branchesr’   )rk   zreport:precisionÚint)re   zreport:includer‘   )rf   zreport:omitr‘   )rl   zreport:show_missingr�   )rm   zreport:skip_coveredr�   )Úsortzreport:sort)rn   zhtml:extra_css)ro   zhtml:directory)rp   z
html:title)rq   z
xml:output)rr   zxml:package_depthr”   r	   c                 C   sB   |  d¡\}}| ||¡rt|d| ƒ}t| ||||ƒƒ dS dS )ztSet an attribute on self if it exists in the ConfigParser.

        Returns True if the attribute was set.

        r|   r%   TF)r<   r   Úgetattrrw   )r   r†   ÚattrÚwhereÚtype_r   r   Úmethodr   r   r   r€   g  s   z+CoverageConfig._set_attr_from_config_optionc                 C   s   | j  |i ¡S )z:Get a dictionary of options for the plugin named `plugin`.)rt   r%   )r   rŽ   r   r   r   Úget_plugin_optionst  s   z!CoverageConfig.get_plugin_optionsc           	      C   sv   | j D ]}|dd… \}}||krt| ||ƒ  dS q| d¡\}}}|r5|| jv r5|| j |i ¡|< dS td| ƒ‚)aB  Set an option in the configuration.

        `option_name` is a colon-separated string indicating the section and
        option name.  For example, the ``branch`` option in the ``[run]``
        section of the config file would be indicated with `"run:branch"`.

        `value` is the new value for the option.

        Nr   r|   úNo such option: %r)r   rw   Ú	partitionr\   rt   Ú
setdefaultr   )	r   Úoption_namerA   rŠ   r—   r˜   Úplugin_nameÚ_Úkeyr   r   r   Ú
set_optionx  s   
þzCoverageConfig.set_optionc                 C   sp   | j D ]}|dd… \}}||krt| |ƒ  S q| d¡\}}}|r2|| jv r2| j |i ¡ |¡S td| ƒ‚)a<  Get an option from the configuration.

        `option_name` is a colon-separated string indicating the section and
        option name.  For example, the ``branch`` option in the ``[run]``
        section of the config file would be indicated with `"run:branch"`.

        Returns the value of the option.

        Nr   r|   rœ   )r   r–   r�   r\   rt   r%   r   )r   rŸ   rŠ   r—   r˜   r    r¡   r¢   r   r   r   Ú
get_option“  s   
ÿzCoverageConfig.get_optionN)r	   )rI   rJ   rK   rL   r   ru   ry   r   Ústrr�   r   r€   r›   r£   r¤   r   r   r   r   rM   ¨   s    4
F
/rM   c           
      K   sþ   t ƒ }| r:| dkrd} | du}|sd} | dfddfD ]\}}|j||d�}|| k}|s5|r5|r5td| ƒ‚|r9 nqtj d¡}|rE||_tj d¡}	|	r[|j d	d
„ |	 	d¡D ƒ¡ |j
di |¤Ž tj |j¡|_tj |j¡|_tj |j¡|_| |fS )a  Read the coverage.py configuration.

    Arguments:
        config_file: a boolean or string, see the `Coverage` class for the
            tricky details.
        all others: keyword arguments from the `Coverage` class, used for
            setting values in the configuration.

    Returns:
        config_file, config:
            config_file is the value to use for config_file in other
            invocations of coverage.

            config is a CoverageConfig object read from the appropriate
            configuration file.

    z.coveragercT)z	setup.cfgF)ztox.iniF)r   z#Couldn't read '%s' as a config fileÚCOVERAGE_FILEÚCOVERAGE_DEBUGc                 s   s   � | ]}|  ¡ V  qd S r"   )r=   )r)   r&   r   r   r   r+   Þ  s   € z'read_coverage_config.<locals>.<genexpr>r;   Nr   )rM   r�   r   r/   r0   r%   rW   rX   r~   r<   ry   ÚpathÚ
expanduserro   rq   )
Úconfig_filer   ÚconfigÚspecified_fileÚfnamer   Úconfig_readÚis_config_fileÚenv_data_fileÚdebugsr   r   r   Úread_coverage_config¬  s:   þÿr²   )rL   r‚   r/   r5   r   Úcoverage.backwardr   r   r   Úcoverage.miscr   r   r   r
   r   ra   ri   rg   ÚobjectrM   r²   r   r   r   r   Ú<module>   s*    ÿÿþ  