o
    bb,                     @   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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dS )    Nc              	   c   s8    t  }t |  z| V  W t | d S t | w N)osgetcwdchdir)dirorig r   /home/ych/rk3568/buildroot/output/rockchip_rk3568_recovery/build/host-python-setuptools-62.6.0/setuptools/_vendor/jaraco/context.pypushd
   s   
r
   c                 c   s   |du rt j| dddd}|du rtjtjdd}|djdi t	  zMd}d	}d

||f}||jddt| it	  || |V  W d   n1 sWw   Y  W |djdi t	  dS W |djdi t	  dS |djdi t	  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mkdir {target_dir}zwget {url} -O -z7tar x{compression} --strip-components=1 -C {target_dir}z | compressionzrm -Rf {target_dir}r   )r   pathbasenamereplace	functoolspartial
subprocess
check_callformatvarsjoininfer_compression)url
target_dirrunnerr
   getterextractcmdr   r   r	   tarball_context   s"   
2r   c                 C   s&   | dd }t dddd}||dS )zF
    Given a URL or filename, infer the compression code for tar.
    NzjJ)gzbzxz)dictget)r   compression_indicatormappingr   r   r	   r   0   s   r   c                 c   s*    t  }z
|V  W | | dS | | w )zk
    Create a temporary directory context. Pass a custom remover
    to override the removal behavior.
    N)tempfilemkdtemp)removertemp_dirr   r   r	   r.   ;   s
   r.   Tc           	      c   s    d| v rdnd}| /}|d| |g}|r| d|g ttjjd}|r'|nd}tj||d |V  W d   dS 1 s>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)extendopenr   r   devnullr   r   )	r   branchquietdest_ctxexerepo_dirr   r6   r3   r   r   r	   repo_contextH   s   "r<   c                   c   s    d V  d S r   r   r   r   r   r	   null[   s   
r=   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 )ExceptionTrapaG  
    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

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

    >>> bool(trap)
    False
    )NNNc                 C   s
   || _ d S r   )
exceptions)selfr?   r   r   r	   __init__      
zExceptionTrap.__init__c                 C   s   | S r   r   r@   r   r   r	   	__enter__   s   zExceptionTrap.__enter__c                 C   
   | j d S Nr   exc_inforC   r   r   r	   type      
zExceptionTrap.typec                 C   rE   )N   rG   rC   r   r   r	   value   rJ   zExceptionTrap.valuec                 C   rE   )N   rG   rC   r   r   r	   tb   rJ   zExceptionTrap.tbc                 G   s&   |d }|ot || j}|r|| _|S rF   )
issubclassr?   rH   )r@   rH   rI   matchesr   r   r	   __exit__   s
   zExceptionTrap.__exit__c                 C   s
   t | jS r   )boolrI   rC   r   r   r	   __bool__   rB   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                     sF   t j}| i | W d     |S 1 sw   Y   |S r   )r>   r?   )argskwargstraprU   funcr@   r   r	   wrapper   s   
z%ExceptionTrap.raises.<locals>.wrapper)r   wraps)r@   rZ   rU   r[   r   rY   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
        rT   )r]   operatornot_)r@   rZ   r   r   r	   passes   s   zExceptionTrap.passesN)__name__
__module____qualname____doc__rH   	ExceptionrA   rD   propertyrI   rL   rN   rQ   rS   rR   r]   r`   r   r   r   r	   r>   `   s    


r>   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)ra   rb   rc   rd   r   r   r   r	   rg      s    rg   )r   r   
contextlibr   r+   shutilr^   contextmanagerr
   r   r   rmtreer.   r<   r=   r>   rg   ContextDecoratorr   r   r   r	   <module>   s(    
	
m