o
    q"CZ   ã                   @   sœ   d 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	m
Z
 eeƒZG dd„ deƒZG dd„ deƒZG d	d
„ d
eƒZG dd„ de	ƒZG dd„ de
ƒZdS )zSupport for plugins.é    N)ÚCoverageExceptionÚisolate_module)ÚCoveragePluginÚ
FileTracerÚFileReporterc                   @   sb   e Zd ZdZdd„ Zeddd„ƒZdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ ZeZdd„ Zdd„ ZdS )ÚPluginsz7The currently loaded collection of coverage.py plugins.c                 C   s(   g | _ i | _g | _g | _d | _d | _d S ©N)ÚorderÚnamesÚfile_tracersÚconfigurersÚcurrent_moduleÚdebug©Úself© r   úI/var/www/html/env/lib/python3.10/site-packages/coverage/plugin_support.pyÚ__init__   s   
zPlugins.__init__Nc           	      C   sh   | ƒ }||_ |D ]&}||_t|ƒ tj| }t|ddƒ}|s$td| ƒ‚| |¡}|||ƒ qd|_|S )zpLoad plugins from `modules`.

        Returns a Plugins object with the loaded and configured plugins.

        Úcoverage_initNz7Plugin module %r didn't define a coverage_init function)r   r   Ú
__import__ÚsysÚmodulesÚgetattrr   Úget_plugin_options)	Úclsr   Úconfigr   ÚpluginsÚmoduleÚmodr   Úoptionsr   r   r   Úload_plugins   s   
ÿ
zPlugins.load_pluginsc                 C   ó   |   || j¡ dS )z­Add a file tracer plugin.

        `plugin` is an instance of a third-party plugin class.  It must
        implement the :meth:`CoveragePlugin.file_tracer` method.

        N)Ú_add_pluginr   ©r   Úpluginr   r   r   Úadd_file_tracer7   ó   zPlugins.add_file_tracerc                 C   r!   )zªAdd a configuring plugin.

        `plugin` is an instance of a third-party plugin class. It must
        implement the :meth:`CoveragePlugin.configure` method.

        N)r"   r   r#   r   r   r   Úadd_configurer@   r&   zPlugins.add_configurerc                 C   s   |   |d¡ dS )zfAdd a plugin that does nothing.

        This is only useful for testing the plugin support.

        N)r"   r#   r   r   r   Úadd_noopI   s   zPlugins.add_noopc                 C   s”   d| j |jjf }| jr,| j d¡r,| j d| j |f ¡ td| j f | jƒ}t||ƒ}||_d|_	| j
 |¡ || j|< |durH| |¡ dS dS )z˜Add a plugin object.

        `plugin` is a :class:`CoveragePlugin` instance to add.  `specialized`
        is a list to append the plugin to.

        z%s.%sr$   zLoaded plugin %r: %rz	plugin %rTN)r   Ú	__class__Ú__name__r   ÚshouldÚwriteÚLabelledDebugÚDebugPluginWrapperÚ_coverage_plugin_nameÚ_coverage_enabledr	   Úappendr
   )r   r$   ÚspecializedÚplugin_nameÚlabelledr   r   r   r"   Q   s   

ÿzPlugins._add_pluginc                 C   ó
   t | jƒS r   )Úboolr	   r   r   r   r   Ú__nonzero__f   ó   
zPlugins.__nonzero__c                 C   r5   r   )Úiterr	   r   r   r   r   Ú__iter__k   r8   zPlugins.__iter__c                 C   s
   | j | S )zReturn a plugin by name.)r
   )r   r3   r   r   r   Úgetn   s   
zPlugins.getr   )r*   Ú
__module__Ú__qualname__Ú__doc__r   Úclassmethodr    r%   r'   r(   r"   r7   Ú__bool__r:   r;   r   r   r   r   r      s    			r   c                   @   s2   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ ZdS )r-   z?A Debug writer, but with labels for prepending to the messages.r   c                 C   s   t |ƒ|g | _|| _d S r   )ÚlistÚlabelsr   )r   Úlabelr   Úprev_labelsr   r   r   r   v   s   
zLabelledDebug.__init__c                 C   s   t || j| jƒS )z<Add a label to the writer, and return a new `LabelledDebug`.)r-   r   rB   )r   rC   r   r   r   Ú	add_labelz   s   zLabelledDebug.add_labelc                 C   s$   | j dg }d dd„ t|ƒD ƒ¡S )z4The prefix to use on messages, combining the labels.Ú z:
c                 s   s    � | ]\}}d | | V  qdS )z  Nr   )Ú.0ÚirC   r   r   r   Ú	<genexpr>�   s   € z/LabelledDebug.message_prefix.<locals>.<genexpr>)rB   ÚjoinÚ	enumerate)r   Úprefixesr   r   r   Úmessage_prefix~   s   zLabelledDebug.message_prefixc                 C   s   | j  d|  ¡ |f ¡ dS )z/Write `message`, but with the labels prepended.z%s%sN)r   r,   rM   )r   Úmessager   r   r   r,   ƒ   s   zLabelledDebug.writeN)r   )r*   r<   r=   r>   r   rE   rM   r,   r   r   r   r   r-   s   s    
r-   c                       s8   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Z‡  ZS )
r.   z:Wrap a plugin, and use debug to report on what it's doing.c                    s   t t| ƒ ¡  || _|| _d S r   )Úsuperr.   r   r$   r   )r   r$   r   ©r)   r   r   r   ‹   s   
zDebugPluginWrapper.__init__c                 C   sD   | j  |¡}| j d||f ¡ |r | j d|f ¡}t||ƒ}|S )Nzfile_tracer(%r) --> %rúfile %r)r$   Úfile_tracerr   r,   rE   ÚDebugFileTracerWrapper)r   ÚfilenameÚtracerr   r   r   r   rR   �   s   
zDebugPluginWrapper.file_tracerc                 C   sF   | j  |¡}| j d||f ¡ |r!| j d|f ¡}t|||ƒ}|S )Nzfile_reporter(%r) --> %rrQ   )r$   Úfile_reporterr   r,   rE   ÚDebugFileReporterWrapper©r   rT   Úreporterr   r   r   r   rV   ˜   s   z DebugPluginWrapper.file_reporterc                 C   s
   | j  ¡ S r   )r$   Úsys_infor   r   r   r   rZ       r8   zDebugPluginWrapper.sys_info)	r*   r<   r=   r>   r   rR   rV   rZ   Ú__classcell__r   r   rP   r   r.   ˆ   s    r.   c                   @   s@   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S )rS   zA debugging `FileTracer`.c                 C   s   || _ || _d S r   )rU   r   )r   rU   r   r   r   r   r   §   s   
zDebugFileTracerWrapper.__init__c                 C   s   dt j |jj¡|jf S )z7A short string identifying a frame, for debug messages.z%s@%d)ÚosÚpathÚbasenameÚf_codeÚco_filenameÚf_lineno)r   Úframer   r   r   Ú_show_frame«   s   þz"DebugFileTracerWrapper._show_framec                 C   ó    | j  ¡ }| j d|f ¡ |S )Nzsource_filename() --> %r)rU   Úsource_filenamer   r,   )r   Ú	sfilenamer   r   r   re   ²   ó   
z&DebugFileTracerWrapper.source_filenamec                 C   rd   )Nz$has_dynamic_source_filename() --> %r)rU   Úhas_dynamic_source_filenamer   r,   )r   Úhasr   r   r   rh   ·   rg   z2DebugFileTracerWrapper.has_dynamic_source_filenamec                 C   s.   | j  ||¡}| j d||  |¡|f ¡ |S )Nz&dynamic_source_filename(%r, %s) --> %r)rU   Údynamic_source_filenamer   r,   rc   )r   rT   rb   Údynr   r   r   rj   ¼   s
   ÿz.DebugFileTracerWrapper.dynamic_source_filenamec                 C   s*   | j  |¡}| j d|  |¡|f ¡ |S )Nzline_number_range(%s) --> %r)rU   Úline_number_ranger   r,   rc   )r   rb   Úpairr   r   r   rl   Ã   s   z(DebugFileTracerWrapper.line_number_rangeN)
r*   r<   r=   r>   r   rc   re   rh   rj   rl   r   r   r   r   rS   ¤   s    rS   c                       sp   e Zd ZdZ‡ f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d„ Z‡  ZS )rW   zA debugging `FileReporter`.c                    s    t t| ƒ |¡ || _|| _d S r   )rO   rW   r   rY   r   rX   rP   r   r   r   Ì   s   
z!DebugFileReporterWrapper.__init__c                 C   rd   )Nzrelative_filename() --> %r)rY   Úrelative_filenamer   r,   ©r   Úretr   r   r   rn   Ñ   rg   z*DebugFileReporterWrapper.relative_filenamec                 C   rd   )Nzlines() --> %r)rY   Úlinesr   r,   ro   r   r   r   rq   Ö   rg   zDebugFileReporterWrapper.linesc                 C   rd   )Nzexcluded_lines() --> %r)rY   Úexcluded_linesr   r,   ro   r   r   r   rr   Û   rg   z'DebugFileReporterWrapper.excluded_linesc                 C   ó$   | j  |¡}| j d||f ¡ |S )Nztranslate_lines(%r) --> %r)rY   Útranslate_linesr   r,   )r   rq   rp   r   r   r   rt   à   ó   z(DebugFileReporterWrapper.translate_linesc                 C   rs   )Nztranslate_arcs(%r) --> %r)rY   Útranslate_arcsr   r,   )r   Úarcsrp   r   r   r   rv   å   ru   z'DebugFileReporterWrapper.translate_arcsc                 C   rd   )Nzno_branch_lines() --> %r)rY   Úno_branch_linesr   r,   ro   r   r   r   rx   ê   rg   z(DebugFileReporterWrapper.no_branch_linesc                 C   rd   )Nzexit_counts() --> %r)rY   Úexit_countsr   r,   ro   r   r   r   ry   ï   rg   z$DebugFileReporterWrapper.exit_countsc                 C   rd   )Nzarcs() --> %r)rY   rw   r   r,   ro   r   r   r   rw   ô   rg   zDebugFileReporterWrapper.arcsc                 C   s$   | j  ¡ }| j dt|ƒf ¡ |S )Nzsource() --> %d chars)rY   Úsourcer   r,   Úlenro   r   r   r   rz   ù   s   
zDebugFileReporterWrapper.sourcec                 C   s(   t | j ¡ ƒ}| j dt|ƒf ¡ |S )Nz"source_token_lines() --> %d tokens)rA   rY   Úsource_token_linesr   r,   r{   ro   r   r   r   r|   þ   s   z+DebugFileReporterWrapper.source_token_lines)r*   r<   r=   r>   r   rn   rq   rr   rt   rv   rx   ry   rw   rz   r|   r[   r   r   rP   r   rW   É   s    rW   )r>   r\   Úos.pathr   Úcoverage.miscr   r   Úcoverage.pluginr   r   r   Úobjectr   r-   r.   rS   rW   r   r   r   r   Ú<module>   s   c%