ó
…¾^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 m 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 e e ƒ Z e	 d	 d
 ƒ d „  ƒ Z e	 d	 d ƒ d „  ƒ Z e	 d	 d ƒ d „  ƒ Z d „  Z d e f d „  ƒ  YZ d S(   s'   Python source expertise for coverage.pyiÿÿÿÿN(   t   envt   files(   t   contractt	   expensivet   isolate_modulet
   join_regex(   t   CoverageExceptiont   NoSource(   t   PythonParser(   t   source_token_linest   source_encoding(   t   FileReportert   returnst   bytesc         C   sX   t  |  d ƒ  } | j ƒ  } Wd QXt j r< t | ƒ } n  | j d d ƒ j d d ƒ S(   sF   Read the Python source text from `filename`.

    Returns bytes.

    t   rbNs   
s   
s   (   t   opent   readR    t
   IRONPYTHONR   t   replace(   t   filenamet   ft   source(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/python.pyt   read_python_source   s
    	t   unicodec         C   s  t  j j |  ƒ \ } } | d k r< t j r< d d g } n	 | g } xy | D]N } | | } t  j j | ƒ r~ t | ƒ } Pn  t | ƒ } | d
 k	 rL PqL qL Wd |  f } | d 7} t	 | ƒ ‚ | j
 d d ƒ } | j t | ƒ d ƒ } | r| d d	 k r| d	 7} n  | S(   s#   Return the source code, as unicode.s   .pys   .pyws   No source for code: '%s'.
s*   Aborting report output, consider using -i.s   t    R   iÿÿÿÿs   
N(   t   ost   patht   splitextR    t   WINDOWSt   existsR   t   get_zip_bytest   NoneR   R   t   decodeR
   (   R   t   baset   extt   extst   try_filenameR   t   exc_msg(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/python.pyt   get_python_source%   s(    	

s
   bytes|Nonec         C   s¿   d t  j d t  j d t  j g } x” | D]Œ } | |  k r+ |  j | ƒ } y t j | d | d  ƒ } Wn t j k
 r„ q+ n Xy | j | d ƒ } Wn t k
 r² q+ n X| Sq+ Wd S(   sû   Get data from `filename` if it is a zip file path.

    Returns the bytestring data read from the zip file, or None if no zip file
    could be found or `filename` isn't in it.  The data returned will be
    an empty string if the file is empty.

    s   .zips   .eggs   .pexi    iÿÿÿÿi   N(	   R   t   sept   splitt	   zipimportt   zipimportert   ZipImportErrort   get_datat   IOErrorR   (   R   t   markerst   markert   partst   zit   data(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/python.pyR   J   s    	$c         C   s‘   |  j  d ƒ r |  S|  j  d ƒ rr |  d  } t j j | ƒ rB | St j rn | d } t j j | ƒ rn | Sn  | S|  j  d ƒ r |  d  d S|  S(	   s•   Return the source file for `filename`.

    Given a file name being traced, return the best guess as to the source
    file to attribute it to.

    s   .pys   .pycs   .pyoiÿÿÿÿt   ws	   $py.classi÷ÿÿÿ(   s   .pycs   .pyo(   t   endswithR   R   R   R    R   (   R   t   py_filenamet   pyw_filename(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/python.pyt   source_for_filec   s    
	
t   PythonFileReporterc           B   sÑ   e  Z d  Z d d „ Z d „  Z e d d ƒ d „  ƒ Z e d „  ƒ Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z d d „ Z e d d ƒ d „  ƒ Z d „  Z d „  Z RS(   s!   Report support for a Python file.c         C   s:  | |  _  t | d ƒ r$ | j } n0 t | t j ƒ rN t d j | ƒ ƒ ‚ n | } t t	 j
 | ƒ ƒ } t t |  ƒ j t	 j | ƒ ƒ t | d ƒ rú | j j d t j ƒ } t j j | ƒ j d ƒ rÞ | t j d 7} n  | d 7} t	 j
 | ƒ } n t	 j | ƒ } | |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  S(   Nt   __file__s   Module {0} has no filet   __name__t   .s	   __init__.t   __init__s   .py(   t   coveraget   hasattrR9   t
   isinstancet   typest
   ModuleTypeR   t   formatR7   R   t   unicode_filenamet   superR8   R<   t   canonical_filenameR:   R   R   R'   R   t   basenamet
   startswitht   relative_filenamet   relnameR   t   _sourcet   _parsert   _statementst	   _excluded(   t   selft   morfR=   R   t   name(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/python.pyR<   ‡   s(    	
				c         C   s   d j  |  j ƒ S(   Ns   <PythonFileReporter {0!r}>(   RB   R   (   RN   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/python.pyt   __repr__¦   s    R   R   c         C   s   |  j  S(   N(   RI   (   RN   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/python.pyRH   ©   s    c         C   sM   |  j  d k rF t d |  j d |  j j d ƒ ƒ |  _  |  j  j ƒ  n  |  j  S(   s&   Lazily create a :class:`PythonParser`.R   t   excludeN(   RK   R   R   R   R=   t   _exclude_regext   parse_source(   RN   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/python.pyt   parser­   s    	c         C   s
   |  j  j S(   s2   Return the line numbers of statements in the file.(   RU   t
   statements(   RN   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/python.pyt   lines¸   s    c         C   s
   |  j  j S(   s2   Return the line numbers of statements in the file.(   RU   t   excluded(   RN   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/python.pyt   excluded_lines¼   s    c         C   s   |  j  j | ƒ S(   N(   RU   t   translate_lines(   RN   RW   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/python.pyRZ   À   s    c         C   s   |  j  j | ƒ S(   N(   RU   t   translate_arcs(   RN   t   arcs(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/python.pyR[   Ã   s    c         C   s7   |  j  j t |  j j j ƒ t |  j j j ƒ ƒ } | S(   N(   RU   t   lines_matchingR   R=   t   configt   partial_listt   partial_always_list(   RN   t	   no_branch(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/python.pyt   no_branch_linesÆ   s    	c         C   s   |  j  j ƒ  S(   N(   RU   R\   (   RN   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/python.pyR\   Î   s    c         C   s   |  j  j ƒ  S(   N(   RU   t   exit_counts(   RN   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/python.pyRc   Ò   s    c         C   s   |  j  j | | | ƒ S(   N(   RU   t   missing_arc_description(   RN   t   startt   endt   executed_arcs(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/python.pyRd   Ö   s    c         C   s+   |  j  d  k r$ t |  j ƒ |  _  n  |  j  S(   N(   RJ   R   R&   R   (   RN   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/python.pyR   Ù   s    c         C   s<   t  j j |  j ƒ \ } } | j d ƒ r. t S| s8 t St S(   sä   Does it seem like this file should contain Python?

        This is used to decide if a file reported as part of the execution of
        a program was really likely to have contained Python in the first
        place.

        s   .py(   R   R   R   R   RG   t   Truet   False(   RN   t   _R"   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/python.pyt   should_be_pythonß   s    	c         C   s   t  |  j ƒ  ƒ S(   N(   R	   R   (   RN   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/python.pyR	   ó   s    N(   R:   t
   __module__t   __doc__R   R<   RQ   R   RH   t   propertyRU   RW   RY   RZ   R[   R   Rb   R\   Rc   Rd   R   Rk   R	   (    (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/python.pyR8   „   s    						(   Rm   t   os.pathR   R@   R)   R=   R    R   t   coverage.miscR   R   R   R   R   R   t   coverage.parserR   t   coverage.phystokensR	   R
   t   coverage.pluginR   R   R&   R   R7   R8   (    (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/python.pyt   <module>   s   "%	!