ó
…¾^Yc           @   s8  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 m Z i  Z d „  Z e e ƒ Z d „  Z e	 j rd d l m Z d d l m Z d	 „  Z e d
 d „  ƒ e	 j re d d „  ƒ n  d „  Z n e Z e Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d e f d „  ƒ  YZ  d „  Z! d e f d „  ƒ  YZ" d e# f d „  ƒ  YZ$ d e$ f d „  ƒ  YZ% d  e% f d! „  ƒ  YZ& d" e& f d# „  ƒ  YZ' d$ e% f d% „  ƒ  YZ( d& e% f d' „  ƒ  YZ) d( e$ f d) „  ƒ  YZ* d S(*   s$   Miscellaneous stuff for coverage.py.iÿÿÿÿN(   t   env(   t   to_bytest   unicode_classc         C   sŠ   |  t  k r‚ t j |  j ƒ } | t  |  <xW t |  ƒ D]F } t |  | ƒ } t | t j ƒ rk t | ƒ } n  t | | | ƒ q5 Wn  t  |  S(   sJ  Copy a module so that we are isolated from aggressive mocking.

    If a test suite mocks os.path.exists (for example), and then we need to use
    it during the test, everything will get tangled up if we use their mock.
    Making a copy of the module when we import it will isolate coverage.py from
    those complications.
    (	   t   ISOLATED_MODULESt   typest
   ModuleTypet   __name__t   dirt   getattrt
   isinstancet   isolate_modulet   setattr(   t   modt   new_modt   namet   value(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyR
      s    
c          O   s   d „  } | S(   s9   Dummy no-op implementation of a decorator with arguments.c         S   s   |  S(   N(    (   t   func(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyt
   _decorator+   s    (    (   t   args_unusedt   kwargs_unusedR   (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyt   dummy_decorator_with_args)   s    	(   t   contract(   t   new_contractc          O   s)   y t  |  | Ž  SWn t k
 r$ n Xd S(   sE   A proxy for contracts.new_contract that doesn't mind happening twice.N(   t   raw_new_contractt
   ValueError(   t   argst   kwargs(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyR   6   s    t   bytesc         C   s   t  |  t ƒ S(   N(   R	   R   (   t   v(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyt   <lambda>@   s    t   unicodec         C   s   t  |  t ƒ S(   N(   R	   R   (   R   (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyR   B   s    c            s   ‡  f d †  } | S(   s1   Ensure that only one of the argnames is non-None.c            s5   t  d „  ˆ j d ƒ Dƒ ƒ ‰  ‡  ‡ f d †  } | S(   Nc         s   s   |  ] } | j  ƒ  Vq d  S(   N(   t   strip(   t   .0R   (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pys	   <genexpr>G   s    t   ,c             sQ   g  ˆ  D] } | j  | ƒ ^ q } t d „  | Dƒ ƒ d k sD t ‚ ˆ |  | Ž  S(   Nc         s   s   |  ] } | d  k	 Vq d  S(   N(   t   None(   R    t   val(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pys	   <genexpr>J   s    i   (   t   gett   sumt   AssertionError(   R   R   R   t   vals(   t
   argnamesetR   (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyt   _wrappedH   s    ""(   t   sett   split(   R   R)   (   t   argnames(   R(   R   s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyR   F   s    (    (   R,   R   (    (   R,   s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyt   one_ofD   s    c          O   s   d S(   s-   Dummy no-op implementation of `new_contract`.N(    (   R   R   (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyR   T   s    c         C   s2   |  \ } } | | k r  d | Sd | | f Sd S(   sÂ   Make a nice string representation of a pair of numbers.

    If the numbers are equal, just return the number, otherwise return the pair
    with a dash between them, indicating the range.

    s   %ds   %d-%dN(    (   t   pairt   startt   end(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyt	   nice_pairY   s    c         C   sÝ   t  |  ƒ }  t  | ƒ } g  } d } d } xx |  D]p } | t | ƒ k rM Pn  | | | k r | d 7} | sv | } n  | } q1 | r1 | j | | f ƒ d } q1 q1 W| rÁ | j | | f ƒ n  d j t t | ƒ ƒ } | S(   s3  Nicely format a list of line numbers.

    Format a list of line numbers for printing by coalescing groups of lines as
    long as the lines represent consecutive statements.  This will coalesce
    even if there are gaps between statements.

    For example, if `statements` is [1,2,3,4,5,10,11,12,13,14] and
    `lines` is [1,2,5,10,11,13,14] then the result will be "1-2, 5-11, 13-14".

    Both `lines` and `statements` can be any iterable. All of the elements of
    `lines` must be in `statements`, and all of the values must be positive
    integers.

    i    i   s   , N(   t   sortedR"   t   lent   appendt   joint   mapR1   (   t
   statementst   linest   pairsR/   t   lidxt   stmtR0   t   ret(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyt   format_linesg   s(    
		c            s4   t  j r, d ˆ j ‰  ‡  ‡ f d †  } | Sˆ Sd S(   s¹   A decorator to indicate that a method shouldn't be called more than once.

    Normally, this does nothing.  During testing, this raises an exception if
    called more than once.

    t   _once_c            s?   t  |  ˆ  ƒ r% t d ˆ j ƒ ‚ n  t |  ˆ  t ƒ ˆ |  ƒ S(   s%   Inner function that checks the cache.s'   Shouldn't have called %s more than once(   t   hasattrR&   R   R   t   True(   t   self(   t   attrt   fn(    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyR)   —   s    N(   R    t   TESTINGR   (   RC   R)   (    (   RB   RC   s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyt	   expensive   s
    	c         C   s   |  d k r d St |  ƒ Sd S(   s"   Return bool(b), but preserve None.N(   R"   t   bool(   t   b(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyt   bool_or_none¢   s    c         C   s   d j  d „  |  Dƒ ƒ S(   s<   Combine a list of regexes into one that matches any of them.t   |c         s   s   |  ] } d  | Vq d S(   s   (?:%s)N(    (   R    t   r(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pys	   <genexpr>¬   s    (   R5   (   t   regexes(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyt
   join_regexª   s    c         C   sC   y t  j |  ƒ Wn+ t k
 r> } | j t j k r? ‚  q? n Xd S(   s9   Remove a file, and don't get annoyed if it doesn't exist.N(   t   ost   removet   OSErrort   errnot   ENOENT(   t   patht   e(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyt   file_be_gone¯   s
    c         C   sO   |  d k r t j }  n  t |  d d ƒ pH t t j d d ƒ pH t j ƒ  } | S(   sH   Determine the encoding to use for output written to `outfile` or stdout.t   encodingN(   R"   t   syst   stdoutR   t
   __stdout__t   localet   getpreferredencoding(   t   outfileRU   (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyt   output_encoding¸   s    t   Hasherc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s   Hashes Python data into md5.c         C   s   t  j ƒ  |  _ d  S(   N(   t   hashlibt   md5(   RA   (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyt   __init__Æ   s    c         C   s©  |  j  j t t t | ƒ ƒ ƒ ƒ t | t ƒ rM |  j  j | j d ƒ ƒ nXt | t ƒ ro |  j  j | ƒ n6| d k r~ n't | t
 t f ƒ r² |  j  j t t | ƒ ƒ ƒ nó t | t t f ƒ rè xÛ | D] } |  j | ƒ qÎ Wn½ t | t ƒ r;| j ƒ  } xŸ t | ƒ D]$ } |  j | ƒ |  j | | ƒ qWnj xg t | ƒ D]Y } | j d ƒ rcqHn  t | | ƒ } t j | ƒ r‡qHn  |  j | ƒ |  j | ƒ qHWd S(   s+   Add `v` to the hash, recursively if needed.t   utf8t   __N(   R_   t   updateR   t   strt   typeR	   R   t   encodeR   R"   t   intt   floatt   tuplet   listt   dictt   keysR2   R   t
   startswithR   t   inspectt	   isroutine(   RA   R   RS   Rl   t   kt   a(    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyRc   É   s2    "c         C   s   |  j  j ƒ  S(   s$   Retrieve the hex digest of the hash.(   R_   t	   hexdigest(   RA   (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyRr   æ   s    (   R   t
   __module__t   __doc__R`   Rc   Rr   (    (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyR]   Ä   s   		c         C   sj   t  |  d ƒ r! d } |  j } n! d } |  j } d j d | ƒ } t d j d | d | d	 | ƒ ƒ ‚ d
 S(   s7   Helper to raise NotImplementedError in interface stubs.t   _coverage_plugin_namet   Plugint   Classs#   {klass.__module__}.{klass.__name__}t   klasss1   {thing} {name!r} needs to implement {func_name}()t   thingR   t	   func_nameN(   R?   Ru   t	   __class__t   formatt   NotImplementedError(   t   thatRz   Ry   R   Rx   (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyt   _needs_to_implementë   s    		t
   SimpleReprc           B   s   e  Z d  Z d „  Z RS(   s'   A mixin implementing a simple __repr__.c      	   C   sH   d j  d |  j j d t |  ƒ d @d d j d „  |  j j ƒ  Dƒ ƒ ƒ S(   Ns   <{klass} @{id:x} {attrs}>Rx   t   idiÿÿÿ t   attrst    c         s   s'   |  ] \ } } d  j  | | ƒ Vq d S(   s   {}={!r}N(   R|   (   R    Rp   R   (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pys	   <genexpr>  s    (   R|   R{   R   R   R5   t   __dict__t   items(   RA   (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyt   __repr__þ   s    	(   R   Rs   Rt   R†   (    (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyR€   ü   s   t   BaseCoverageExceptionc           B   s   e  Z d  Z RS(   s$   The base of all Coverage exceptions.(   R   Rs   Rt   (    (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyR‡     s   t   CoverageExceptionc           B   s   e  Z d  Z RS(   s4   A run-of-the-mill exception specific to coverage.py.(   R   Rs   Rt   (    (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyRˆ     s   t   NoSourcec           B   s   e  Z d  Z RS(   s)   We couldn't find the source for a module.(   R   Rs   Rt   (    (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyR‰     s   t   NoCodec           B   s   e  Z d  Z RS(   s!   We couldn't find any code at all.(   R   Rs   Rt   (    (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyRŠ     s   t	   NotPythonc           B   s   e  Z d  Z RS(   s3   A source file turned out not to be parsable Python.(   R   Rs   Rt   (    (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyR‹     s   t   ExceptionDuringRunc           B   s   e  Z d  Z RS(   s€   An exception happened while running customer code.

    Construct it with three arguments, the values from `sys.exc_info`.

    (   R   Rs   Rt   (    (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyRŒ     s   t   StopEverythingc           B   s   e  Z d  Z RS(   sÆ   An exception that means everything should stop.

    The CoverageTest class converts these to SkipTest, so that when running
    tests, raising this exception will automatically skip the test.

    (   R   Rs   Rt   (    (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyR   (  s   (+   Rt   RP   R^   Rn   RY   RM   RV   R   t   coverageR    t   coverage.backwardR   R   R   R
   R   RD   t	   contractsR   R   R   t   PY3R-   R1   R=   RE   RH   RL   RT   R"   R\   t   objectR]   R   R€   t	   ExceptionR‡   Rˆ   R‰   RŠ   R‹   RŒ   R   (    (    (    s/   /tmp/pip-build-hU8Cw8/coverage/coverage/misc.pyt   <module>   sR   					
				&					'	
	