U .e@sddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z e r\ddl m Z eeZGdddeZGdd d eZdS) )absolute_importN)rmtree)MYPY_CHECK_RUNNING)OptionalcsVeZdZdZdfdd ZeddZdd Zd d Zd d Z ddZ ddZ 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. NtempcsPtt||dkr"|dkr"d}|dkr4||}||_d|_||_||_dS)NTF)superr__init___create_path_deleteddeletekind)selfpathr 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 AssertionErrorformatr rrrrr@s zTempDirectory.pathcCsd|jj|jS)Nz <{} {!r}>)rr__name__rrrrr__repr__HszTempDirectory.__repr__cCs|SNrrrrr __enter__KszTempDirectory.__enter__cCs|jr|dSr)r cleanup)rexcvaluetbrrr__exit__NszTempDirectory.__exit__cCs.tjtjd|d}td||S)zECreate a temporary directory and store its path in self.path pip-{}-prefixCreated temporary directory: {})osrrealpathtempfilemkdtemprloggerdebug)rrrrrrr Rs zTempDirectory._createcCs"d|_tj|jrt|jdS)z?Remove the temporary directory created and reset state TN)r r%rexistsr rrrrrr_szTempDirectory.cleanup)NNr) r __module__ __qualname____doc__r propertyrrrr r r __classcell__rrrrrs  rcs:eZdZdZdZd fdd ZeddZdd ZZ S) AdjacentTempDirectoryaHelper 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|ddS)Nz/\)r )rstriporiginalrr1r )rr3r rrrr |s zAdjacentTempDirectory.__init__ccstdt|D]D}t|j|dD],}dd|||d}||kr$|Vq$qtt|jD]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)rangelen itertoolscombinations_with_replacement LEADING_CHARSjoin)clsnamei candidatenew_namerrr_generate_namess  z%AdjacentTempDirectory._generate_namesc Cstj|j\}}||D]b}tj||}zt|Wn0tk rl}z|jtj kr\W5d}~XYqXtj |}qqtj t j d |d}td ||S)Nr!r"r$)r%rsplitr3rBr<mkdirOSErrorerrnoZEEXISTr&r'r(rr)r*)rrrootr>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.typingrtypingrZ getLoggerrr)objectrr1rrrrs     Q