ó
…¾^Yc           @   sW  d  Z  d d l Z d d l 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
 d d l m Z m Z m Z m Z d d l m Z d d l m Z d d	 l m Z e e ƒ Z d
 e j j e j j e ƒ d ƒ g Z d d „ Z d „  Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ  d „  Z! d „  Z" d S(   s   HTML reporting for coverage.py.iÿÿÿÿN(   t   env(   t   iitems(   t   flat_rootname(   t   CoverageExceptiont   file_be_gonet   Hashert   isolate_module(   t   Reporter(   t   Numbers(   t   Templites   /usr/share/javascriptt	   htmlfilest    c         C   s¶   g  } xŠ t  D]‚ } t j j | |  ƒ } t j j | ƒ r> | S| j | ƒ | r t j j | | |  ƒ } t j j | ƒ r | S| j | ƒ q q Wt d |  t j ƒ  | f ƒ ‚ d S(   s  Return the path to a data file of ours.

    The file is searched for on `STATIC_PATH`, and the first place it's found,
    is returned.

    Each directory in `STATIC_PATH` is searched as-is, and also, if `pkgdir`
    is provided, at that sub-directory.

    s/   Couldn't find static file %r from %r, tried: %rN(   t   STATIC_PATHt   ost   patht   joint   existst   appendR   t   getcwd(   t   fnamet   pkgdirt   triedt
   static_dirt   static_filename(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyt   data_filename!   s    
c         C   s)   t  t |  ƒ ƒ  } | j ƒ  SWd QXd S(   s+   Return the contents of a data file of ours.N(   t   openR   t   read(   R   t	   data_file(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyt	   read_data=   s    c         C   s5   t  |  d ƒ   } | j | j d d ƒ ƒ Wd QXd S(   s*   Write `html` to `fname`, properly encoded.t   wbt   asciit   xmlcharrefreplaceN(   R   t   writet   encode(   R   t   htmlt   fout(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyt
   write_htmlC   s    t   HtmlReporterc        
   B   se   e  Z d  Z d d d d d d d d d g	 Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   s   HTML reporting.s	   style.cssR   s   jquery.min.jst   jquerys"   jquery.ba-throttle-debounce.min.jss   jquery-throttle-debounces   jquery.hotkeys.jss   jquery-hotkeyss   jquery.isonscreen.jss   jquery-isonscreens   jquery.tablesorter.min.jss   jquery-tablesorters   coverage_html.jss   keybd_closed.pngs   keybd_open.pngc         C   s  t  t |  ƒ j | | ƒ d  |  _ |  j j } t j rI | j	 d ƒ } n  i t
 d 6t d 6| d 6t j d 6t j d 6|  _ t t d ƒ |  j ƒ |  _ | |  _ g  |  _ g  |  _ |  j j j ƒ  |  _ t ƒ  |  _ d  |  _ t ƒ  |  _ t j j ƒ  j d ƒ |  _ d  S(	   Nt   utf8t   escapet   pairt   titlet   __url__t   __version__s   pyfile.htmls   %Y-%m-%d %H:%M(    t   superR%   t   __init__t   Nonet	   directoryt   configt
   html_titleR    t   PY2t   decodeR(   R)   t   coverageR+   R,   t   template_globalsR	   R   t   source_tmplt   filest   all_files_numst   datat   has_arcst
   HtmlStatust   statust	   extra_cssR   t   totalst   datetimet   nowt   strftimet
   time_stamp(   t   selft   covR1   R*   (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyR.   Z   s(    		
				c         C   s  |  j  j s t d ƒ ‚ |  j j |  j  j ƒ t ƒ  } | j |  j  ƒ | j ƒ  } |  j j ƒ  | k rˆ |  j j	 ƒ  |  j j
 | ƒ n  |  j  j r² t j j |  j  j ƒ |  _ n  |  j |  j | |  j  j ƒ |  j sæ t d ƒ ‚ n  |  j ƒ  |  j ƒ  |  j j o|  j j S(   sc   Generate an HTML report for `morfs`.

        `morfs` is a list of modules or file names.

        s(   must give a directory for html reportings   No data to report.(   R1   t   html_dirt   AssertionErrorR=   R   R   t   updatet	   hexdigestt   settings_hasht   resett   set_settings_hashR>   R   R   t   basenamet   report_filest	   html_fileR9   R   t
   index_filet   make_local_static_report_filesR?   t   n_statementst
   pc_covered(   RD   t   morfst   mt   these_settings(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyt   reports   s     		

c         C   s€   xB |  j  D]7 \ } } t j t | | ƒ t j j |  j | ƒ ƒ q
 W|  j r| t j |  j	 j t j j |  j |  j ƒ ƒ n  d S(   s5   Make local instances of static files for HTML report.N(
   t   STATIC_FILESt   shutilt   copyfileR   R   R   R   R0   R>   R1   (   RD   t   staticR   (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyRQ   –   s    		c         C   s9   t  ƒ  } | j | ƒ |  j j j | j | ƒ | j ƒ  S(   s@   Compute a hash that changes if the file needs to be re-reported.(   R   RH   R5   R:   t   add_to_hasht   filenameRI   (   RD   t   sourcet   frRU   (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyt	   file_hash¦   s    	c      	      sv  t  | j ƒ  ƒ } | d } t j j |  j | ƒ } | j } |  j j | ƒ |  j	 j
 r” | j d k } | j d k } | r” | r” t | ƒ d Sn  | j ƒ  }	 |  j |	 j d ƒ | ƒ }
 |  j j | ƒ } |
 | k rù |  j j |  j j | ƒ ƒ d S|  j j | |
 ƒ |  j r0| j ƒ  } | j ƒ  } n  d } d } d } d | } g  } xkt | j ƒ  d	 d
 ƒD]Q\ ‰  } g  } d } d } ˆ  | j k r¨| j d ƒ n  ˆ  | j k rÇ| j | ƒ nEˆ  | j k ræ| j | ƒ n&|  j ríˆ  | k rí| j | ƒ g  } g  } xW | ˆ  D]K } | d k  rA| j d ƒ n | j | ƒ | j | j ˆ  | | ƒ ƒ qWd ‰ d j ‡  ‡ f d †  | Dƒ ƒ } t | ƒ d
 k rµ| d } qd t | ƒ d j d „  t | d	 d
 ƒDƒ ƒ f } n ˆ  | j k r| j | ƒ n  g  } x_ | D]W \ } } | d k rG| j t | ƒ ƒ qt | ƒ pVd } | j d | | f ƒ qW| j i d j | ƒ d 6ˆ  d 6d j | ƒ p¦d d 6| d 6| d 6ƒ qkW|  j  j! i
 | d 6| d 6| d  6| d! 6|  j d" 6|  j" d# 6| d$ 6| d% 6| d& 6|  j# d' 6ƒ } t$ | | ƒ i | d% 6| d( 6| j ƒ  d) 6} |  j j | ƒ |  j j% | | ƒ d S(*   s*   Generate an HTML file for one source file.s   .htmli    Ns   utf-8s   run hide_runt   exct   miss   par t   starti   R   t   stmt   exits   %s&#x202F;&#x219B;&#x202F;%ss   ,&nbsp;&nbsp; c         3   s   |  ] } ˆ ˆ  | f Vq d  S(   N(    (   t   .0t   d(   t   linenot	   short_fmt(    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pys	   <genexpr>ð   s    s   %d missed branches: %ss   , c         s   s%   |  ] \ } } d  | | f Vq d S(   s   %d) %sN(    (   Rf   t   numt   ann_long(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pys	   <genexpr>÷   s   t   wss   &nbsp;s   <span class="%s">%s</span>R"   t   numbert    t   plnt   classt   annotatet   annotate_longt   c_exct   c_mist   c_part   c_runR;   R>   R_   t   numst   linesRC   t   html_filenamet   relative_filename(&   R   Rz   R   R   R   R0   t   numbersR9   R   R1   t   skip_coveredt	   n_missingt   n_partial_branchesR   R^   R`   R!   R=   R8   t
   index_infot   set_file_hashR;   t   missing_branch_arcst   arcs_executedt	   enumeratet   source_token_linest
   statementst   excludedt   missingt   missing_arc_descriptiont   lenR(   R7   t   renderR>   RC   R$   t   set_index_info(   RD   R_   t   analysist   rootnameRy   t	   html_pathRw   t   no_missing_linest   no_missing_branchesR^   t	   this_hasht	   that_hashR   R‚   Rv   Rs   Rt   Ru   Rx   t   linet
   line_classt   annotate_htmlRr   t   shortst   longst   bR"   t   tok_typet   tok_textt   tok_htmlR   (    (   Rh   Ri   s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyRO   ­   s¬    
	
	
% "	 	

c         C   s¡   t  t d ƒ |  j ƒ } t |  j ƒ |  _ | j i |  j d 6|  j d 6|  j	 d 6|  j d 6|  j
 d 6ƒ } t t j j |  j d ƒ | ƒ |  j j |  j ƒ d S(   s*   Write the index.html file for this report.s
   index.htmlR;   R>   R8   R?   RC   N(   R	   R   R6   t   sumR9   R?   RŠ   R;   R>   R8   RC   R$   R   R   R   R0   R=   R    (   RD   t
   index_tmplR"   (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyRP   )  s    	



(   s	   style.cssR   (   s   jquery.min.jsR&   (   s"   jquery.ba-throttle-debounce.min.jss   jquery-throttle-debounce(   s   jquery.hotkeys.jss   jquery-hotkeys(   s   jquery.isonscreen.jss   jquery-isonscreen(   s   jquery.tablesorter.min.jss   jquery-tablesorter(   s   coverage_html.jsR   (   s   keybd_closed.pngR   (   s   keybd_open.pngR   (
   t   __name__t
   __module__t   __doc__RX   R.   RW   RQ   R`   RO   RP   (    (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyR%   I   s    			#			|R<   c           B   st   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 d „  Z RS(   s@   The status information we keep to support incremental reporting.s   status.jsoni   c         C   s   |  j  ƒ  d  S(   N(   RK   (   RD   (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyR.   _  s    c         C   s   d |  _  i  |  _ d S(   s   Initialize to empty.R   N(   t   settingsR8   (   RD   (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyRK   b  s    	c         C   s  t  } yC t j j | |  j ƒ } t | d ƒ  } t j | ƒ } Wd QXWn t t	 f k
 rh t  } n? Xt
 } | d |  j k r‹ t  } n | d t j k r§ t  } n  | ri  |  _ xG t | d ƒ D]5 \ } } t | d d Œ  | d d <| |  j | <qÇ W| d |  _ n
 |  j ƒ  d S(	   s$   Read the last status in `directory`.t   rNt   formatt   versionR8   t   indexRw   R¡   (   t   FalseR   R   R   t   STATUS_FILER   t   jsont   loadt   IOErrort
   ValueErrort   Truet   STATUS_FORMATR5   R,   R8   R   R   R¡   RK   (   RD   R0   t   usablet   status_filet   fstatusR=   R]   t   fileinfo(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyR   g  s&    
			c   	   
   C   s  t  j j | |  j ƒ } i  } xC t |  j ƒ D]2 \ } } | d d j ƒ  | d d <| | | <q. Wi |  j d 6t j	 d 6|  j
 d 6| d 6} t | d ƒ  } t j | | d d ƒWd QXd t  j k rt t  j j | d ƒ d ƒ  } | j d ƒ Wd QXn  d S(   s(   Write the current status to `directory`.R¥   Rw   R£   R¤   R¡   R8   t   wt
   separatorst   ,t   :Nt   JENKINS_URLs
   status.dats3   https://issues.jenkins-ci.org/browse/JENKINS-28428
(   R´   Rµ   (   R   R   R   R§   R   R8   t	   init_argsR­   R5   R,   R¡   R   R¨   t   dumpt   environR    (	   RD   R0   R¯   R8   R]   R±   R=   R#   t   dat(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyR    €  s    



!c         C   s   |  j  S(   s)   Get the hash of the coverage.py settings.(   R¡   (   RD   (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyRJ   ˜  s    c         C   s   | |  _  d S(   s)   Set the hash of the coverage.py settings.N(   R¡   (   RD   R¡   (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyRL   œ  s    c         C   s   |  j  j | i  ƒ j d d ƒ S(   s#   Get the hash of `fname`'s contents.t   hashR   (   R8   t   get(   RD   R   (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyR`      s    c         C   s   | |  j  j | i  ƒ d <d S(   s#   Set the hash of `fname`'s contents.R»   N(   R8   t
   setdefault(   RD   R   t   val(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyR€   ¤  s    c         C   s   |  j  j | i  ƒ j d i  ƒ S(   s/   Get the information for index.html for `fname`.R¥   (   R8   R¼   (   RD   R   (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyR   ¨  s    c         C   s   | |  j  j | i  ƒ d <d S(   s/   Set the information for index.html for `fname`.R¥   N(   R8   R½   (   RD   R   t   info(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyR‹   ¬  s    (   Rž   RŸ   R    R§   R­   R.   RK   R   R    RJ   RL   R`   R€   R   R‹   (    (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyR<   =  s   									c         C   s   |  j  d d ƒ j  d d ƒ S(   s\   HTML-escape the text in `t`.

    This is only suitable for HTML text, not attributes.

    t   &s   &amp;t   <s   &lt;(   t   replace(   t   t(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyR(   ³  s    c         C   s   d |  S(   sE   Format a pair of numbers so JavaScript can read them in an attribute.s   %s %s(    (   t   ratio(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyR)   ½  s    (#   R    R@   R¨   R   RY   R5   R    t   coverage.backwardR   t   coverage.filesR   t   coverage.miscR   R   R   R   t   coverage.reportR   t   coverage.resultsR   t   coverage.templiteR	   R   R   t   dirnamet   __file__R   R   R   R$   R%   t   objectR<   R(   R)   (    (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/html.pyt   <module>   s,   "$		ôv	
