U v_ @s&ddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddlmZmZddlmZerddlmZmZmZmZmZmZed d d ZeeZed d ddZdae ddZ Gddde!Z"da#e ddZ$Gddde!Z%e%Z&Gdd d e!Z'Gddde'Z(dS))absolute_importN)contextmanager) ExitStack) ensure_text)enumrmtree)MYPY_CHECK_RUNNING)AnyDictIteratorOptionalTypeVarUnion_T TempDirectory)boundz build-envzephem-wheel-cachez req-build) BUILD_ENVEPHEM_WHEEL_CACHE REQ_BUILDc cs2t"}t|}az dVW5|aXW5QRXdSN)r_tempdir_manager)stackold_tempdir_managerr/builddir/build/BUILDROOT/alt-python38-pip-20.2.4-1.el7.x86_64/opt/alt/python38/lib/python3.8/site-packages/pip/_internal/utils/temp_dir.pyglobal_tempdir_manager%s   rc@s(eZdZdZddZddZddZdS) TempDirectoryTypeRegistryz$Manages temp directory behavior cCs i|_dSr_should_deleteselfrrr__init__5sz"TempDirectoryTypeRegistry.__init__cCs||j|<dS)z[Indicate whether a TempDirectory of the given kind should be auto-deleted. Nr)r kindvaluerrr set_delete9sz$TempDirectoryTypeRegistry.set_deletecCs|j|dS)z^Get configured auto-delete flag for a given TempDirectory type, default True. T)rget)r r"rrr get_delete@sz$TempDirectoryTypeRegistry.get_deleteN)__name__ __module__ __qualname____doc__r!r$r&rrrrr1srccs t}taz tVW5|aXdS)zuProvides a scoped global tempdir registry that can be used to dictate whether directories should be deleted. N)_tempdir_registryr)old_tempdir_registryrrrtempdir_registryKs  r-c@s eZdZdS)_DefaultN)r'r(r)rrrrr.Zsr.cs^eZdZdZdeddffdd ZeddZd d Zd d Z d dZ ddZ ddZ Z S)raMHelper 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. NtempFcsptt||tkr(|dk r$d}nd}|dkr:||}||_d|_||_||_|rlt dk sbt t |dS)NF) superrr!_default_create_path_deleteddeleter"rAssertionError enter_context)r pathr5r"globally_managed __class__rrr!vs  zTempDirectory.__init__cCs|jrtd|j|jS)Nz$Attempted to access deleted path: {})r4r6formatr3rrrrr8s zTempDirectory.pathcCsd|jj|jS)Nz <{} {!r}>)r<r;r'r8rrrr__repr__szTempDirectory.__repr__cCs|Srrrrrr __enter__szTempDirectory.__enter__cCs8|jdk r|j}ntr$t|j}nd}|r4|dS)NT)r5r+r&r"cleanup)r excr#tbr5rrr__exit__s zTempDirectory.__exit__cCs*tjtjd|d}td||S)zECreate a temporary directory and store its path in self.path pip-{}-prefixCreated temporary directory: %s)osr8realpathtempfilemkdtempr<loggerdebug)r r"r8rrrr2s  zTempDirectory._createcCs&d|_tj|jr"tt|jdS)z?Remove the temporary directory created and reset state TN)r4rGr8existsr3rrrrrrr?szTempDirectory.cleanup)r'r(r)r*r1r!propertyr8r=r>rBr2r? __classcell__rrr:rras  cs: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/\)r5)rstriporiginalr0rPr!)r rRr5r:rrr!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)NrCrDrF)rGr8splitrRrar[mkdirOSErrorerrnoEEXISTrHrIrJr<rKrL)r r"rootr]r_r8exrrrr2s   zAdjacentTempDirectory._create)N) r'r(r)r*rZr! classmethodrar2rOrrr:rrPs  rP)) __future__rrerXloggingos.pathrGrI contextlibrpip._vendor.contextlib2rZpip._vendor.sixrpip._internal.utils.miscrrpip._internal.utils.typingrtypingr r r r r rr getLoggerr'rK tempdir_kindsrrobjectrr+r-r.r1rrPrrrrs<          i