B Re @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 dVWd|aXWdQRXdS)N)r_tempdir_manager)stackold_tempdir_managerr/builddir/build/BUILDROOT/alt-python37-pip-20.2.4-6.el8.x86_64/opt/alt/python37/lib/python3.7/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|j|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#rrrrr1srccs 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||tkr(|dk r$d}nd}|dkr:||}||_d|_||_||_|rlt dk sbt t |dS)NF) superrr_default_create_path_deleteddeleterrAssertionError enter_context)rpathr2rglobally_managed) __class__rrrvs  zTempDirectory.__init__cCs|jrtd|j|jS)Nz$Attempted to access deleted path: {})r1r3formatr0)rrrrr5szTempDirectory.pathcCsd|jj|jS)Nz <{} {!r}>)r8r7r$r5)rrrr__repr__szTempDirectory.__repr__cCs|S)Nr)rrrr __enter__szTempDirectory.__enter__cCs8|jdk r|j}ntr$t|j}nd}|r4|dS)NT)r2r(r#rcleanup)rexcr tbr2rrr__exit__s zTempDirectory.__exit__cCs*tjtjd|d}td||S)zECreate a temporary directory and store its path in self.path zpip-{}-)prefixzCreated temporary directory: %s)osr5realpathtempfilemkdtempr8loggerdebug)rrr5rrrr/s zTempDirectory._createcCs&d|_tj|jr"tt|jdS)z?Remove the temporary directory created and reset state TN)r1r@r5existsr0rr)rrrrr;szTempDirectory.cleanup)r$r%r&r'r.rpropertyr5r9r:r>r/r; __classcell__rr)r7rras  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/\)r2)rstriporiginalr-rIr)rrKr2)r7rrrs zAdjacentTempDirectory.__init__ccsxZtdt|D]H}xBt|j|dD],}dd|||d}||kr(|Vq(WqWxNtt|jD]<}x6t|j|D]$}dd||}||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_namesc Cstj|j\}}x||D]`}tj||}yt|Wn0tk rn}z|jtj kr^Wdd}~XYqXtj |}PqWtj t j d |d}td||S)Nzpip-{}-)r?zCreated temporary directory: %s)r@r5splitrKrZrTmkdirOSErrorerrnoEEXISTrArBrCr8rDrE)rrrootrVrXr5exrrrr/s   zAdjacentTempDirectory._create)N) r$r%r&r'rSr classmethodrZr/rHrr)r7rrIs   rI)) __future__rr^rQloggingos.pathr@rB contextlibrpip._vendor.contextlib2rZpip._vendor.sixrpip._internal.utils.miscrrpip._internal.utils.typingrtypingr r r r r rr getLoggerr$rD tempdir_kindsrrobjectrr(r*r+r.rrIrrrrs6          i