3 Re @s&ddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddlmZmZddlmZerddlmZmZmZmZmZmZed d d ZejeZed 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)Zboundz build-envzephem-wheel-cachez req-build) BUILD_ENVEPHEM_WHEEL_CACHE REQ_BUILDccs2t"}t|}az dVWd|aXWdQRXdS)N)r_tempdir_manager)stackold_tempdir_managerr/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-5.el9.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_internal/utils/temp_dir.pyglobal_tempdir_manager%s   rc@s(eZdZdZddZddZddZdS) TempDirectoryTypeRegistryz$Manages temp directory behavior cCs i|_dS)N)_should_delete)selfrrr__init__5sz"TempDirectoryTypeRegistry.__init__cCs||j|<dS)z[Indicate whether a TempDirectory of the given kind should be auto-deleted. N)r)rkindvaluerrr set_delete9sz$TempDirectoryTypeRegistry.set_deletecCs|jj|dS)z^Get configured auto-delete flag for a given TempDirectory type, default True. T)rget)rrrrr get_delete@sz$TempDirectoryTypeRegistry.get_deleteN)__name__ __module__ __qualname____doc__rr r"rrrrr1src cs t}taz tVWd|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|j|tkr(|dk r$d}nd}|dkr:|j|}||_d|_||_||_|rlt dk sbt t j |dS)NF) superrr_default_create_path_deleteddeleterrAssertionError enter_context)rpathr1rglobally_managed) __class__rrrvs  zTempDirectory.__init__cCs|j stdj|j|jS)Nz$Attempted to access deleted path: {})r0r2formatr/)rrrrr4s zTempDirectory.pathcCsdj|jj|jS)Nz <{} {!r}>)r7r6r#r4)rrrr__repr__szTempDirectory.__repr__cCs|S)Nr)rrrr __enter__szTempDirectory.__enter__cCs8|jdk r|j}ntr$tj|j}nd}|r4|jdS)NT)r1r'r"rcleanup)rexcrtbr1rrr__exit__s zTempDirectory.__exit__cCs*tjjtjdj|d}tjd||S)zECreate a temporary directory and store its path in self.path zpip-{}-)prefixzCreated temporary directory: %s)osr4realpathtempfilemkdtempr7loggerdebug)rrr4rrrr.s zTempDirectory._createcCs&d|_tjj|jr"tt|jdS)z?Remove the temporary directory created and reset state TN)r0r?r4existsr/rr)rrrrr:szTempDirectory.cleanup)r#r$r%r&r-rpropertyr4r8r9r=r.r: __classcell__rr)r6rras  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"|jd|_tt|j|ddS)Nz/\)r1)rstriporiginalr,rHr)rrJr1)r6rrrs zAdjacentTempDirectory.__init__ccsxZtdt|D]H}xBtj|j|dD],}ddj|||d}||kr(|Vq(WqWxNtt|jD]<}x6tj|j|D]$}ddj||}||kr|VqWqlWdS)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_namescCstjj|j\}}x|j|D]`}tjj||}ytj|Wn0tk rn}z|jtj kr^WYdd}~XqXtjj |}PqWtjj t j dj |d}tjd||S)Nzpip-{}-)r>zCreated temporary directory: %s)r?r4splitrJrYrSmkdirOSErrorerrnoEEXISTr@rArBr7rCrD)rrrootrUrWr4exrrrr.s   zAdjacentTempDirectory._create)N) r#r$r%r&rRr classmethodrYr.rGrr)r6rrHs   rH)) __future__rr]rPloggingos.pathr?rA contextlibrpip._vendor.contextlib2rZpip._vendor.sixrpip._internal.utils.miscrrpip._internal.utils.typingrtypingr r r r r rr getLoggerr#rC tempdir_kindsrrobjectrr'r)r*r-rrHrrrrs6          i