U ��.e��@s�ddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z e r\ddl m Z e�e�ZGdd�de�ZGdd �d e�ZdS) �)�absolute_importN)�rmtree)�MYPY_CHECK_RUNNING)�OptionalcsVeZdZdZd�fdd� Zedd��Zdd �Zd d �Zd d �Z dd�Z dd�Z �Z S)� TempDirectoryaMHelper 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�tempcsPtt|���|dkr"|dkr"d}|dkr4|�|�}||_d|_||_||_dS)NTF)�superr�__init__�_create�_path�_deleted�delete�kind)�self�pathr r�� __class__��@/usr/lib/python3.8/site-packages/pip/_internal/utils/temp_dir.pyr +s zTempDirectory.__init__cCs|jrtd�|j���|jS)Nz$Attempted to access deleted path: {})r �AssertionError�formatr �rrrrr@s �zTempDirectory.pathcCsd�|jj|j�S)Nz <{} {!r}>)rr�__name__rrrrr�__repr__HszTempDirectory.__repr__cCs|S�Nrrrrr� __enter__KszTempDirectory.__enter__cCs|jr|��dSr)r �cleanup)r�exc�value�tbrrr�__exit__NszTempDirectory.__exit__cCs.tj�tjd�|�d��}t�d�|��|S)zECreate a temporary directory and store its path in self.path �pip-{}-��prefix�Created temporary directory: {})�osr�realpath�tempfile�mkdtempr�logger�debug)rrrrrrr Rs �zTempDirectory._createcCs"d|_tj�|j�rt|j�dS)z?Remove the temporary directory created and reset state TN)r r%r�existsr rrrrrr_szTempDirectory.cleanup)NNr) r� __module__� __qualname__�__doc__r �propertyrrrr r r� __classcell__rrrrrs�  rcs:eZdZdZdZd �fdd� Zedd��Zdd �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-~.=%0123456789Ncs"|�d�|_tt|�j|d�dS)Nz/\)r )�rstrip�originalrr1r )rr3r rrrr |s zAdjacentTempDirectory.__init__ccs�tdt|��D]D}t�|j|d�D],}dd�|�||d�}||kr$|Vq$qtt|j��D]8}t�|j|�D]$}dd�|�|}||krt|VqtqbdS)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_CHARS�join)�cls�name�i� candidate�new_namerrr�_generate_names�s � �z%AdjacentTempDirectory._generate_namesc Cs�tj�|j�\}}|�|�D]b}tj�||�}zt�|�Wn0tk rl}z|jtj kr\�W5d}~XYqXtj� |�}q�qtj� t j d� |�d��}t�d� |��|S)Nr!r"r$)r%r�splitr3rBr<�mkdir�OSError�errnoZEEXISTr&r'r(rr)r*)rr�rootr>r@rZexrrrr �s  �zAdjacentTempDirectory._create)N) rr,r-r.r;r � classmethodrBr r0rrrrr1gs  r1)Z __future__rrFr9ZloggingZos.pathr%r'Zpip._internal.utils.miscrZpip._internal.utils.typingr�typingrZ getLoggerrr)�objectrr1rrrr�s     Q