a
    0f^$                     @   s@  U 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m	Z	 d dl
mZ d dlmZmZmZmZmZmZmZmZ d dlmZmZ eeZedddZed	d
ddZdaee ed< e	ed dddZG dd dZ da!ee  ed< e	ee ddf dddZ"G dd dZ#e# Z$G dd dZ%G dd de%Z&dS )    N)	ExitStackcontextmanager)Path)AnyCallableDict	GeneratorListOptionalTypeVarUnion)enumrmtree_TTempDirectory)boundz	build-envzephem-wheel-cachez	req-build)	BUILD_ENVEPHEM_WHEEL_CACHE	REQ_BUILD_tempdir_manager)NNNreturnc                  c   sJ   t  0} t|  }azd V  W |an|a0 W d    n1 s<0    Y  d S N)r   r   )stackold_tempdir_manager r   U/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pip/_internal/utils/temp_dir.pyglobal_tempdir_manager'   s
    
r   c                   @   s@   e Zd ZdZddddZeeddddZeed	d
dZdS )TempDirectoryTypeRegistryzManages temp directory behaviorNr   c                 C   s
   i | _ d S r   _should_deleteselfr   r   r   __init__5   s    z"TempDirectoryTypeRegistry.__init__)kindvaluer   c                 C   s   || j |< dS )z[Indicate whether a TempDirectory of the given kind should be
        auto-deleted.
        Nr   )r"   r$   r%   r   r   r   
set_delete8   s    z$TempDirectoryTypeRegistry.set_deleter$   r   c                 C   s   | j |dS )z^Get configured auto-delete flag for a given TempDirectory type,
        default True.
        T)r    get)r"   r$   r   r   r   
get_delete>   s    z$TempDirectoryTypeRegistry.get_delete)	__name__
__module____qualname____doc__r#   strboolr&   r)   r   r   r   r   r   2   s   r   _tempdir_registryc                  c   s$   t } t a zt V  W | a n| a 0 dS )zuProvides a scoped global tempdir registry that can be used to dictate
    whether directories should be deleted.
    N)r0   r   )old_tempdir_registryr   r   r   tempdir_registryH   s
    r2   c                   @   s   e Zd ZdS )_DefaultN)r*   r+   r,   r   r   r   r   r3   V   s   r3   c                       s   e Zd ZdZdedddfee eede	f eeed fddZ
eed	d
dZed	ddZeedddZeeeddddZeedddZdd	ddZ  ZS )r   aM  Helper class that owns and cleans up a temporary directory.

    This class can be used as a context manager or as an OO representation of a
    temporary directory.

    Attributes:
        path
            Location to the created temporary directory
        delete
            Whether the directory should be deleted when exiting
            (when used as a contextmanager)

    Methods:
        cleanup()
            Deletes the temporary directory

    When used as a context manager, if the delete attribute is True, on
    exiting the context the temporary directory is deleted.
    NtempFT)pathdeleter$   globally_managedignore_cleanup_errorsc                    sr   t    |tu r$|d ur d}nd }|d u r6| |}|| _d| _|| _|| _|| _|rnt	d usdJ t	
|  d S )NF)superr#   _default_create_path_deletedr6   r$   r8   r   enter_context)r"   r5   r6   r$   r7   r8   	__class__r   r   r#   r   s    

zTempDirectory.__init__r   c                 C   s   | j rJ d| j | jS )Nz"Attempted to access deleted path: )r=   r<   r!   r   r   r   r5      s    zTempDirectory.pathc                 C   s   d| j j d| jdS )N< >)r@   r*   r5   r!   r   r   r   __repr__   s    zTempDirectory.__repr__)r"   r   c                 C   s   | S r   r   r!   r   r   r   	__enter__   s    zTempDirectory.__enter__)excr%   tbr   c                 C   s8   | j d ur| j }ntr$t| j}nd}|r4|   d S )NT)r6   r0   r)   r$   cleanup)r"   rF   r%   rG   r6   r   r   r   __exit__   s    
zTempDirectory.__exit__r'   c                 C   s,   t jtjd| dd}td| |S )z<Create a temporary directory and store its path in self.pathpip--prefixCreated temporary directory: %s)osr5   realpathtempfilemkdtemploggerdebug)r"   r$   r5   r   r   r   r;      s    zTempDirectory._createc                    s   d| _ tj| jsdS g  tdtf ttdd fdd}| j	rzt
| jdd W n  tyt   t
| j|d	 Y n0  rtd
| j n
t
| j dS )z6Remove the temporary directory created and reset stateTN.)funcr5   exc_valr   c                    s`   d tt||}| }| tjtjtjfv rBt	
d|| nt	
d| j|  | dS )z/Log a warning for a `rmtree` error and continue
z2Failed to remove a temporary file '%s' due to %s.
z%s failed with %s.N)join	tracebackformat_exception_onlytyperstriprO   unlinkremovermdirrS   rT   r,   append)rU   r5   rV   Zformatted_excerrorsr   r   onerror   s    z&TempDirectory.cleanup.<locals>.onerrorF)ignore_errors)Zonexcz[Failed to remove contents in a temporary directory '%s'.
You can safely remove it manually.)r=   rO   r5   existsr<   r   r   r   BaseExceptionr8   r   OSErrorrS   warning)r"   rc   r   ra   r   rH      s(    
zTempDirectory.cleanup)r*   r+   r,   r-   r:   r
   r.   r   r/   r3   r#   propertyr5   rD   r   rE   r   rI   r;   rH   __classcell__r   r   r?   r   r   ]   s(   #
c                       sb   e Zd ZdZdZdeee dd fddZe	ee
eddf ddd	Zeed
ddZ  ZS )AdjacentTempDirectorya  Helper class that creates a temporary directory adjacent to a real one.

    Attributes:
        original
            The original directory to create a temp directory for.
        path
            After calling create() or entering, contains the full
            path to the temporary directory.
        delete
            Whether the directory should be deleted when exiting
            (when used as a contextmanager)

    z-~.=%0123456789N)originalr6   r   c                    s   | d| _t j|d d S )Nz/\)r6   )r\   rl   r9   r#   )r"   rl   r6   r?   r   r   r#      s    zAdjacentTempDirectory.__init__)namer   c                 c   s   t dt|D ]D}t| j|d D ],}dd| ||d  }||kr$|V  q$qt t| jD ]8}t| j|D ]$}dd| | }||krt|V  qtqbdS )a  Generates a series of temporary names.

        The algorithm replaces the leading characters in the name
        with ones that are valid filesystem characters, but are not
        valid package names (for both Python and pip definitions of
        package).
           ~ N)rangelen	itertoolscombinations_with_replacementLEADING_CHARSrX   )clsrm   i	candidatenew_namer   r   r   _generate_names   s    	

z%AdjacentTempDirectory._generate_namesr'   c                 C   s   t j| j\}}| |D ]d}t j||}zt | W n2 tyn } z|jtj	krZ W Y d }~qd }~0 0 t j
|} qqt j
tjd| dd}td| |S )NrJ   rK   rL   rN   )rO   r5   splitrl   rz   rX   mkdirrg   errnoEEXISTrP   rQ   rR   rS   rT   )r"   r$   rootrm   rx   r5   exr   r   r   r;     s    zAdjacentTempDirectory._create)N)r*   r+   r,   r-   ru   r.   r
   r/   r#   classmethodr   rz   r;   rj   r   r   r?   r   rk      s   rk   )'r}   rs   loggingos.pathrO   rQ   rY   
contextlibr   r   pathlibr   typingr   r   r   r   r	   r
   r   r   pip._internal.utils.miscr   r   	getLoggerr*   rS   r   tempdir_kindsr   __annotations__r   r   r0   r2   r3   r:   r   rk   r   r   r   r   <module>   s8   
(

 