ó
…¾^Yc           @   s€   d  Z  d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l m	 Z	 e e ƒ Z d e	 f d „  ƒ  YZ
 d S(   s'   Source file annotation for coverage.py.iÿÿÿÿN(   t   flat_rootname(   t   isolate_module(   t   Reportert   AnnotateReporterc           B   sJ   e  Z d  Z d „  Z e j d ƒ Z e j d ƒ Z d d „ Z	 d „  Z
 RS(   s  Generate annotated source files showing line coverage.

    This reporter creates annotated copies of the measured source files. Each
    .py file is copied as a .py,cover file, with a left-hand margin annotating
    each line::

        > def h(x):
        -     if 0:   #pragma: no cover
        -         pass
        >     if x == 1:
        !         a = 1
        >     else:
        >         a = 2

        > h(2)

    Executed lines use '>', lines not executed use '!', lines excluded from
    consideration use '-'.

    c         C   s&   t  t |  ƒ j | | ƒ d  |  _ d  S(   N(   t   superR   t   __init__t   Nonet	   directory(   t   selft   coveraget   config(    (    s3   /tmp/pip-build-hU8Cw8/coverage/coverage/annotate.pyR   '   s    s   \s*(#|$)s   \s*else\s*:\s*(#|$)c         C   s   |  j  |  j | | ƒ d S(   sI   Run the report.

        See `coverage.report()` for arguments.

        N(   t   report_filest   annotate_file(   R   t   morfsR   (    (    s3   /tmp/pip-build-hU8Cw8/coverage/coverage/annotate.pyt   report.   s    c         C   sÌ  t  | j ƒ } t  | j ƒ } t  | j ƒ } |  j r‡ t j j |  j t | j	 ƒ  ƒ ƒ } | j
 d ƒ rz | d  d } n  | d 7} n | j d } t j | d d d ƒ} d } d }	 t }
 | j ƒ  } xòt | j t ƒ d	 d
 ƒD]Õ\ } } x0 | t | ƒ k  r'| | | k  r'| d
 7} qø Wx0 |	 t | ƒ k  rZ| |	 | k  rZ|	 d
 7}	 q+W| t | ƒ k  r¢| | | k r¢|	 t | ƒ k pœ| |	 | k }
 n  |  j j | ƒ rÄ| j d ƒ ní |  j j | ƒ rr| t | ƒ k r
|	 t | ƒ k r
| j d ƒ q±| t | ƒ k s.|	 t | ƒ k r>| j d ƒ q±| | | |	 k rb| j d ƒ q±| j d ƒ n? | | k rŽ| j d ƒ n# |
 r¤| j d ƒ n | j d ƒ | j | ƒ qé WWd QXd S(   s]   Annotate a single file.

        `fr` is the FileReporter for the file to annotate.

        t   _pyiýÿÿÿs   .pys   ,covert   wt   encodingt   utf8i    t   starti   u     u   ! u   > u   - N(   t   sortedt
   statementst   missingt   excludedR   t   ost   patht   joinR    t   relative_filenamet   endswitht   filenamet   iot   opent   Truet   sourcet	   enumeratet
   splitlinest   lent   blank_ret   matcht   writet   else_re(   R   t   frt   analysisR   R   R   t	   dest_filet   destt   it   jt   coveredR!   t   linenot   line(    (    s3   /tmp/pip-build-hU8Cw8/coverage/coverage/annotate.pyR   6   sJ    	$(%%"%$$N(   t   __name__t
   __module__t   __doc__R   t   ret   compileR%   R(   R   R   R   (    (    (    s3   /tmp/pip-build-hU8Cw8/coverage/coverage/annotate.pyR      s   	(   R4   R   R   R5   t   coverage.filesR    t   coverage.miscR   t   coverage.reportR   R   (    (    (    s3   /tmp/pip-build-hU8Cw8/coverage/coverage/annotate.pyt   <module>   s   