B
    ê¹`#  ã               @   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               @   sj   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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 | _g | _d | _d | _d S )N)ÚorderÚnamesÚfile_tracersÚconfigurersÚcontext_switchersÚcurrent_moduleÚdebug)Úself© r   ú_/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/coverage/plugin_support.pyÚ__init__   s    zPlugins.__init__Nc       	      C   sl   | ƒ }||_ xT|D ]L}||_t|ƒ tj| }t|ddƒ}|sJtd| ƒ‚| |¡}|||ƒ qW 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   Zget_plugin_options)	Úclsr   Úconfigr   ZpluginsÚmoduleÚmodr   Úoptionsr   r   r   Úload_plugins   s    



zPlugins.load_pluginsc             C   s   |   || 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_tracer8   s    zPlugins.add_file_tracerc             C   s   |   || j¡ dS )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   r   Úadd_configurerA   s    zPlugins.add_configurerc             C   s   |   || j¡ dS )zµAdd a dynamic context plugin.

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

        N)r   r   )r   r   r   r   r   Úadd_dynamic_contextJ   s    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)r   )r   r   r   r   r   Úadd_noopS   s    zPlugins.add_noopc             C   s   d| j |jjf }| jrX| j d¡rX| j d| j |f ¡ td| j f | jƒ}t||ƒ}||_d|_	| j
 |¡ || j|< |dk	rŒ| |¡ 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   ZshouldÚwriteÚLabelledDebugÚDebugPluginWrapperZ_coverage_plugin_nameZ_coverage_enabledr   Úappendr	   )r   r   ZspecializedÚplugin_nameZlabelledr   r   r   r   [   s    

zPlugins._add_pluginc             C   s
   t | jƒS )N)Úboolr   )r   r   r   r   Ú__nonzero__p   s    zPlugins.__nonzero__c             C   s
   t | jƒS )N)Úiterr   )r   r   r   r   Ú__iter__u   s    zPlugins.__iter__c             C   s
   | j | S )zReturn a plugin by name.)r	   )r   r*   r   r   r   Úgetx   s    zPlugins.get)N)r%   Ú
__module__Ú__qualname__Ú__doc__r   Úclassmethodr   r    r!   r"   r#   r   r,   Ú__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 )N)ÚlistÚlabelsr   )r   Úlabelr   Zprev_labelsr   r   r   r   €   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   r6   )r   r7   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Úir7   r   r   r   ú	<genexpr>‹   s    z/LabelledDebug.message_prefix.<locals>.<genexpr>)r6   Ú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&   r@   )r   Úmessager   r   r   r&      s    zLabelledDebug.writeN)r   )r%   r0   r1   r2   r   r8   r@   r&   r   r   r   r   r'   }   s
   
r'   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
‡  ZS )r(   z:Wrap a plugin, and use debug to report on what it's doing.c                s   t t| ƒ ¡  || _|| _d S )N)Ú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) --> %rzfile %r)r   Úfile_tracerr   r&   r8   ÚDebugFileTracerWrapper)r   ÚfilenameÚtracerr   r   r   r   rC   š   s    
zDebugPluginWrapper.file_tracerc             C   sF   | j  |¡}| j d||f ¡ |rB| j d|f ¡}t|||ƒ}|S )Nzfile_reporter(%r) --> %rzfile %r)r   Úfile_reporterr   r&   r8   ÚDebugFileReporterWrapper)r   rE   Úreporterr   r   r   r   rG   ¢   s    z DebugPluginWrapper.file_reporterc             C   s$   | j  |¡}| j d||f ¡ |S )Nzdynamic_context(%r) --> %r)r   Údynamic_contextr   r&   )r   ÚframeÚcontextr   r   r   rJ   ª   s    z"DebugPluginWrapper.dynamic_contextc             C   s$   | j  |¡}| j d||f ¡ |S )Nz find_executable_files(%r) --> %r)r   Úfind_executable_filesr   r&   )r   Úsrc_dirZexecutable_filesr   r   r   rM   ¯   s    z(DebugPluginWrapper.find_executable_filesc             C   s"   | j  d|f ¡ | j |¡ d S )Nzconfigure(%r))r   r&   r   Ú	configure)r   r   r   r   r   rO   ´   s    zDebugPluginWrapper.configurec             C   s
   | j  ¡ S )N)r   Úsys_info)r   r   r   r   rP   ¸   s    zDebugPluginWrapper.sys_info)r%   r0   r1   r2   r   rC   rG   rJ   rM   rO   rP   Ú__classcell__r   r   )r$   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 )rD   zA debugging `FileTracer`.c             C   s   || _ || _d S )N)rF   r   )r   rF   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   rK   r   r   r   Ú_show_frameÃ   s    z"DebugFileTracerWrapper._show_framec             C   s    | j  ¡ }| j d|f ¡ |S )Nzsource_filename() --> %r)rF   Úsource_filenamer   r&   )r   Z	sfilenamer   r   r   rY   Ê   s    
z&DebugFileTracerWrapper.source_filenamec             C   s    | j  ¡ }| j d|f ¡ |S )Nz$has_dynamic_source_filename() --> %r)rF   Úhas_dynamic_source_filenamer   r&   )r   Zhasr   r   r   rZ   Ï   s    
z2DebugFileTracerWrapper.has_dynamic_source_filenamec             C   s.   | j  ||¡}| j d||  |¡|f ¡ |S )Nz&dynamic_source_filename(%r, %s) --> %r)rF   Údynamic_source_filenamer   r&   rX   )r   rE   rK   Zdynr   r   r   r[   Ô   s    z.DebugFileTracerWrapper.dynamic_source_filenamec             C   s*   | j  |¡}| j d|  |¡|f ¡ |S )Nzline_number_range(%s) --> %r)rF   Úline_number_ranger   r&   rX   )r   rK   Úpairr   r   r   r\   Û   s    z(DebugFileTracerWrapper.line_number_rangeN)
r%   r0   r1   r2   r   rX   rY   rZ   r[   r\   r   r   r   r   rD   ¼   s   rD   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 )rH   zA debugging `FileReporter`.c                s    t t| ƒ |¡ || _|| _d S )N)rB   rH   r   rI   r   )r   rE   rI   r   )r$   r   r   r   ä   s    z!DebugFileReporterWrapper.__init__c             C   s    | j  ¡ }| j d|f ¡ |S )Nzrelative_filename() --> %r)rI   Úrelative_filenamer   r&   )r   Úretr   r   r   r^   é   s    
z*DebugFileReporterWrapper.relative_filenamec             C   s    | j  ¡ }| j d|f ¡ |S )Nzlines() --> %r)rI   Úlinesr   r&   )r   r_   r   r   r   r`   î   s    
zDebugFileReporterWrapper.linesc             C   s    | j  ¡ }| j d|f ¡ |S )Nzexcluded_lines() --> %r)rI   Úexcluded_linesr   r&   )r   r_   r   r   r   ra   ó   s    
z'DebugFileReporterWrapper.excluded_linesc             C   s$   | j  |¡}| j d||f ¡ |S )Nztranslate_lines(%r) --> %r)rI   Útranslate_linesr   r&   )r   r`   r_   r   r   r   rb   ø   s    z(DebugFileReporterWrapper.translate_linesc             C   s$   | j  |¡}| j d||f ¡ |S )Nztranslate_arcs(%r) --> %r)rI   Útranslate_arcsr   r&   )r   Úarcsr_   r   r   r   rc   ý   s    z'DebugFileReporterWrapper.translate_arcsc             C   s    | j  ¡ }| j d|f ¡ |S )Nzno_branch_lines() --> %r)rI   Úno_branch_linesr   r&   )r   r_   r   r   r   re     s    
z(DebugFileReporterWrapper.no_branch_linesc             C   s    | j  ¡ }| j d|f ¡ |S )Nzexit_counts() --> %r)rI   Úexit_countsr   r&   )r   r_   r   r   r   rf     s    
z$DebugFileReporterWrapper.exit_countsc             C   s    | j  ¡ }| j d|f ¡ |S )Nzarcs() --> %r)rI   rd   r   r&   )r   r_   r   r   r   rd     s    
zDebugFileReporterWrapper.arcsc             C   s$   | j  ¡ }| j dt|ƒf ¡ |S )Nzsource() --> %d chars)rI   Úsourcer   r&   Úlen)r   r_   r   r   r   rg     s    
zDebugFileReporterWrapper.sourcec             C   s(   t | j ¡ ƒ}| j dt|ƒf ¡ |S )Nz"source_token_lines() --> %d tokens)r5   rI   Úsource_token_linesr   r&   rh   )r   r_   r   r   r   ri     s    z+DebugFileReporterWrapper.source_token_lines)r%   r0   r1   r2   r   r^   r`   ra   rb   rc   re   rf   rd   rg   ri   rQ   r   r   )r$   r   rH   á   s   rH   )r2   rR   Úos.pathr   Zcoverage.miscr   r   Zcoverage.pluginr   r   r   Úobjectr   r'   r(   rD   rH   r   r   r   r   Ú<module>   s   m*%