
    
_d$                        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Zej                  d        Z	ej                  dde	fd       Z
d Zej                  ej                  fd       Zej                  ddefd       Zej                  d        Z G d	 d
      Z G d dej"                  ej$                        Z G d dej$                        Zy)    Nc              #      K   t        j                         }t        j                  |        	 |  t        j                  |       y# t        j                  |       w xY ww)z
    >>> tmp_path = getfixture('tmp_path')
    >>> with pushd(tmp_path):
    ...     assert os.getcwd() == os.fspath(tmp_path)
    >>> assert os.getcwd() != os.fspath(tmp_path)
    N)osgetcwdchdir)dirorigs     C/usr/lib/python3/dist-packages/setuptools/_vendor/jaraco/context.pypushdr
      s>      99;DHHSM	
s   *A!A A!AA!c           
   #     K   |?t         j                  j                  |       j                  dd      j                  dd      }|&t	        j
                  t        j                  d      }nt        j                  dt                | dj                  di t                      	 d	}d
}dj                  ||f      } | |j                  ddt        |       it                       ||      5  | ddd        | dj                  di t                      y# 1 sw Y   *xY w#  | dj                  di t                      w xY ww)z
    Get a tarball, extract it, change to that directory, yield, then
    clean up.
    `runner` is the function to invoke commands.
    `pushd` is a context manager for changing the directory.
    Nz.tar.gz z.tgzT)shellzrunner parameter is deprecatedzmkdir {target_dir}zwget {url} -O -z7tar x{compression} --strip-components=1 -C {target_dir}z | compressionzrm -Rf {target_dir} )r   pathbasenamereplace	functoolspartial
subprocess
check_callwarningswarnDeprecationWarningformatvarsjoininfer_compression)url
target_dirrunnerr
   getterextractcmds          r	   tarball_contextr$      s,     WW%%c*229bAII&RTU
~"":#8#8E68JK
 &&&0017"Kjj&'*+zszzG&7&<GGH: 		 	+$++5df56	 	 	+$++5df56s7   B$E'A
D+ 1D6D+ >!ED($D+ +"EEc                 L    | dd }t        ddd      }|j                  |d      S )a  
    Given a URL or filename, infer the compression code for tar.

    >>> infer_compression('http://foo/bar.tar.gz')
    'z'
    >>> infer_compression('http://foo/bar.tgz')
    'z'
    >>> infer_compression('file.bz')
    'j'
    >>> infer_compression('file.xz')
    'J'
    NzjJ)gzbzxz)dictget)r   compression_indicatormappings      r	   r   r   :   s0      Hccc*G;;,c22    c              #   h   K   t        j                         }	 |  | |       y#  | |       w xY ww)aN  
    Create a temporary directory context. Pass a custom remover
    to override the removal behavior.

    >>> import pathlib
    >>> with temp_dir() as the_dir:
    ...     assert os.path.isdir(the_dir)
    ...     _ = pathlib.Path(the_dir).joinpath('somefile').write_text('contents')
    >>> assert not os.path.exists(the_dir)
    N)tempfilemkdtemp)removertemp_dirs     r	   r6   r6   N   s0      !Hs   2% 	2
/2Tc              #     K   d| v rdnd} |       5 }|d| |g}|r|j                  d|g       t        t        j                  j                  d      }|r|nd}t        j                  ||       | ddd       y# 1 sw Y   yxY ww)z
    Check out the repo indicated by url.

    If dest_ctx is supplied, it should be a context manager
    to yield the target directory for the check out.
    githgclonez--branchwN)stdout)extendopenr   r   devnullr   r   )	r   branchquietdest_ctxexerepo_dirr#   r?   r<   s	            r	   repo_contextrE   a   s      C<%TC	 xGS(+JJ
F+,rww,!tc&1  s   BA!A<3	B<BBc               #      K   d yw)z
    A null context suitable to stand in for a meaningful context.

    >>> with null() as value:
    ...     assert value is None
    Nr   r   r1   r	   nullrG   t   s      
s   c                   t    e Zd ZdZdZeffdZd Zed        Z	ed        Z
ed        Zd Zd	 Zed
dZd Zy)ExceptionTrapa  
    A context manager that will catch certain exceptions and provide an
    indication they occurred.

    >>> with ExceptionTrap() as trap:
    ...     raise Exception()
    >>> bool(trap)
    True

    >>> with ExceptionTrap() as trap:
    ...     pass
    >>> bool(trap)
    False

    >>> with ExceptionTrap(ValueError) as trap:
    ...     raise ValueError("1 + 1 is not 3")
    >>> bool(trap)
    True
    >>> trap.value
    ValueError('1 + 1 is not 3')
    >>> trap.tb
    <traceback object at ...>

    >>> with ExceptionTrap(ValueError) as trap:
    ...     raise Exception()
    Traceback (most recent call last):
    ...
    Exception

    >>> bool(trap)
    False
    )NNNc                     || _         y N)
exceptions)selfrL   s     r	   __init__zExceptionTrap.__init__   s	    $r1   c                     | S rK   r   rM   s    r	   	__enter__zExceptionTrap.__enter__       r1   c                      | j                   d   S Nr   exc_inforP   s    r	   typezExceptionTrap.type       }}Qr1   c                      | j                   d   S )N   rU   rP   s    r	   valuezExceptionTrap.value   rX   r1   c                      | j                   d   S )N   rU   rP   s    r	   tbzExceptionTrap.tb   rX   r1   c                 V    |d   }|xr t        || j                        }|r|| _        |S rT   )
issubclassrL   rV   )rM   rV   rW   matchess       r	   __exit__zExceptionTrap.__exit__   s/    {<:dDOO<$DMr1   c                 ,    t        | j                        S rK   )boolrW   rP   s    r	   __bool__zExceptionTrap.__bool__   s    DIIr1   _testc                J     t        j                         fd       }|S )a  
        Wrap func and replace the result with the truth
        value of the trap (True if an exception occurred).

        First, give the decorator an alias to support Python 3.8
        Syntax.

        >>> raises = ExceptionTrap(ValueError).raises

        Now decorate a function that always fails.

        >>> @raises
        ... def fail():
        ...     raise ValueError('failed')
        >>> fail()
        True
        c                  x    t        j                        5 } | i | d d d               S # 1 sw Y   xY wrK   )rI   rL   )argskwargstraprg   funcrM   s      r	   wrapperz%ExceptionTrap.raises.<locals>.wrapper   s=    t/ &4d%f%&;& &s   	09)r   wraps)rM   rm   rg   rn   s   ``` r	   raiseszExceptionTrap.raises   s'    & 
		 
	
 r1   c                 D    | j                  |t        j                        S )a  
        Wrap func and replace the result with the truth
        value of the trap (True if no exception).

        First, give the decorator an alias to support Python 3.8
        Syntax.

        >>> passes = ExceptionTrap(ValueError).passes

        Now decorate a function that always fails.

        >>> @passes
        ... def fail():
        ...     raise ValueError('failed')

        >>> fail()
        False
        rf   )rp   operatornot_)rM   rm   s     r	   passeszExceptionTrap.passes   s    & {{4x}}{55r1   N)__name__
__module____qualname____doc__rV   	ExceptionrN   rQ   propertyrW   r[   r^   rb   re   rd   rp   rt   r   r1   r	   rI   rI      ss    B  H#,, %             %) 66r1   rI   c                       e Zd ZdZy)suppressz
    A version of contextlib.suppress with decorator support.

    >>> @suppress(KeyError)
    ... def key_error():
    ...     {}['']
    >>> key_error()
    N)ru   rv   rw   rx   r   r1   r	   r|   r|      s    r1   r|   c                   (    e Zd ZdZ	 	 ddZd Zd Zy)on_interrupta  
    Replace a KeyboardInterrupt with SystemExit(1)

    >>> def do_interrupt():
    ...     raise KeyboardInterrupt()
    >>> on_interrupt('error')(do_interrupt)()
    Traceback (most recent call last):
    ...
    SystemExit: 1
    >>> on_interrupt('error', code=255)(do_interrupt)()
    Traceback (most recent call last):
    ...
    SystemExit: 255
    >>> on_interrupt('suppress')(do_interrupt)()
    >>> with __import__('pytest').raises(KeyboardInterrupt):
    ...     on_interrupt('ignore')(do_interrupt)()
    c                      || _         || _        y rK   )actioncode)rM   r   r   s      r	   rN   zon_interrupt.__init__  s     	r1   c                     | S rK   r   rP   s    r	   rQ   zon_interrupt.__enter__  rR   r1   c                     |t         us| j                  dk(  ry | j                  dk(  rt        | j                        || j                  dk(  S )Nignoreerrorr|   )KeyboardInterruptr   
SystemExitr   )rM   exctypeexcinstexctbs       r	   rb   zon_interrupt.__exit__  sE    ++t{{h/F[[G#TYY'W4{{j((r1   N)r   rZ   )ru   rv   rw   rx   rN   rQ   rb   r   r1   r	   r~   r~      s     (  )r1   r~   )r   r   
contextlibr   r3   shutilrr   r   contextmanagerr
   r$   r   rmtreer6   rE   rG   rI   r|   ContextDecoratorr~   r   r1   r	   <module>r      s    	           $(U 7 7:3( ]]  $ !  $ 
 
n6 n6bz""J$?$? %):.. %)r1   