o
    v&i(                     @  s  d Z ddlm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
 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 dd
lmZmZmZmZmZmZ eeZG dd dZeegdf ZG dd d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.    )annotationsN)IterableIterator)	FrameType)AnyCallable)PluginError)isolate_module)CoveragePluginFileReporter
FileTracer)TArcTConfigurable	TDebugCtlTLineNoTPluginConfigTSourceTokenLinesc                   @  s   e Zd ZdZd+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d1d"d#Zd2d%d&Zd3d)d*ZdS )4Pluginsz7The currently loaded collection of coverage.py plugins.NdebugTDebugCtl | NonereturnNonec                 C  s.   g | _ i | _g | _g | _g | _d | _|| _d S N)ordernamesfile_tracersconfigurerscontext_switcherscurrent_moduler   )selfr    r    ]/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/coverage/plugin_support.py__init__   s   
zPlugins.__init__modulesIterable[str]configr   c                 C  s`   |D ](}|| _ t| tj| }t|dd}|s td|d||}|| | qd| _ dS )z@Load plugin modules, and read their settings from configuration.coverage_initNzPlugin module z' didn't define a coverage_init function)r   
__import__sysr#   getattrr   get_plugin_options)r   r#   r%   modulemodr&   optionsr    r    r!   load_from_config$   s   



zPlugins.load_from_configplugin_initsIterable[TCoverageInit]c                 C  s   |D ]}||  qdS )z%Load plugins from callables provided.Nr    )r   r/   fnr    r    r!   load_from_callables;   s   
zPlugins.load_from_callablespluginr
   c                 C     |  || j dS )zAdd 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   r3   r    r    r!   add_file_tracerC      zPlugins.add_file_tracerc                 C  r4   )zAdd a configuring plugin.

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

        N)r5   r   r6   r    r    r!   add_configurerL   r8   zPlugins.add_configurerc                 C  r4   )zAdd a dynamic context plugin.

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

        N)r5   r   r6   r    r    r!   add_dynamic_contextU   r8   zPlugins.add_dynamic_contextc                 C  s   |  |d dS )zfAdd a plugin that does nothing.

        This is only useful for testing the plugin support.

        N)r5   r6   r    r    r!   add_noop^   s   zPlugins.add_noopspecializedlist[CoveragePlugin] | Nonec                 C  s   | j  d|jj }| jr/| jdr/| jd| j d| td| j | j}t||}||_d|_	| j
| || j|< |durK|| dS dS )zAdd a plugin object.

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

        .r3   zLoaded plugin z: zplugin TN)r   	__class____name__r   shouldwriteLabelledDebugDebugPluginWrapper_coverage_plugin_name_coverage_enabledr   appendr   )r   r3   r<   plugin_namelabelledr    r    r!   r5   f   s   

zPlugins._add_pluginboolc                 C  
   t | jS r   )rJ   r   r   r    r    r!   __bool__~      
zPlugins.__bool__Iterator[CoveragePlugin]c                 C  rK   r   )iterr   rL   r    r    r!   __iter__   rN   zPlugins.__iter__rH   strc                 C  s
   | j | S )zReturn a plugin by name.)r   )r   rH   r    r    r!   get   s   
zPlugins.getr   )r   r   r   r   )r#   r$   r%   r   r   r   )r/   r0   r   r   )r3   r
   r   r   )r3   r
   r<   r=   r   r   r   rJ   )r   rO   )rH   rR   r   r
   )r@   
__module____qualname____doc__r"   r.   r2   r7   r9   r:   r;   r5   rM   rQ   rS   r    r    r    r!   r      s    




	
	
	


r   c                   @  s:   e Zd ZdZddd	d
ZdddZdddZdddZdS )rC   z?A Debug writer, but with labels for prepending to the messages.r    labelrR   r   r   prev_labelsr$   c                 C  s   t ||g | _|| _d S r   )listlabelsr   )r   rX   r   rY   r    r    r!   r"      s   
zLabelledDebug.__init__r   c                 C  s   t || j| jS )z<Add a label to the writer, and return a new `LabelledDebug`.)rC   r   r[   )r   rX   r    r    r!   	add_label   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irX   r    r    r!   	<genexpr>   s    z/LabelledDebug.message_prefix.<locals>.<genexpr>)r[   join	enumerate)r   prefixesr    r    r!   message_prefix   s   zLabelledDebug.message_prefixmessager   c                 C  s   | j |   |  dS )z/Write `message`, but with the labels prepended.N)r   rB   rd   )r   re   r    r    r!   rB      s   zLabelledDebug.writeN)r    )rX   rR   r   r   rY   r$   )rX   rR   r   rC   r   rR   )re   rR   r   r   )r@   rU   rV   rW   r"   r\   rd   rB   r    r    r    r!   rC      s    

rC   c                      s^   e Zd ZdZd" f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
  ZS ))rD   z:Wrap a plugin, and use debug to report on what it's doing.r3   r
   r   rC   r   r   c                   s   t    || _|| _d S r   )superr"   r3   r   )r   r3   r   r?   r    r!   r"      s   

zDebugPluginWrapper.__init__filenamerR   FileTracer | Nonec                 C  sH   | j |}| jd|d| |r"| jd|}t||}|S )Nzfile_tracer() --> file )r3   file_tracerr   rB   r\   DebugFileTracerWrapper)r   ri   tracerr   r    r    r!   rm      s   
zDebugPluginWrapper.file_tracerFileReporter | strc                 C  sX   | j |}t|tsJ | jd|d| |r*| jd|}t|||}|S )Nzfile_reporter(rk   rl   )r3   file_reporter
isinstancer   r   rB   r\   DebugFileReporterWrapperr   ri   reporterr   r    r    r!   rq      s   z DebugPluginWrapper.file_reporterframer   
str | Nonec                 C  (   | j |}| jd|d| |S )Nzdynamic_context(rk   )r3   dynamic_contextr   rB   )r   rv   contextr    r    r!   ry         z"DebugPluginWrapper.dynamic_contextsrc_dirr$   c                 C  rx   )Nzfind_executable_files(rk   )r3   find_executable_filesr   rB   )r   r|   executable_filesr    r    r!   r}      r{   z(DebugPluginWrapper.find_executable_filesr%   r   c                 C  s$   | j d|d | j| d S )Nz
configure())r   rB   r3   	configure)r   r%   r    r    r!   r      s   zDebugPluginWrapper.configureIterable[tuple[str, Any]]c                 C  s
   | j  S r   )r3   sys_inforL   r    r    r!   r      rN   zDebugPluginWrapper.sys_info)r3   r
   r   rC   r   r   )ri   rR   r   rj   )ri   rR   r   rp   )rv   r   r   rw   )r|   rR   r   r$   )r%   r   r   r   )r   r   )r@   rU   rV   rW   r"   rm   rq   ry   r}   r   r   __classcell__r    r    rh   r!   rD      s    


	

rD   c                   @  sL   e 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S )"rn   zA debugging `FileTracer`.ro   r   r   rC   r   r   c                 C  s   || _ || _d S r   )ro   r   )r   ro   r   r    r    r!   r"      s   
zDebugFileTracerWrapper.__init__rv   r   rR   c                 C  s    t j|jj}| d|j S )z7A short string identifying a frame, for debug messages.@)ospathbasenamef_codeco_filenamef_lineno)r   rv   ri   r    r    r!   _show_frame   s   z"DebugFileTracerWrapper._show_framec                 C      | j  }| jd| |S )Nzsource_filename() --> )ro   source_filenamer   rB   )r   	sfilenamer    r    r!   r         
z&DebugFileTracerWrapper.source_filenamerJ   c                 C  r   )Nz"has_dynamic_source_filename() --> )ro   has_dynamic_source_filenamer   rB   )r   hasr    r    r!   r      r   z2DebugFileTracerWrapper.has_dynamic_source_filenameri   rw   c                 C  s.   | j ||}| jd|| || |S )Nz*dynamic_source_filename({!r}, {}) --> {!r})ro   dynamic_source_filenamer   rB   formatr   )r   ri   rv   dynr    r    r!   r      s   z.DebugFileTracerWrapper.dynamic_source_filenametuple[TLineNo, TLineNo]c                 C  s.   | j |}| jd| | d| |S )Nzline_number_range(rk   )ro   line_number_ranger   rB   r   )r   rv   pairr    r    r!   r      s   z(DebugFileTracerWrapper.line_number_rangeN)ro   r   r   rC   r   r   )rv   r   r   rR   rf   rT   )ri   rR   rv   r   r   rw   )rv   r   r   r   )
r@   rU   rV   rW   r"   r   r   r   r   r   r    r    r    r!   rn      s    




rn   c                      s   e Zd ZdZd( f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d)d#d$Zd/d&d'Z  ZS )0rs   zA debugging `FileReporter`.ri   rR   ru   r   r   rC   r   r   c                   s   t  | || _|| _d S r   )rg   r"   ru   r   rt   rh   r    r!   r"      s   
z!DebugFileReporterWrapper.__init__c                 C  r   )Nzrelative_filename() --> )ru   relative_filenamer   rB   r   retr    r    r!   r      r   z*DebugFileReporterWrapper.relative_filenameset[TLineNo]c                 C  r   )Nzlines() --> )ru   linesr   rB   r   r    r    r!   r      r   zDebugFileReporterWrapper.linesc                 C  r   )Nzexcluded_lines() --> )ru   excluded_linesr   rB   r   r    r    r!   r     r   z'DebugFileReporterWrapper.excluded_linesr   Iterable[TLineNo]c                 C  rx   )Nztranslate_lines(rk   )ru   translate_linesr   rB   )r   r   r   r    r    r!   r   
  r{   z(DebugFileReporterWrapper.translate_linesarcsIterable[TArc]	set[TArc]c                 C  rx   )Nztranslate_arcs(rk   )ru   translate_arcsr   rB   )r   r   r   r    r    r!   r     r{   z'DebugFileReporterWrapper.translate_arcsc                 C  r   )Nzno_branch_lines() --> )ru   no_branch_linesr   rB   r   r    r    r!   r     r   z(DebugFileReporterWrapper.no_branch_linesdict[TLineNo, int]c                 C  r   )Nzexit_counts() --> )ru   exit_countsr   rB   r   r    r    r!   r     r   z$DebugFileReporterWrapper.exit_countsc                 C  r   )Nzarcs() --> )ru   r   r   rB   r   r    r    r!   r     r   zDebugFileReporterWrapper.arcsc                 C  s&   | j  }| jdt| d |S )Nzsource() --> z chars)ru   sourcer   rB   lenr   r    r    r!   r   #  s   
zDebugFileReporterWrapper.sourcer   c                 C  s*   t | j }| jdt| d |S )Nzsource_token_lines() --> z tokens)rZ   ru   source_token_linesr   rB   r   r   r    r    r!   r   (  s   z+DebugFileReporterWrapper.source_token_lines)ri   rR   ru   r   r   rC   r   r   rf   )r   r   )r   r   r   r   )r   r   r   r   )r   r   )r   r   )r   r   )r@   rU   rV   rW   r"   r   r   r   r   r   r   r   r   r   r   r   r    r    rh   r!   rs      s    








rs   )#rW   
__future__r   r   os.pathr(   collections.abcr   r   typesr   typingr   r   coverage.exceptionsr   coverage.miscr	   coverage.pluginr
   r   r   coverage.typesr   r   r   r   r   r   r   TCoverageInitrC   rD   rn   rs   r    r    r    r!   <module>   s&    r+'