ó
…¾^Yc           @   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 d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d e	 f d „  ƒ  YZ d e
 f d „  ƒ  YZ d S(   s   Support for plugins.iÿÿÿÿN(   t   CoverageExceptiont   isolate_module(   t   CoveragePlugint
   FileTracert   FileReportert   Pluginsc           B   se   e  Z d  Z d „  Z e d	 d „ ƒ Z d „  Z d „  Z d „  Z	 d „  Z
 e
 Z d „  Z d „  Z RS(
   s7   The currently loaded collection of coverage.py plugins.c         C   s1   g  |  _  i  |  _ g  |  _ d  |  _ d  |  _ d  S(   N(   t   ordert   namest   file_tracerst   Nonet   current_modulet   debug(   t   self(    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyt   __init__   s
    				c   	      C   s—   |  ƒ  } | | _  xu | D]m } | | _ t | ƒ t j | } t | d d ƒ } | sj t d | ƒ ‚ n  | j | ƒ } | | | ƒ q Wd | _ | S(   s`   Load plugins from `modules`.

        Returns a list of loaded and configured plugins.

        t   coverage_inits7   Plugin module %r didn't define a coverage_init functionN(	   R   R
   t
   __import__t   syst   modulest   getattrR	   R    t   get_plugin_options(	   t   clsR   t   configR   t   pluginst   modulet   modR   t   options(    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyt   load_plugins   s    			
	c         C   s   |  j  | |  j ƒ d S(   s­   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(   t   _add_pluginR   (   R   t   plugin(    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyt   add_file_tracer6   s    c         C   s   |  j  | d ƒ d S(   sf   Add a plugin that does nothing.

        This is only useful for testing the plugin support.

        N(   R   R	   (   R   R   (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyt   add_noop?   s    c         C   sÎ   d |  j  | j j f } |  j r |  j j d ƒ r |  j j d |  j  | f ƒ t d |  j  f |  j ƒ } t | | ƒ } n  | | _ t	 | _
 |  j j | ƒ | |  j | <| d k	 rÊ | j | ƒ n  d S(   s˜   Add a plugin object.

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

        s   %s.%sR   s   Loaded plugin %r: %rs	   plugin %rN(   R
   t	   __class__t   __name__R   t   shouldt   writet   LabelledDebugt   DebugPluginWrappert   _coverage_plugin_namet   Truet   _coverage_enabledR   t   appendR   R	   (   R   R   t   specializedt   plugin_namet   labelled(    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyR   G   s    		c         C   s   t  |  j ƒ S(   N(   t   boolR   (   R   (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyt   __nonzero__\   s    c         C   s   t  |  j ƒ S(   N(   t   iterR   (   R   (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyt   __iter__a   s    c         C   s   |  j  | S(   s   Return a plugin by name.(   R   (   R   R*   (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyt   getd   s    N(   R    t
   __module__t   __doc__R   t   classmethodR	   R   R   R   R   R-   t   __bool__R/   R0   (    (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyR      s   							R#   c           B   s5   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z RS(   s?   A Debug writer, but with labels for prepending to the messages.c         C   s#   t  | ƒ | g |  _ | |  _ d  S(   N(   t   listt   labelsR   (   R   t   labelR   t   prev_labels(    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyR   l   s    c         C   s   t  | |  j |  j ƒ S(   s<   Add a label to the writer, and return a new `LabelledDebug`.(   R#   R   R6   (   R   R7   (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyt	   add_labelp   s    c         C   s-   |  j  d g } d j d „  t | ƒ Dƒ ƒ S(   s4   The prefix to use on messages, combining the labels.t    s   :
c         s   s#   |  ] \ } } d  | | Vq d S(   s     N(    (   t   .0t   iR7   (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pys	   <genexpr>w   s    (   R6   t   joint	   enumerate(   R   t   prefixes(    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyt   message_prefixt   s    c         C   s$   |  j  j d |  j ƒ  | f ƒ d S(   s/   Write `message`, but with the labels prepended.s   %s%sN(   R   R"   R@   (   R   t   message(    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyR"   y   s    (    (   R    R1   R2   R   R9   R@   R"   (    (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyR#   i   s
   		R$   c           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s:   Wrap a plugin, and use debug to report on what it's doing.c         C   s)   t  t |  ƒ j ƒ  | |  _ | |  _ d  S(   N(   t   superR$   R   R   R   (   R   R   R   (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyR      s    	c         C   sa   |  j  j | ƒ } |  j j d | | f ƒ | r] |  j j d | f ƒ } t | | ƒ } n  | S(   Ns   file_tracer(%r) --> %rs   file %r(   R   t   file_tracerR   R"   R9   t   DebugFileTracerWrapper(   R   t   filenamet   tracerR   (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyRC   †   s    c         C   sd   |  j  j | ƒ } |  j j d | | f ƒ | r` |  j j d | f ƒ } t | | | ƒ } n  | S(   Ns   file_reporter(%r) --> %rs   file %r(   R   t   file_reporterR   R"   R9   t   DebugFileReporterWrapper(   R   RE   t   reporterR   (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyRG   Ž   s    c         C   s   |  j  j ƒ  S(   N(   R   t   sys_info(   R   (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyRJ   –   s    (   R    R1   R2   R   RC   RG   RJ   (    (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyR$   ~   s
   			RD   c           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s   A debugging `FileTracer`.c         C   s   | |  _  | |  _ d  S(   N(   RF   R   (   R   RF   R   (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyR      s    	c         C   s#   d t  j j | j j ƒ | j f S(   s7   A short string identifying a frame, for debug messages.s   %s@%d(   t   ost   patht   basenamet   f_codet   co_filenamet   f_lineno(   R   t   frame(    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyt   _show_frame¡   s    c         C   s*   |  j  j ƒ  } |  j j d | f ƒ | S(   Ns   source_filename() --> %r(   RF   t   source_filenameR   R"   (   R   t	   sfilename(    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyRS   ¨   s    c         C   s*   |  j  j ƒ  } |  j j d | f ƒ | S(   Ns$   has_dynamic_source_filename() --> %r(   RF   t   has_dynamic_source_filenameR   R"   (   R   t   has(    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyRU   ­   s    c         C   s?   |  j  j | | ƒ } |  j j d | |  j | ƒ | f ƒ | S(   Ns&   dynamic_source_filename(%r, %s) --> %r(   RF   t   dynamic_source_filenameR   R"   RR   (   R   RE   RQ   t   dyn(    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyRW   ²   s    c         C   s9   |  j  j | ƒ } |  j j d |  j | ƒ | f ƒ | S(   Ns   line_number_range(%s) --> %r(   RF   t   line_number_rangeR   R"   RR   (   R   RQ   t   pair(    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyRY   ¹   s    #(	   R    R1   R2   R   RR   RS   RU   RW   RY   (    (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyRD   š   s   					RH   c           B   sq   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z RS(   s   A debugging `FileReporter`.c         C   s,   t  t |  ƒ j | ƒ | |  _ | |  _ d  S(   N(   RB   RH   R   RI   R   (   R   RE   RI   R   (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyR   Â   s    	c         C   s*   |  j  j ƒ  } |  j j d | f ƒ | S(   Ns   relative_filename() --> %r(   RI   t   relative_filenameR   R"   (   R   t   ret(    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyR[   Ç   s    c         C   s*   |  j  j ƒ  } |  j j d | f ƒ | S(   Ns   lines() --> %r(   RI   t   linesR   R"   (   R   R\   (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyR]   Ì   s    c         C   s*   |  j  j ƒ  } |  j j d | f ƒ | S(   Ns   excluded_lines() --> %r(   RI   t   excluded_linesR   R"   (   R   R\   (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyR^   Ñ   s    c         C   s0   |  j  j | ƒ } |  j j d | | f ƒ | S(   Ns   translate_lines(%r) --> %r(   RI   t   translate_linesR   R"   (   R   R]   R\   (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyR_   Ö   s    c         C   s0   |  j  j | ƒ } |  j j d | | f ƒ | S(   Ns   translate_arcs(%r) --> %r(   RI   t   translate_arcsR   R"   (   R   t   arcsR\   (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyR`   Û   s    c         C   s*   |  j  j ƒ  } |  j j d | f ƒ | S(   Ns   no_branch_lines() --> %r(   RI   t   no_branch_linesR   R"   (   R   R\   (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyRb   à   s    c         C   s*   |  j  j ƒ  } |  j j d | f ƒ | S(   Ns   exit_counts() --> %r(   RI   t   exit_countsR   R"   (   R   R\   (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyRc   å   s    c         C   s*   |  j  j ƒ  } |  j j d | f ƒ | S(   Ns   arcs() --> %r(   RI   Ra   R   R"   (   R   R\   (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyRa   ê   s    c         C   s0   |  j  j ƒ  } |  j j d t | ƒ f ƒ | S(   Ns   source() --> %d chars(   RI   t   sourceR   R"   t   len(   R   R\   (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyRd   ï   s    c         C   s6   t  |  j j ƒ  ƒ } |  j j d t | ƒ f ƒ | S(   Ns"   source_token_lines() --> %d tokens(   R5   RI   t   source_token_linesR   R"   Re   (   R   R\   (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyRf   ô   s    (   R    R1   R2   R   R[   R]   R^   R_   R`   Rb   Rc   Ra   Rd   Rf   (    (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyRH   ¿   s   										(   R2   RK   t   os.pathR   t   coverage.miscR    R   t   coverage.pluginR   R   R   t   objectR   R#   R$   RD   RH   (    (    (    s9   /tmp/pip-build-hU8Cw8/coverage/coverage/plugin_support.pyt   <module>   s   Y%