B
    ê¹`6M  ã               @   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	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 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d„ ZdS )zConfig file for coverage.pyé    N)Úenv)ÚconfigparserÚiitemsÚstring_class)ÚcontractÚCoverageExceptionÚisolate_module)Úsubstitute_variables)ÚTomlConfigParserÚTomlDecodeErrorc               @   sZ   e Zd ZdZdd„ Zd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 )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   úW/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/coverage/config.pyr      s    zHandyConfigParser.__init__Nc             C   s,   i }t jdkr|pd|d< tjj| |f|ŽS )z-Read a file name as UTF-8 configuration data.)é   é   zutf-8Úencoding)r   Z	PYVERSIONr   r   Úread)r   Ú	filenamesr   Úkwargsr   r   r   r   &   s    
zHandyConfigParser.readc             C   s4   x.| j D ]$}|| }tj | ||¡}|r|S qW 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   x,| j D ]"}|| }tj | |¡}|r|S qW dS )NF)r   r   r   Úhas_section)r   r   r   r    r!   r   r   r   r"   5   s    zHandyConfigParser.has_sectionc             C   sB   x2| j D ](}|| }tj | |¡rtj | |¡S qW t |¡‚d S )N)r   r   r   r"   ÚoptionsÚNoSectionError)r   r   r   r    r   r   r   r#   =   s
    zHandyConfigParser.optionsc             C   s,   i }x"|   |¡D ]}|  ||¡||< qW |S )z/Get the contents of a section, as a dictionary.)r#   Úget)r   r   ÚdÚoptr   r   r   Úget_sectionD   s    zHandyConfigParser.get_sectionc             O   s^   x4| j D ]}|| }tj | ||¡rP qW t ||¡‚tjj| ||f|ž|Ž}t|tjƒ}|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.

        )	r   r   r   r   ÚNoOptionErrorr%   r	   ÚosÚenviron)r   r   r   Úargsr   r   r    Úvr   r   r   r%   K   s    
zHandyConfigParser.getc             C   sR   |   ||¡}g }x<| d¡D ].}x(| d¡D ]}| ¡ }|r,| |¡ q,W qW |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ÚvaluesZ
value_lineÚvaluer   r   r   Úgetlist`   s    	zHandyConfigParser.getlistc             C   s„   |   ||¡}g }xn| ¡ D ]b}| ¡ }yt |¡ W n8 tjk
rl } ztd||||f ƒ‚W dd}~X Y nX |r| |¡ qW |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%   Ú
splitlinesr1   ÚreÚcompileÚerrorr   r   )r   r   r   Z	line_listr2   r4   Úer   r   r   Úgetregexlistr   s    	$zHandyConfigParser.getregexlist)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r"   r#   r(   r%   r5   r;   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            +   @   sØ   e Zd ZdZdd„ Zdddddd	d
gZdd„ Zeeddd„ ƒZ	dd„ Z
ddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<g+ZdKd>d?„Zd@dA„ ZdBdC„ ZdDdE„ ZdFdG„ ZdHdI„ ZdJS )LÚCoverageConfigzŠCoverage.py configuration.

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

    c             C   sR  g | _ g | _d| _d| _d| _d| _d| _d| _d| _d| _	d| _
d| _g | _g | _d| _d| _d| _g | _d| _d| _d| _d| _g | _d| _d| _tdd… | _d| _d| _d| _d| _tdd… | _ t!dd… | _"d| _#d| _$d| _%d| _&d| _'d| _(d| _)d| _*d| _+d| _,d| _-d| _.d| _/d	| _0d
| _1d| _2d| _3t4 5¡ | _6i | _7dS )z:Initialize the configuration attributes to their defaults.NFz	.coverageg        r   ZhtmlcovzCoverage reportzcoverage.xmléc   zcoverage.json)8Úattempted_config_filesÚconfig_files_readÚconfig_fileÚ_config_contentsZ_includeZ_omitÚbranchÚcommand_lineÚconcurrencyÚcontextÚcover_pylibÚ	data_fileÚdebugÚdisable_warningsÚdynamic_contextÚnoteÚparallelÚpluginsÚrelative_filesÚrun_includeÚrun_omitÚsourceÚsource_pkgsÚtimidÚ_crashÚDEFAULT_EXCLUDEÚexclude_listÚ
fail_underÚignore_errorsÚreport_includeÚreport_omitÚDEFAULT_PARTIAL_ALWAYSÚpartial_always_listÚDEFAULT_PARTIALÚpartial_listÚ	precisionÚreport_contextsÚshow_missingÚskip_coveredÚ
skip_emptyÚsortÚ	extra_cssÚhtml_dirÚhtml_skip_coveredÚhtml_skip_emptyÚ
html_titleÚshow_contextsÚ
xml_outputÚxml_package_depthÚjson_outputÚjson_pretty_printÚjson_show_contextsÚcollectionsÚOrderedDictÚpathsÚplugin_options)r   r   r   r   r   ¦   sf    
zCoverageConfig.__init__rL   rH   rQ   r^   r]   rT   rS   c             K   sH   xBt |ƒD ]6\}}|dk	r
|| jkr4t|tƒr4|g}t| ||ƒ q
W dS )z!Read config values from `kwargs`.N)r   ÚMUST_BE_LISTÚ
isinstancer   Úsetattr)r   r   Úkr-   r   r   r   Ú	from_argsö   s
    zCoverageConfig.from_args)Úfilenamec          
   C   sF  t j |¡\}}|dkr"t|ƒ}nt|ƒ}| j |¡ y| |¡}W n8 tj	t
fk
r| } ztd||f ƒ‚W dd}~X Y nX |s†dS | j tt jj|ƒ¡ d}y,x&| jD ]}	| j|f|	žŽ }
|
rªd}qªW W n2 tk
rþ } ztd||f ƒ‚W dd}~X Y nX t t¡}x0| jD ]&}	|	d  d¡\}}||  |¡ qW xVt|ƒD ]J\}}| |¡}|rFx.t| |¡ƒ| D ]}td|||f ƒ‚qrW qFW | d	¡rÌx*| d	¡D ]}| d	|¡| j|< d}q¬W x0| jD ]&}| |¡rÔ| |¡| j|< d}qÔW |r
d}n|}|rBt j |¡| _ t!|d
ƒ}| ¡ | _"W dQ R X |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.tomlz Couldn't read config file %s: %sNFTé   ú:z0Unrecognized option '[%s] %s=' in config file %srv   Úrb)#r*   ÚpathÚsplitextr
   r   rB   r   r   r   ÚErrorr   r   rC   ÚextendÚmapÚabspathÚCONFIG_FILE_OPTIONSÚ_set_attr_from_config_optionÚ
ValueErrorrt   ÚdefaultdictÚsetr0   Úaddr   r"   r#   r5   rv   rQ   r(   rw   rD   ÚopenrE   )r   r}   r   Ú_ÚextÚcpZ
files_readÚerrZany_setÚoption_specZwas_setZall_optionsr   r   r#   r    ÚunknownÚpluginÚusedÚfr   r   r   Ú	from_fileþ   s^    
""



zCoverageConfig.from_filec             C   s
   t  | ¡S )z#Return a copy of the configuration.)ÚcopyÚdeepcopy)r   r   r   r   r˜   Q  s    zCoverageConfig.copy)rF   z
run:branchÚboolean)rG   zrun:command_line)rH   zrun:concurrencyÚlist)rI   zrun:context)rJ   zrun:cover_pylibrš   )rK   zrun:data_file)rL   z	run:debugr›   )rM   zrun:disable_warningsr›   )rN   zrun:dynamic_context)rO   zrun:note)rP   zrun:parallelrš   )rQ   zrun:pluginsr›   )rR   zrun:relative_filesrš   )rS   zrun:includer›   )rT   zrun:omitr›   )rU   z
run:sourcer›   )rV   zrun:source_pkgsr›   )rW   z	run:timidrš   )rX   z
run:_crash)rZ   zreport:exclude_linesÚ	regexlist)r[   zreport:fail_underÚfloat)r\   zreport:ignore_errorsrš   )r`   zreport:partial_branches_alwaysrœ   )rb   zreport:partial_branchesrœ   )rc   zreport:precisionÚint)rd   zreport:contextsr›   )r]   zreport:includer›   )r^   zreport:omitr›   )re   zreport:show_missingrš   )rf   zreport:skip_coveredrš   )rg   zreport:skip_emptyrš   )rh   zreport:sort)ri   zhtml:extra_css)rj   zhtml:directory)rk   zhtml:skip_coveredrš   )rl   zhtml:skip_emptyrš   )rm   z
html:title)rn   zhtml:show_contextsrš   )ro   z
xml:output)rp   zxml:package_depthrž   )rq   zjson:output)rr   zjson:pretty_printrš   )rs   zjson:show_contextsrš   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)r0   r   Úgetattrrz   )r   r   ÚattrÚwhereÚtype_r   r   Úmethodr   r   r   rˆ   ”  s    z+CoverageConfig._set_attr_from_config_optionc             C   s   | j  |i ¡S )z:Get a dictionary of options for the plugin named `plugin`.)rw   r%   )r   r”   r   r   r   Úget_plugin_options¡  s    z!CoverageConfig.get_plugin_optionsc       	      C   sŽ   |dkr|| _ dS x6| jD ],}|dd… \}}||krt| ||ƒ dS qW | d¡\}}}|r~|| jkr~|| j |i ¡|< dS td| ƒ‚dS )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.

        rv   Nr   r   zNo such option: %r)rv   r‡   rz   Ú	partitionrQ   rw   Ú
setdefaultr   )	r   Úoption_namer4   r’   r    r¡   Úplugin_namerŽ   Úkeyr   r   r   Ú
set_option¥  s    zCoverageConfig.set_optionc             C   s‚   |dkr| j S x0| jD ]&}|dd… \}}||krt| |ƒS qW | d¡\}}}|rr|| jkrr| j |i ¡ |¡S td| ƒ‚dS )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.

        rv   Nr   r   zNo such option: %r)rv   r‡   rŸ   r¥   rQ   rw   r%   r   )r   r§   r’   r    r¡   r¨   rŽ   r©   r   r   r   Ú
get_optionÄ  s    zCoverageConfig.get_optionc             C   s   t j |¡S )z8Make final adjustments to a file path to make it usable.)r*   r   Ú
expanduser)r   r   r   r   r   Úpost_process_fileà  s    z CoverageConfig.post_process_filec                sN   ˆ   ˆ j¡ˆ _ˆ   ˆ j¡ˆ _ˆ   ˆ j¡ˆ _t ‡ fdd„ˆ j ¡ D ƒ¡ˆ _dS )z7Make final adjustments to settings to make them usable.c             3   s(   | ] \}}|‡ fd d„|D ƒfV  qdS )c                s   g | ]}ˆ   |¡‘qS r   )r­   )Ú.0r–   )r   r   r   ú
<listcomp>ê  s    z9CoverageConfig.post_process.<locals>.<genexpr>.<listcomp>Nr   )r®   r{   r-   )r   r   r   ú	<genexpr>ê  s   z.CoverageConfig.post_process.<locals>.<genexpr>N)r­   rK   rj   ro   rt   ru   rv   Úitems)r   r   )r   r   Úpost_processä  s    
zCoverageConfig.post_processN)r   )r<   r=   r>   r?   r   rx   r|   r   Ústrr—   r˜   r‡   rˆ   r¤   rª   r«   r­   r²   r   r   r   r   r@      sr   KS
r@   c             C   sJ   | dkrd} | dk	}|s,t j d¡} | r,d}|s4d} | d|fdddg}|S )z€What config files should we try to read?

    Returns a list of tuples:
        (filename, is_our_file, was_file_specified)
    z.coveragercTZCOVERAGE_RCFILE)z	setup.cfgFF)ztox.iniFF)zpyproject.tomlFF)r*   r+   r%   )rD   Úspecified_fileÚfiles_to_tryr   r   r   Úconfig_files_to_tryï  s    	r¶   c       
      K   s¤   t ƒ }| rJt| ƒ}x6|D ].\}}}|j||d}|r6P |rtd| ƒ‚qW tj d¡}|r`||_tj d¡}	|	rŒ|j 	dd„ |	 
d¡D ƒ¡ |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:
            config is a CoverageConfig object read from the appropriate
            configuration file.

    )r   z#Couldn't read '%s' as a config fileZCOVERAGE_FILEZCOVERAGE_DEBUGc             s   s   | ]}|  ¡ V  qd S )N)r1   )r®   r&   r   r   r   r°   1  s    z'read_coverage_config.<locals>.<genexpr>r/   )r@   r¶   r—   r   r*   r+   r%   rK   rL   r„   r0   r|   r²   )
rD   r   Úconfigrµ   Úfnamer   r´   Zconfig_readZenv_data_fileZdebugsr   r   r   Úread_coverage_config  s$    r¹   )r?   rt   r˜   r*   Úos.pathr7   Zcoverager   Zcoverage.backwardr   r   r   Zcoverage.miscr   r   r   r	   Zcoverage.tomlconfigr
   r   r   r   rY   ra   r_   Úobjectr@   r¶   r¹   r   r   r   r   Ú<module>   s*   v  T