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