
    ϶vgP%                       d dl m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	Z	d dl
Zd dlZd dlmZ ej        dk     rd dlmZ nd dlZej        dd
            Zej        	 dd d            Zd!dZd Z eee          Zej        d             Zd Zej        ej        fd            Zej        ddefd            Zd Z G d d          Z G d dej        ej                   Z G d dej                   Z!dS )"    )annotationsN)Iterator)      )tarfiledirstr | os.PathLikereturnIterator[str | os.PathLike]c              #     K   t          j                    }t          j        |            	 | V  t          j        |           dS # t          j        |           w xY 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)r   origs     ^/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/setuptools/_vendor/jaraco/context.pypushdr      sQ       9;;DHSMMM			
s   A A
target_dirstr | os.PathLike | Nonec              #    K   |Gt           j                            |                               dd                              dd          }t          j        |           	 t
          j                            |           }t          j	        |d          5 }|
                    |t                     ddd           n# 1 swxY w Y   |V  t          j        |           dS # t          j        |           w xY w)a  
    Get a tarball, extract it, yield, then clean up.

    >>> import urllib.request
    >>> url = getfixture('tarfile_served')
    >>> target = getfixture('tmp_path') / 'out'
    >>> tb = tarball(url, target_dir=target)
    >>> import pathlib
    >>> with tb as extracted:
    ...     contents = pathlib.Path(extracted, 'contents.txt').read_text(encoding='utf-8')
    >>> assert not os.path.exists(extracted)
    Nz.tar.gz z.tgzzr|*)fileobjmode)pathfilter)r   r   basenamereplacemkdirurllibrequesturlopenr   open
extractallstrip_first_componentshutilrmtree)urlr   reqtfs       r   tarballr)   '   s6       W%%c**229bAAII&RTUU

 HZ"n$$S))\#E222 	IbMMz2GMHHH	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	Ij!!!!!j!!!!s0   !5C$ B?3C$ ?CC$ CC$ $C:membertarfile.TarInfoc                L    | j                             dd          \  }| _         | S )N/   )namesplit)r*   r   _s      r   r#   r#   G   s&     [&&sA..NAv{M    c                 L    d }t          j        |t          |                     S )a  
    Compose any number of dependent context managers into a single one.

    The last, innermost context manager may take arbitrary arguments, but
    each successive context manager should accept the result from the
    previous as a single parameter.

    Like :func:`jaraco.functools.compose`, behavior works from right to
    left, so the context manager should be indicated from outermost to
    innermost.

    Example, to create a context manager to change to a temporary
    directory:

    >>> temp_dir_as_cwd = _compose(pushd, temp_dir)
    >>> with temp_dir_as_cwd() as dir:
    ...     assert os.path.samefile(os.getcwd(), dir)
    c                :      fd}t          j        |          S )Nc               ?     K    | i |5 } |          5 }|V  d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S N )argskwargssavedresinnerouters       r   composedz/_compose.<locals>.compose_two.<locals>.composedd   s      ''' 5%%,, #			                                s,   A)A-	A-	AAA)
contextlibcontextmanager)r<   r=   r>   s   `` r   compose_twoz_compose.<locals>.compose_twoc   s5    	 	 	 	 	 	 (222r2   )	functoolsreducereversed)cmgrsrA   s     r   _composerF   O   s,    (3 3 3 K%999r2   c               /    K   t          j        dt          d           |                    dt                    }t          | i |5 } ||          5 }|V  d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NzBtarball_context is deprecated. Use tarball or tarball_cwd instead.   
stacklevelr   )warningswarnDeprecationWarningpopr   r)   )r8   r9   	pushd_ctxtballr   s        r   tarball_contextrQ   p   s     ML   
 

7E**I	$	!&	!	! UIIe,<,< 			                                s6   A;A#A;#A'	'A;*A'	+A;;A?A?c                    t          j        dt          d           | dd         }t          ddd	          }|                    |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'
    z3infer_compression is deprecated with no replacementrH   rI   NzjJ)gzbzxz)rK   rL   rM   dictget)r&   compression_indicatormappings      r   infer_compressionr^   |   s_     M=     Hccc***G;;,c222r2   c              #  p   K   t          j                    }	 |V   | |           dS #  | |           w xY w)a`  
    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', encoding='utf-8')
    >>> assert not os.path.exists(the_dir)
    N)tempfilemkdtemp)removertemp_dirs     r   rc   rc      sP       !!Hs   ( 5Tc              #    K   d| v rdnd} |            5 }|d| |g}|r|                     d|g           t          t          j        j        d          }|r|nd}t          j        ||           |V  ddd           dS # 1 swxY w Y   dS )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)extendr!   r   r   devnull
subprocess
check_call)	r&   branchquietdest_ctxexerepo_dircmdrk   ri   s	            r   repo_contextrt      s       C<<%%TC	 xGS(+ 	-JJ
F+,,,rw,,!+tc&1111                 s   ABBBc                 `    t          j        dt          d           t          j                    S )aD  
    A null context suitable to stand in for a meaningful context.

    >>> with null() as value:
    ...     assert value is None

    This context is most useful when dealing with two or more code
    branches but only some need a context. Wrap the others in a null
    context to provide symmetry across all options.
    z.null is deprecated. Use contextlib.nullcontextrH   rI   )rK   rL   rM   r?   nullcontextr7   r2   r   nullrw      s7     M8   
 !###r2   c                      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dS )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                    || _         d S r6   )
exceptions)selfr{   s     r   __init__zExceptionTrap.__init__   s    $r2   c                    | S r6   r7   r|   s    r   	__enter__zExceptionTrap.__enter__       r2   c                    | j         d         S Nr   exc_infor   s    r   typezExceptionTrap.type       }Qr2   c                    | j         d         S )Nr.   r   r   s    r   valuezExceptionTrap.value   r   r2   c                    | j         d         S )NrH   r   r   s    r   tbzExceptionTrap.tb   r   r2   c                V    |d         }|ot          || j                  }|r|| _        |S r   )
issubclassr{   r   )r|   r   r   matchess       r   __exit__zExceptionTrap.__exit__  s5    {<:dDO<< 	%$DMr2   c                *    t          | j                  S r6   )boolr   r   s    r   __bool__zExceptionTrap.__bool__  s    DIr2   _testc               N     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                     t          j                  5 } | i | d d d            n# 1 swxY w Y    |          S r6   )ry   r{   )r8   r9   trapr   funcr|   s      r   wrapperz%ExceptionTrap.raises.<locals>.wrapper!  s    t// &4d%f%%%& & & & & & & & & & & & & & &5;;s   	+//)rB   wraps)r|   r   r   r   s   ``` r   raiseszExceptionTrap.raises  sF    & 
			 	 	 	 	 	 
		
 r2   c                D    |                      |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
        r   )r   operatornot_)r|   r   s     r   passeszExceptionTrap.passes)  s    & {{4x}{555r2   N)__name__
__module____qualname____doc__r   	Exceptionr}   r   propertyr   r   r   r   r   r   r   r   r7   r2   r   ry   ry      s         B  H#,, % % % %       X      X      X      %)     66 6 6 6 6r2   ry   c                      e Zd ZdZdS )suppressz
    A version of contextlib.suppress with decorator support.

    >>> @suppress(KeyError)
    ... def key_error():
    ...     {}['']
    >>> key_error()
    N)r   r   r   r   r7   r2   r   r   r   ?  s           r2   r   c                  &    e Zd ZdZddZd Zd ZdS )	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)()
    errorr.   c               "    || _         || _        d S r6   )actioncode)r|   r   r   s      r   r}   zon_interrupt.__init__]  s    			r2   c                    | S r6   r7   r   s    r   r   zon_interrupt.__enter__a  r   r2   c                    |t           us| j        dk    rd S | j        dk    rt          | j                  || j        dk    S )Nignorer   r   )KeyboardInterruptr   
SystemExitr   )r|   exctypeexcinstexctbs       r   r   zon_interrupt.__exit__d  sK    +++t{h/F/FF[G##TY''W4{j((r2   N)r   r.   )r   r   r   r   r}   r   r   r7   r2   r   r   r   J  sP         $     ) ) ) ) )r2   r   )r   r	   r
   r   r6   )r   r   r
   r   )r*   r+   r
   r+   )"
__future__r   r?   rB   r   r   r$   rl   sysr`   urllib.requestr   rK   typingr   version_info	backportsr   r@   r   r)   r#   rF   tarball_cwdrQ   r^   r%   rc   rt   rw   ry   r   ContextDecoratorr   r7   r2   r   <module>r      sn   " " " " " "          				      



             g!!!!!!!NNN      04" " " " ">   : : :< hug&&   3 3 32 ]    $ !    $$ $ $&n6 n6 n6 n6 n6 n6 n6 n6b    z"J$?   ) ) ) ) ):. ) ) ) ) )r2   