ó
…¾^Yc           @   s
  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 Z d d l Z d d l m	 Z	 d d l
 m Z d d l m Z m Z m Z m Z e e ƒ Z d „  Z d „  Z e d d	 ƒ d
 „  ƒ Z e d d	 ƒ d „  ƒ Z d „  Z e	 j ri  Z i  Z d „  Z n	 d „  Z e	 j rAe d d	 ƒ d „  ƒ Z n e d d	 d d	 ƒ d „  ƒ Z e d d	 ƒ d „  ƒ Z d a d a e ƒ  d „  Z  d „  Z! d e" f d „  ƒ  YZ# d e" f d „  ƒ  YZ$ d e" f d „  ƒ  YZ% d „  Z& d e" f d „  ƒ  YZ' d „  Z( d S(   s   File wrangling.iÿÿÿÿN(   t   env(   t   unicode_class(   t   contractt   CoverageExceptiont
   join_regext   isolate_modulec           C   s,   t  j j t t  j ƒ t  j ƒ a i  a d S(   s?   Set the directory that `relative_filename` will be relative to.N(   t   ost   patht   normcaset   abs_filet   curdirt   sept   RELATIVE_DIRt   CANONICAL_FILENAME_CACHE(    (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyt   set_relative_directory   s    "c           C   s   t  S(   s=   Return the directory that `relative_filename` is relative to.(   R   (    (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyt   relative_directory"   s    t   returnst   unicodec         C   s>   t  j j |  ƒ } | j t ƒ r4 |  t t ƒ }  n  t |  ƒ S(   sœ   Return the relative form of `filename`.

    The file name will be relative to the current directory when the
    `set_relative_directory` was called.

    (   R   R   R   t
   startswithR   t   lent   unicode_filename(   t   filenamet   fnorm(    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyt   relative_filename'   s    c         C   sÇ   |  t  k r¿ t j j |  ƒ s¦ x… t j g t j D]m } | d k rJ q2 n  t j j | |  ƒ } y t j j | ƒ } Wn t	 k
 rŽ t
 } n X| r2 | }  Pq2 q2 Wn  t |  ƒ } | t  |  <n  t  |  S(   sz   Return a canonical file name for `filename`.

    An absolute path with no redundant components and normalized case.

    N(   R   R   R   t   isabsR
   t   syst   Nonet   joint   existst   UnicodeErrort   FalseR	   (   R   R   t   fR   t   cf(    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyt   canonical_filename5   s     
c         C   s&   t  j |  ƒ d } t j d d | ƒ S(   s(  A base for a flat file name to correspond to this file.

    Useful for writing files about the code where you want all the files in
    the same directory, but need to differentiate same-named files from
    different directories.

    For example, the file a/b/c.py will return 'a_b_c_py'

    i   s   [\\/.:]t   _(   t   ntpatht
   splitdrivet   ret   sub(   R   t   name(    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyt   flat_rootnameN   s    
c         C   sD  t  j r0 t |  t ƒ r0 |  j t j ƒ  ƒ }  n  |  t k rD t |  St j	 j
 |  ƒ \ } } | sq | j ƒ  } nÅ | s€ | } n¶ t | ƒ } | t k r¥ t | } n7 y t j | ƒ } Wn t k
 rÑ g  } n X| t | <t j	 j | ƒ } x0 | D]( } t j	 j | ƒ | k rõ | } Pqõ qõ Wt j	 j | | ƒ } | t |  <| S(   s:   Get the actual path of `path`, including the correct case.(   R    t   PY2t
   isinstanceR   t   encodeR   t   getfilesystemencodingt   _ACTUAL_PATH_CACHER   R   t   splitt   uppert   actual_patht   _ACTUAL_PATH_LIST_CACHEt   listdirt   OSErrorR   R   (   R   t   headt   tailt   actpatht   filest   normtailR   (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyR0   a   s2    	


c         C   s   |  S(   s*   The actual path for non-Windows platforms.(    (   R   (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyR0   ‚   s    c         C   s@   t  |  t ƒ r< t j ƒ  p$ t j ƒ  } |  j | d ƒ }  n  |  S(   s'   Return a Unicode version of `filename`.t   replace(   R*   t   strR   R,   t   getdefaultencodingt   decode(   R   t   encoding(    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyR   ˆ   s    R   c         C   s   |  S(   s'   Return a Unicode version of `filename`.(    (   R   (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyR      s    c         C   sv   t  j j t  j j |  ƒ ƒ } y t  j j | ƒ } Wn t k
 rG n Xt  j j | ƒ } t | ƒ } t | ƒ } | S(   s2   Return the absolute normalized form of `filename`.(	   R   R   t
   expandvarst
   expandusert   realpathR   t   abspathR0   R   (   R   R   (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyR	   –   s    c         C   s   t  j |  ƒ p t j |  ƒ S(   s)   Is `filename` an absolute path on any OS?(   R#   R   t	   posixpath(   R   (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyt   isabs_anywhere©   s    c         C   sS   g  } xF |  p g  D]8 } | j  d ƒ r8 | j | ƒ q | j t | ƒ ƒ q W| S(   s"  Prepare the file patterns for use in a `FnmatchMatcher`.

    If a pattern starts with a wildcard, it is used as a pattern
    as-is.  If it does not start with a wildcard, then it is made
    absolute with the current directory.

    If `patterns` is None, an empty list is returned.

    t   *t   ?(   RD   RE   (   R   t   appendR	   (   t   patternst   preppedt   p(    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyt   prep_patterns®   s    
t   TreeMatcherc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sø   A matcher for files in a tree.

    Construct with a list of paths, either files or directories. Paths match
    with the `match` method if they are one of the files, or if they are
    somewhere in a subtree rooted at one of the directories.

    c         C   s   t  | ƒ |  _ d  S(   N(   t   listt   paths(   t   selfRM   (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyt   __init__É   s    c         C   s   d |  j  S(   Ns   <TreeMatcher %r>(   RM   (   RN   (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyt   __repr__Ì   s    c         C   s   |  j  S(   s4   A list of strings for displaying when dumping state.(   RM   (   RN   (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyt   infoÏ   s    c         C   sW   xP |  j  D]E } | j | ƒ r
 | | k r/ t S| t | ƒ t j k rO t Sq
 q
 Wt S(   s1   Does `fpath` indicate a file in one of our trees?(   RM   R   t   TrueR   R   R   R   (   RN   t   fpathRI   (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyt   matchÓ   s    (   t   __name__t
   __module__t   __doc__RO   RP   RQ   RT   (    (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyRK   Á   s
   			t   ModuleMatcherc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s    A matcher for modules in a tree.c         C   s   t  | ƒ |  _ d  S(   N(   RL   t   modules(   RN   t   module_names(    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyRO   â   s    c         C   s   d |  j  S(   Ns   <ModuleMatcher %r>(   RY   (   RN   (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyRP   å   s    c         C   s   |  j  S(   s4   A list of strings for displaying when dumping state.(   RY   (   RN   (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyRQ   è   s    c         C   s^   | s
 t  SxM |  j D]B } | j | ƒ r | | k r9 t S| t | ƒ d k rV t Sq q Wt  S(   s<   Does `module_name` indicate a module in one of our packages?t   .(   R   RY   R   RR   R   (   RN   t   module_namet   m(    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyRT   ì   s    (   RU   RV   RW   RO   RP   RQ   RT   (    (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyRX   à   s
   			t   FnmatchMatcherc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s)   A matcher for files by file name pattern.c         C   sb   | |  _  d „  | Dƒ } d „  | Dƒ } t j rF d „  | Dƒ } n  t j t | ƒ ƒ |  _ d  S(   Nc         s   s   |  ] } t  j | ƒ Vq d  S(   N(   t   fnmatcht	   translate(   t   .0RI   (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pys	   <genexpr>  s    c         s   s!   |  ] } | j  d  d ƒ Vq d S(   s   \/s   [\\/]N(   R9   (   Ra   RI   (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pys	   <genexpr>  s    c         s   s   |  ] } | d  Vq d S(   s   (?i)N(    (   Ra   RI   (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pys	   <genexpr>	  s    (   t   patsR    t   WINDOWSR%   t   compileR   (   RN   Rb   t   fnpats(    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyRO   þ   s    
	c         C   s   d |  j  S(   Ns   <FnmatchMatcher %r>(   Rb   (   RN   (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyRP     s    c         C   s   |  j  S(   s4   A list of strings for displaying when dumping state.(   Rb   (   RN   (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyRQ     s    c         C   s   |  j  j | ƒ d k	 S(   s1   Does `fpath` match one of our file name patterns?N(   R%   RT   R   (   RN   RS   (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyRT     s    (   RU   RV   RW   RO   RP   RQ   RT   (    (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyR^   ü   s
   			c         C   s7   t  j d |  ƒ } | r* | j d ƒ } n	 t j } | S(   s?   Find the path separator used in this string, or os.sep if none.s   [\\/]i    (   R%   t   searcht   groupR   R   (   t   st	   sep_matcht   the_sep(    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyR     s
    	t   PathAliasesc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s‰  A collection of aliases for paths.

    When combining data files from remote machines, often the paths to source
    code are different, for example, due to OS differences, or because of
    serialized checkouts on continuous integration machines.

    A `PathAliases` object tracks a list of pattern/result pairs, and can
    map a path through those aliases to produce a unified path.

    c         C   s   g  |  _  d  S(   N(   t   aliases(   RN   (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyRO   -  s    c         C   s÷   | j  d ƒ } | j d ƒ r- t d ƒ ‚ n  t | ƒ } | j d ƒ re t | ƒ re t | ƒ } n  | | 7} t j | ƒ } t	 j
 d d | ƒ } | j d d ƒ } t	 j d | ƒ } t | ƒ } | j  d ƒ | } |  j j | | | | f ƒ d S(	   s  Add the `pattern`/`result` pair to the list of aliases.

        `pattern` is an `fnmatch`-style pattern.  `result` is a simple
        string.  When mapping paths, if a path starts with a match against
        `pattern`, then that match is replaced with `result`.  This models
        isomorphic source trees being rooted at different places on two
        different machines.

        `pattern` can't end with a wildcard component, since that would
        match an entire tree, and not just its root.

        s   \/RD   s$   Pattern must not end with wildcards.s	   \\Z(\(|$)s   \1s   [\\/]s   (?i)N(   t   rstript   endswithR   R   R   RC   R	   R_   R`   R%   R&   R9   Rd   Rl   RF   (   RN   t   patternt   resultt   pattern_sept	   regex_patt   regext
   result_sep(    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyt   add0  s    
c         C   s…   x~ |  j  D]s \ } } } } | j | ƒ } | r
 | j | j d ƒ | ƒ } | | k rm | j | | ƒ } n  t | ƒ } | Sq
 W| S(   s?  Map `path` through the aliases.

        `path` is checked against all of the patterns.  The first pattern to
        match is used to replace the root of the path with the result root.
        Only one pattern is ever used.  If no patterns match, `path` is
        returned unchanged.

        The separator style in the result is made to match that of the result
        in the alias.

        Returns the mapped path.  If a mapping has happened, this is a
        canonical path.  If no mapping has happened, it is the original value
        of `path` unchanged.

        i    (   Rl   RT   R9   Rg   R!   (   RN   R   Rs   Rp   Rq   Rt   R]   t   new(    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyt   map[  s    (   RU   RV   RW   RO   Ru   Rw   (    (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyRk   "  s   
		+c         c   s   xˆ t  t j |  ƒ ƒ D]q \ } \ } } } | d k rM d | k rM | 2q n  x7 | D]/ } t j d | ƒ rT t j j | | ƒ VqT qT Wq Wd S(   s™  Yield all of the importable Python files in `dirname`, recursively.

    To be importable, the files have to be in a directory with a __init__.py,
    except for `dirname` itself, which isn't required to have one.  The
    assumption is that `dirname` was specified directly, so the user knows
    best, but sub-directories are checked for a __init__.py to be sure we only
    find the importable files.

    i    s   __init__.pys   ^[^.#~!$@%^&*()+=,]+\.pyw?$N(   t	   enumerateR   t   walkR%   RT   R   R   (   t   dirnamet   it   dirpatht   dirnamest	   filenamesR   (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyt   find_python_filesv  s    
+()   RW   R_   R#   R   t   os.pathRB   R%   R   t   coverageR    t   coverage.backwardR   t   coverage.miscR   R   R   R   R   R   R   R!   R(   Rc   R-   R1   R0   R)   R   R	   R   R   R   RC   RJ   t   objectRK   RX   R^   R   Rk   R   (    (    (    s0   /tmp/pip-build-hU8Cw8/coverage/coverage/files.pyt   <module>   sH   "				!					
T