o Ec@sUddlZddlZddlZddlZddlZddlmZmZddl m Z m Z m Z m Z mZmZddlmZmZeeZedddZedd d d Zdae eed <ed e dfddZGdddZdae eed<ed e efddZGdddZeZGdddZ Gddde Z!dS)N) ExitStackcontextmanager)AnyDictIteratorOptionalTypeVarUnion)enumrmtree_T TempDirectory)Zboundz build-envzephem-wheel-cachez req-build)Z BUILD_ENVZEPHEM_WHEEL_CACHEZ REQ_BUILD_tempdir_managerreturnccsNt}t|}azdVW|an|awWddS1s wYdSN)rr)stackZold_tempdir_managerrO/opt/alt/python310/lib/python3.10/site-packages/pip/_internal/utils/temp_dir.pyglobal_tempdir_managers "rc@sBeZdZdZd ddZdededdfdd Zdedefd d ZdS) TempDirectoryTypeRegistryzManages temp directory behaviorrNcCs i|_dSr_should_deleteselfrrr__init__*s z"TempDirectoryTypeRegistry.__init__kindvaluecCs||j|<dS)z[Indicate whether a TempDirectory of the given kind should be auto-deleted. Nr)rrrrrr set_delete-z$TempDirectoryTypeRegistry.set_deletecCs|j|dS)z^Get configured auto-delete flag for a given TempDirectory type, default True. T)rget)rrrrr get_delete3rz$TempDirectoryTypeRegistry.get_deleterN) __name__ __module__ __qualname____doc__rstrboolrr rrrrr's  r_tempdir_registryccs$t}taztVW|adS|aw)zuProvides a scoped global tempdir registry that can be used to dictate whether directories should be deleted. N)r(r)Zold_tempdir_registryrrrtempdir_registry=s r)c@s eZdZdS)_DefaultN)r"r#r$rrrrr*Ksr*c seZdZdZdeddfdeedeede fdedeffd d Z e d efd d Z d efddZ ded efddZdededed dfddZded efddZdddZZS)r aMHelper 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. NZtempFpathdeleterglobally_managedcspt|tur|durd}nd}|dur||}||_d|_||_||_|r6tdus/Jt |dSdS)NF) superr_default_create_path_deletedr,rr enter_context)rr+r,rr- __class__rrrgs   zTempDirectory.__init__rcCs|jr Jd|j|jS)Nz"Attempted to access deleted path: )r2r1rrrrr+szTempDirectory.pathcCsd|jjd|jdS)N< >)r5r"r+rrrr__repr__szTempDirectory.__repr__rcCs|Srrrrrr __enter__szTempDirectory.__enter__excrtbcCs<|jdur |j}n trt|j}nd}|r|dSdS)NT)r,r(r rcleanup)rr;rr<r,rrr__exit__s  zTempDirectory.__exit__cCs,tjtjd|dd}td||S)zr0r= __classcell__rrr4rr Rs, !  csdeZdZdZdZddedeeddffdd Ze d ede efd d Z d edefd dZ Z 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-~.=%0123456789Noriginalr,rcs|d|_tj|ddS)Nz/\)r,)rstriprNr.r)rrNr,r4rrrs zAdjacentTempDirectory.__init__nameccstdt|D]"}t|j|dD]}dd|||d}||kr)|Vqqtt|jD]}t|j|D]}dd||}||krM|Vq;q2dS)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)clsrPi candidatenew_namerrr_generate_namess(  z%AdjacentTempDirectory._generate_namesrc Cstj|j\}}||D]1}tj||}zt|Wnty7}z |jtj kr-WYd}~qd}~wwtj |}ntj t j d|dd}t d||S)Nr?r@rArC)rDr+splitrNr^rYmkdirOSErrorerrnoZEEXISTrErFrGrHrI)rrrootrPr\r+Zexrrrr0s     zAdjacentTempDirectory._creater)r"r#r$r%rXr&rr'r classmethodrr^r0rLrrr4rrMs rM)"rbrVZloggingZos.pathrDrF contextlibrrtypingrrrrrr Zpip._internal.utils.miscr r Z getLoggerr"rHr Z tempdir_kindsr__annotations__rrr(r)r*r/r rMrrrrs4      ^