
    ,hP%                    4   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j4                  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!y)    )annotationsN)Iterator)      )tarfilec              #     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/var/www/html/Resume-Scraper/venv/lib/python3.12/site-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                  j                  |       }t        j                  |d      5 }|j                  |t               ddd       | t        j                  |       y# 1 sw Y   #xY w# t        j                  |       w xY w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)url
target_dirreqtfs       r   tarballr%   '   s       WW%%c*229bAII&RTU

 HHZ"nn$$S)\\#E2 	IbMMz2GMH	Ij!		I 	I 	j!s6   AC06C C
(C 4C0
CC C--C0c                N    | j                   j                  dd      \  }| _         | S )N/   )namesplit)memberr   _s      r   r   r   G   s%     [[&&sA.NAv{M    c                 F    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 }| d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wwN )argskwargssavedresinnerouters       r   composedz/_compose.<locals>.compose_two.<locals>.composedd   sL     '' 5%, #	     s(   	A	7+7	A4	7A A)
contextlibcontextmanager)r7   r8   r9   s   `` r   compose_twoz_compose.<locals>.compose_twoc   s    	 ((22r-   )	functoolsreducereversed)cmgrsr<   s     r   _composerA   O   s     (3 K%99r-   c               /     K   t        j                  dt        d       |j                  dt              }t        | i |5 } ||      5 }| d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY ww)NzBtarball_context is deprecated. Use tarball or tarball_cwd instead.   
stacklevelr   )warningswarnDeprecationWarningpopr   r%   )r3   r4   	pushd_ctxtballr   s        r   tarball_contextrL   p   ss     MML
 

7E*I	$	!&	! UIe,< 	     s5   >A7 	A+	AA+	A7A(	$A++A40A7c                    t        j                  dt        d       | 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'
    z3infer_compression is deprecated with no replacementrC   rD   NzjJ)gzbzxz)rF   rG   rH   dictget)r!   compression_indicatormappings      r   infer_compressionrY   |   sG     MM=  Hccc*G;;,c22r-   c              #  h   K   t        j                         }	 |  | |       y#  | |       w xY w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   r^   r^      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)extendr   r	   r   devnull
subprocess
check_call)	r!   branchquietdest_ctxexerepo_dircmdrf   rd   s	            r   repo_contextro      s      C<%TC	 xGS(+JJ
F+,rww,!tc&1  s   BA!A<3	B<BBc                 b    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.nullcontextrC   rD   )rF   rG   rH   r:   nullcontextr2   r-   r   nullrr      s*     MM8
 !!##r-   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 r1   )
exceptions)selfrv   s     r   __init__zExceptionTrap.__init__   s	    $r-   c                    | S r1   r2   rw   s    r   	__enter__zExceptionTrap.__enter__       r-   c                     | j                   d   S Nr   exc_inforz   s    r   typezExceptionTrap.type       }}Qr-   c                     | j                   d   S )Nr(   r   rz   s    r   valuezExceptionTrap.value   r   r-   c                     | j                   d   S )NrC   r   rz   s    r   tbzExceptionTrap.tb   r   r-   c                V    |d   }|xr t        || j                        }|r|| _        |S r~   )
issubclassrv   r   )rw   r   r   matchess       r   __exit__zExceptionTrap.__exit__  s/    {<:dDOO<$DMr-   c                ,    t        | j                        S r1   )boolr   rz   s    r   __bool__zExceptionTrap.__bool__  s    DIIr-   _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r1   )rt   rv   )r3   r4   trapr   funcrw   s      r   wrapperz%ExceptionTrap.raises.<locals>.wrapper!  s=    t/ &4d%f%&;& &s   	09)r=   wraps)rw   r   r   r   s   ``` r   raiseszExceptionTrap.raises  s'    & 
		 
	
 r-   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
        r   )r   operatornot_)rw   r   s     r   passeszExceptionTrap.passes)  s    & {{4x}}{55r-   N)__name__
__module____qualname____doc__r   	Exceptionrx   r{   propertyr   r   r   r   r   r   r   r   r2   r-   r   rt   rt      ss    B  H#,, %             %) 66r-   rt   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)r   r   r   r   r2   r-   r   r   r   ?  s    r-   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 r1   )actioncode)rw   r   r   s      r   rx   zon_interrupt.__init__]  s    	r-   c                    | S r1   r2   rz   s    r   r{   zon_interrupt.__enter__a  r|   r-   c                    |t         us| j                  dk(  ry | j                  dk(  rt        | j                        || j                  dk(  S )Nignoreerrorr   )KeyboardInterruptr   
SystemExitr   )rw   exctypeexcinstexctbs       r   r   zon_interrupt.__exit__d  sE    ++t{{h/F[[G#TYY'W4{{j((r-   N)r   r(   )r   r   r   r   rx   r{   r   r2   r-   r   r   r   J  s    $)r-   r   )r   zstr | os.PathLikereturnIterator[str | os.PathLike]r1   )r"   zstr | os.PathLike | Noner   r   )r+   tarfile.TarInfor   r   )"
__future__r   r:   r=   r   r	   r   rg   sysr[   urllib.requestr   rF   typingr   version_info	backportsr   r;   r   r%   r   rA   tarball_cwdrL   rY   r    r^   ro   rr   rt   r   ContextDecoratorr   r2   r-   r   <module>r      sO   "    	   
     g!    04"-" " "> :< ug&  32 ]]  $ !  $$&n6 n6bz""J$?$? ):.. )r-   