ó
“=¼]c           @@  s1  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l m Z d d l	 m
 Z
 m Z m Z d d l m Z d d l m Z m Z m Z d d	 l m Z d
 d d d g Z e d d d g e ƒ Z d „  Z e d „ Z d e
 f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d S(   sv   
A Cython plugin for coverage.py

Requires the coverage package at least in version 4.0 (which added the plugin API).
i    (   t   absolute_importN(   t   defaultdict(   t   CoveragePlugint
   FileTracert   FileReporter(   t   canonical_filenamei   (   t   find_root_package_dirt   is_package_dirt   open_source_file(   t   __version__s   .cs   .cpps   .ccs   .cxxs   .pys   .pyxs   .pxdc         C@  s;   t  j j } x( t D]  } |  | } | | ƒ r | Sq Wd  S(   N(   t   ost   patht   existst   C_FILE_EXTENSIONSt   None(   t	   base_patht   file_existst   extt	   file_name(    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyt   _find_c_source   s    
c         C@  sõ   t  j j | ƒ } t  j j | ƒ r… | j d ƒ s: | r… t  j j t  j j |  ƒ | ƒ } t  j j | ƒ r… t  j j | ƒ } q… n  t  j j | ƒ së xQ t j D]C } t  j j t  j j | | ƒ ƒ } t  j j | ƒ r¡ t	 | ƒ Sq¡ Wn  t	 | ƒ S(   Ns   .pxi(
   R
   R   t   abspathR   t   endswitht   joint   dirnamet   syst   realpathR   (   t	   main_filet	   file_patht   relative_path_searcht   abs_patht   rel_file_patht   sys_patht	   test_path(    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyt   _find_dep_file_path$   s    "!!t   Pluginc           B@  sY   e  Z d Z d Z d Z d  „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z RS(   c         C@  s   d t  f g S(   Ns   Cython version(   R	   (   t   self(    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyt   sys_info=   s    c         C@  sý   | j  d ƒ s | j  d ƒ r" d Sd } } t t j j | ƒ ƒ } |  j rp | |  j k rp |  j | d } n  | d k rÆ |  j | ƒ \ } } | s› d S|  j | | ƒ \ } } | d k rÆ d Sn  |  j	 d k rá i  |  _	 n  t
 | | | |  j |  j	 ƒ S(   sR   
        Try to find a C source file for a file path found by the tracer.
        t   <s   memory:i    N(   t
   startswithR   R   R
   R   R   t   _c_files_mapt   _find_source_filest   _read_source_linest   _file_path_mapt   CythonModuleTracer(   R#   t   filenamet   c_filet   py_filet   _t   code(    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyt   file_tracer@   s     
c         C@  s£   t  t j j | ƒ ƒ } |  j rI | |  j k rI |  j | \ } } } nG |  j | ƒ \ } } | sh d  S|  j | | ƒ \ } } | d  k r d  St | | | | ƒ S(   N(	   R   R
   R   R   R'   R(   R   R)   t   CythonModuleReporter(   R#   R,   R-   R   R0   R/   (    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyt   file_reporter^   s    c         C@  sT  t  j j | ƒ \ } } | j ƒ  } | t k r3 nÓ | d k rs t j d | t j ƒ } | r| | j ƒ   } qn“ | d k r³ t j d | t j ƒ } | r| | j ƒ   } qnS | d k r|  j	 t  j j
 | ƒ | ƒ | |  j k r|  j | d d  f Sn d S| t k r| n	 t | ƒ } | d  k r±t j | ƒ } t  j j | | ƒ j t  j j ƒ } t | ƒ d k r±t  j j t  j j
 | ƒ d j | ƒ ƒ } t | ƒ } q±n  d  }	 | rJt  j j | ƒ d d	 }	 t  j j |	 ƒ sòd  }	 n  y5 t | d
 ƒ   }
 d |
 j d ƒ k r d SWd  QXWqJt t f k
 rFd  } qJXn  | |	 f S(   Ns   .pyds   [.]cp[0-9]+-win[_a-z0-9]*$s   .sos&   [.](?:cpython|pypy)-[0-9]+[-_a-z0-9]*$s   .pxii    i   t   .s   .pyt   rbs   /* Generated by Cython i   (   NN(   NN(   R
   R   t   splitextt   lowert   MODULE_FILE_EXTENSIONSt   ret   searcht   It   startt   _find_c_source_filesR   R'   R   R   R   R   t   uncachedt   relpatht   splitt   sept   lenR   R   t   opent   readt   IOErrort   OSError(   R#   R,   t   basenameR   t   platform_suffixR-   t   package_roott   package_patht   test_basepatht   py_source_filet   f(    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyR(   q   sH    $*	c         C@  sÂ   t  j j | ƒ s d St  j j } xn t  j | ƒ D]] } | | ƒ d j ƒ  } | t k r2 |  j t  j j | | ƒ | ƒ | |  j	 k r d Sq2 q2 Wt
 | ƒ r¾ |  j t  j j | ƒ | ƒ n  d S(   s¦   
        Desperately parse all C files in the directory or its package parents
        (not re-descending) to find the (included) source file in one of them.
        Ni   (   R
   R   t   isdirR6   t   listdirR7   R   R)   R   R'   R   R=   R   (   R#   t   dir_patht   source_fileR6   R,   R   (    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyR=   £   s    c         C@  sÛ   |  j  d k r i  |  _  n  | |  j  k r: |  j  | } n |  j | ƒ } | |  j  | <|  j d k rq i  |  _ n  xE | j ƒ  D]7 \ } } t | | d t ƒ} | | | f |  j | <q~ W| |  j k rÌ d S|  j | d S(   sý   
        Parse a Cython generated C/C++ source file and find the executable lines.
        Each executable line starts with a comment header that states source file
        and line number, as well as the surrounding range of source code lines.
        R   i   i   N(   N(   NN(   t   _parsed_c_filesR   t   _parse_cfile_linesR'   t   itemsR!   t   True(   R#   R-   t
   sourcefilet
   code_linesR,   R0   R   (    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyR)   µ   s    	c      
   C@  sú  t  j d ƒ j } t  j d ƒ j } t  j d ƒ j } t  j d ƒ j } t  j d ƒ j } t t ƒ } t t ƒ } d }	 t | ƒ }
 t |
 ƒ }
 x|
 D]ü } | | ƒ } | sd | k rš |	 d k	 rš | | ƒ } | r| |	 j	 t
 | j d ƒ ƒ ƒ qqš qš n  | j ƒ  \ } } | }	 t
 | ƒ } xg |
 D]_ } | | ƒ } | r‚| j d ƒ j ƒ  } | | ƒ rpPn  | | | | <Pq3| | ƒ r3Pq3q3Wqš WWd QXxS | j ƒ  D]E \ } }
 t |
 ƒ j | j | d	 ƒ ƒ } x | D] } |
 | =qáWq­W| S(
   sb   
        Parse a C file and extract all source file lines that generated executable code.
        s    */[*] +"(.*)":([0-9]+)$s    *[*] (.*) # <<<<<<+$s    *[*]/$s    *__Pyx_TraceLine\(([0-9]+),sX   \s*c(?:type)?def\s+(?:(?:public|external)\s+)?(?:struct|union|enum|class)(\s+[^:]+|)\s*:s   __Pyx_TraceLine(i   N(    (   R9   t   compilet   matchR   t   dictt   setR   RC   t   itert   addt   intt   groupt   groupst   rstripRT   t
   differencet   get(   R#   R-   t   match_source_path_linet   match_current_code_linet   match_comment_endt   match_trace_linet   not_executableRW   t   executable_linest   current_filenamet   linest   lineRY   t
   trace_lineR,   t   linenot   comment_linet	   code_linet
   dead_lines(    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyRS   Ï   sJ    &!N(   t   __name__t
   __module__R   R*   R'   RR   R$   R1   R3   R(   R=   R)   RS   (    (    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyR"   5   s   				2		R+   c           B@  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sA   
    Find the Python/Cython source file for a Cython module.
    c         C@  sD   t  t |  ƒ j ƒ  | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(   t   superR+   t   __init__t   module_fileR.   R-   R'   R*   (   R#   Rv   R.   R-   t   c_files_mapt   file_path_map(    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyRu     s    				c         C@  s   t  S(   N(   RU   (   R#   (    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyt   has_dynamic_source_filename  s    c         C@  sÅ   | j  j } y |  j | SWn t k
 r. n Xt | | ƒ } |  j rt | d j ƒ  d k rt |  j |  j | <|  j S|  j d k	 s‰ t	 ‚ | |  j k r´ |  j
 | d f |  j | <n  | |  j | <| S(   sR   
        Determine source file path.  Called by the function call tracer.
        iýÿÿÿs   .pyN(   t   f_codet   co_filenameR*   t   KeyErrorR!   R.   R7   R'   R   t   AssertionErrorR-   (   R#   R,   t   frameRQ   R   (    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyt   dynamic_source_filename  s    (   Rr   Rs   t   __doc__Ru   Ry   R   (    (    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyR+     s   		R2   c           B@  s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sP   
    Provide detailed trace information for one source file to coverage.py.
    c         C@  s5   t  t |  ƒ j | ƒ | |  _ | |  _ | |  _ d  S(   N(   Rt   R2   Ru   t   nameR-   t   _code(   R#   R-   RQ   R   R0   (    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyRu   -  s    		c         C@  s   t  |  j ƒ S(   sJ   
        Return set of line numbers that are possibly executable.
        (   R[   R‚   (   R#   (    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyRk   3  s    c         c@  sj   d } x] t  |  j j ƒ  ƒ D]F \ } } x | | k rI g  V| d 7} q+ Wd | f g V| d 7} q Wd  S(   Ni   t   txt(   t   sortedR‚   RT   (   R#   t   current_linet   line_noRp   (    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyt   _iter_source_tokens9  s    "c         C@  s[   t  j j |  j ƒ r: t |  j ƒ  } | j ƒ  SWd QXn d j d „  |  j ƒ  Dƒ ƒ Sd S(   sA   
        Return the source code of the file as a string.
        Ns   
c         s@  s)   |  ] } | r | d  d n d Vq d S(   i    i   t    N(    (   t   .0t   tokens(    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pys	   <genexpr>K  s   (   R
   R   R   R,   R   RD   R   R‡   (   R#   RM   (    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyt   sourceB  s    c         c@  s   t  j j |  j ƒ rX t |  j ƒ / } x% | D] } d | j d ƒ f g Vq. WWd QXn% x" |  j ƒ  D] } d | f g Vqe Wd S(   s6   
        Iterate over the source code tokens.
        Rƒ   s   
N(   R
   R   R   R,   R   Ra   R‡   (   R#   RM   Rl   (    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyt   source_token_linesN  s    $(   Rr   Rs   R€   Ru   Rk   R‡   R‹   RŒ   (    (    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyR2   )  s   					c         C@  s   |  j  t ƒ  ƒ d  S(   N(   t   add_file_tracerR"   (   t   regt   options(    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyt   coverage_init[  s    (   R€   t
   __future__R    R9   t   os.pathR
   R   t   collectionsR   t   coverage.pluginR   R   R   t   coverage.filesR   t   UtilsR   R   R   Rˆ   R	   R   R[   R8   R   t   FalseR!   R"   R+   R2   R   (    (    (    s_   /home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python2.7/site-packages/Cython/Coverage.pyt   <module>   s"   		Î&2