U
    Ïvag$  ã                   @   sÞ   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d„ ƒZ	ejdde	fdd„ƒZ
dd„ Zejejfdd	„ƒZejdd
efdd„ƒZejdd„ ƒZG dd„ dƒZG dd„ dejejƒZG dd„ dejƒZdS )é    Nc              	   c   s.   t  ¡ }t  | ¡ z
| V  W 5 t  |¡ X dS )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Úorig© r   úU/var/www/html/myvenv/lib/python3.8/site-packages/setuptools/_vendor/jaraco/context.pyÚpushd   s
    	

r	   c              
   c   sÈ   |dkr$t j | ¡ dd¡ dd¡}|dkr>tjtjdd�}nt 	dt
¡ |djf tƒ Žƒ zRd
}d}d ||f¡}||jf dt| ƒitƒ —Žƒ ||ƒ� |V  W 5 Q R X W 5 |d	jf tƒ Žƒ X dS )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rm -Rf {target_dir}zwget {url} -O -z7tar x{compression} --strip-components=1 -C {target_dir}z | Úcompression)r   ÚpathÚbasenameÚreplaceÚ	functoolsÚpartialÚ
subprocessÚ
check_callÚwarningsÚwarnÚDeprecationWarningÚformatÚvarsÚjoinÚinfer_compression)ÚurlZ
target_dirZrunnerr	   ÚgetterÚextractÚcmdr   r   r   Útarball_context   s    
r   c                 C   s&   | dd… }t d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'
    éþÿÿÿNÚzÚjÚJ)ÚgzZbzÚxz)ÚdictÚget)r   Zcompression_indicatorÚmappingr   r   r   r   :   s    r   c                 c   s"   t  ¡ }z
|V  W 5 | |ƒ X dS )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)ZremoverÚtemp_dirr   r   r   r+   N   s    
r+   Tc           	   	   c   sr   d| krdnd}|ƒ �R}|d| |g}|r6|  d|g¡ ttjjdƒ}|rL|nd}tj||d� |V  W 5 Q R X 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.
    ÚgitZhgÚclonez--branchÚwN)Ústdout)ÚextendÚopenr   r   Údevnullr   r   )	r   ÚbranchÚquietZdest_ctxZexeZrepo_dirr   r2   r/   r   r   r   Úrepo_contexta   s    r5   c                   c   s
   dV  dS )z‡
    A null context suitable to stand in for a meaningful context.

    >>> with null() as value:
    ...     assert value is None
    Nr   r   r   r   r   Únullt   s    r6   c                   @   st   e Zd ZdZdZeffdd„Zdd„ Zedd„ ƒZ	ed	d
„ ƒZ
edd„ ƒZdd„ Zdd„ Zedœdd„Zd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                 C   s
   || _ d S ©N)Ú
exceptions)Úselfr9   r   r   r   Ú__init__£   s    zExceptionTrap.__init__c                 C   s   | S r8   r   ©r:   r   r   r   Ú	__enter__¦   s    zExceptionTrap.__enter__c                 C   s
   | j d S ©Nr   ©Úexc_infor<   r   r   r   Útype©   s    zExceptionTrap.typec                 C   s
   | j d S )Né   r?   r<   r   r   r   Úvalue­   s    zExceptionTrap.valuec                 C   s
   | j d S )Né   r?   r<   r   r   r   Útb±   s    zExceptionTrap.tbc                 G   s&   |d }|ot || jƒ}|r"|| _|S r>   )Ú
issubclassr9   r@   )r:   r@   rA   Úmatchesr   r   r   Ú__exit__µ   s
    zExceptionTrap.__exit__c                 C   s
   t | jƒS r8   )ÚboolrA   r<   r   r   r   Ú__bool__¼   s    zExceptionTrap.__bool__©Ú_testc                   s   t  ˆ¡‡ ‡‡fd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               	      s(   t ˆjƒ�}ˆ| |Ž W 5 Q R X ˆ |ƒS r8   )r7   r9   )ÚargsÚkwargsÚtrap©rL   Úfuncr:   r   r   ÚwrapperÒ   s    z%ExceptionTrap.raises.<locals>.wrapper)r   Úwraps)r:   rQ   rL   rR   r   rP   r   Úraises¿   s    zExceptionTrap.raisesc                 C   s   | j |tjd�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
        rK   )rT   ÚoperatorÚnot_)r:   rQ   r   r   r   ÚpassesÚ   s    zExceptionTrap.passesN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r@   Ú	Exceptionr;   r=   ÚpropertyrA   rC   rE   rH   rJ   rI   rT   rW   r   r   r   r   r7      s   !


r7   c                   @   s   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)rX   rY   rZ   r[   r   r   r   r   r^   ð   s   r^   c                   @   s*   e Zd ZdZddd„Zdd„ Zd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)()
    ÚerrorrB   c                 C   s   || _ || _d S r8   )ÚactionÚcode)r:   ra   rb   r   r   r   r;     s    zon_interrupt.__init__c                 C   s   | S r8   r   r<   r   r   r   r=     s    zon_interrupt.__enter__c                 C   s6   |t k	s| jdkrd S | jdkr,t| jƒ|‚| jdkS )NÚignorer`   r^   )ÚKeyboardInterruptra   Ú
SystemExitrb   )r:   ÚexctypeÚexcinstÚexctbr   r   r   rH     s
    
zon_interrupt.__exit__N)r`   rB   )rX   rY   rZ   r[   r;   r=   rH   r   r   r   r   r_   û   s     û

r_   )r   r   Ú
contextlibr   r)   ÚshutilrU   r   Úcontextmanagerr	   r   r   Úrmtreer+   r5   r6   r7   r^   ÚContextDecoratorr_   r   r   r   r   Ú<module>   s*   


q