U ÀÒ.e‘ ã @ sŠ d dl mZ d dlZd dlZd dlZd dlZd dlZd dlm Z d dl mZ er\d dlm Z e e¡ZG dd„ deƒZG dd „ d eƒZdS ) é )Úabsolute_importN)Úrmtree)ÚMYPY_CHECK_RUNNING)ÚOptionalc sV e Zd ZdZd‡ fdd„ Zedd„ ƒZdd „ Zd d„ Zdd „ Z dd„ Z dd„ Z‡ ZS )Ú TempDirectoryaM 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Útempc sP t t| ƒ ¡ |d kr"|d kr"d}|d kr4| |¡}|| _d| _|| _|| _d S )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__c C s | j rtd | j¡ƒ‚| jS )Nz$Attempted to access deleted path: {})r ÚAssertionErrorÚformatr ©r r r r r @ s ÿzTempDirectory.pathc C s d | jj| j¡S )Nz <{} {!r}>)r r Ú__name__r r r r r Ú__repr__H s zTempDirectory.__repr__c C s | S ©Nr r r r r Ú __enter__K s zTempDirectory.__enter__c C s | j r| ¡ d S r )r Úcleanup)r ÚexcÚvalueÚtbr r r Ú__exit__N s zTempDirectory.__exit__c C s. t j 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)r r r r r r r R s ÿzTempDirectory._createc C s" d| _ tj | j¡rt| jƒ dS )z?Remove the temporary directory created and reset state TN)r r% r Úexistsr r r r r r r _ s zTempDirectory.cleanup)NNr ) r Ú __module__Ú__qualname__Ú__doc__r Úpropertyr r r r r r Ú __classcell__r r r r r s ü r c s: e Zd ZdZdZd ‡ 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-~.=%0123456789Nc s" | d¡| _tt| ƒj|d� d S )Nz/\)r )ÚrstripÚoriginalr r1 r )r r3 r r r r r | s zAdjacentTempDirectory.__init__c c s t dt|ƒƒD ]D}t | j|d ¡D ],}dd |¡ ||d… }||kr$|V q$qt t| jƒƒD ]8}t | j|¡D ]$}dd |¡ | }||krt|V qtqbdS )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_namer r r Ú_generate_names€ s ÿ ÿz%AdjacentTempDirectory._generate_namesc C s® t j | j¡\}}| |¡D ]b}t j ||¡}zt |¡ W n0 tk rl } z|jtj kr\‚ W 5 d }~X Y qX t j |¡} qšqt j tjd |¡d�¡}t d |¡¡ |S )Nr! r" r$ )r% r Úsplitr3 rB r<