a [f@sUddlZddlZddlZddlZddlZddlmZmZddl m Z m Z m Z m Z mZmZddlmZmZeeZedddZedd d d Zdae eed <ee dd ddZGdddZdae eed<ee ed ddZGdddZeZGdddZ Gddde Z!dS)N) ExitStackcontextmanager)AnyDictIteratorOptionalTypeVarUnion)enumrmtree_T TempDirectory)boundz build-envzephem-wheel-cachez req-build)Z BUILD_ENVZEPHEM_WHEEL_CACHEZ REQ_BUILD_tempdir_managerreturnccsJt0}t|}azdVW|an|a0Wdn1s<0YdSN)rr)stackZold_tempdir_managerr@/usr/lib/python3.9/site-packages/pip/_internal/utils/temp_dir.pyglobal_tempdir_managers  rc@s@eZdZdZddddZeeddddZeed d d ZdS) TempDirectoryTypeRegistryzManages temp directory behaviorNrcCs i|_dSr_should_deleteselfrrr__init__*sz"TempDirectoryTypeRegistry.__init__)kindvaluercCs||j|<dS)z[Indicate whether a TempDirectory of the given kind should be auto-deleted. Nr)rrrrrr set_delete-sz$TempDirectoryTypeRegistry.set_deleterrcCs|j|dS)z^Get configured auto-delete flag for a given TempDirectory type, default True. T)rget)rrrrr get_delete3sz$TempDirectoryTypeRegistry.get_delete) __name__ __module__ __qualname____doc__rstrboolrr"rrrrr'sr_tempdir_registryccs$t}taztVW|an|a0dS)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+cseZdZdZdeddfeeeede feedfdd Z e edd d Z edd d Z eed ddZeeeddddZeedddZddddZZS)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. NZtempF)pathdeleterglobally_managedcslt|tur$|dur d}nd}|dur6||}||_d|_||_||_|rhtdus^Jt |dS)NF) superr_default_create_path_deletedr-rr enter_context)rr,r-rr. __class__rrrgs   zTempDirectory.__init__rcCs|jrJd|j|jS)Nz"Attempted to access deleted path: )r3r2rrrrr,szTempDirectory.pathcCsd|jjd|jdS)N< >)r6r#r,rrrr__repr__szTempDirectory.__repr__)rrcCs|Srrrrrr __enter__szTempDirectory.__enter__)excrtbrcCs8|jdur|j}ntr$t|j}nd}|r4|dS)NT)r-r)r"rcleanup)rr<rr=r-rrr__exit__s zTempDirectory.__exit__r cCs,tjtjd|dd}td||S)zszTempDirectory.cleanup)r#r$r%r&r0rr'r r(r+rpropertyr,r:r r;rr?r1r> __classcell__rrr5rr Rs$ !  cs\eZdZdZdZd eeeddfdd Ze ee eddd Z eed d d Z 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-~.=%0123456789N)originalr-rcs|d|_tj|ddS)Nz/\)r-)rstriprOr/r)rrOr-r5rrrs zAdjacentTempDirectory.__init__)namerccstdt|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)clsrQi candidatenew_namerrr_generate_namess   z%AdjacentTempDirectory._generate_namesr c Cstj|j\}}||D]d}tj||}zt|Wn2tyn}z|jtj krZWYd}~qd}~00tj |}qqtj t j d|dd}t d||S)Nr@rArBrD)rEr,splitrOr_rZmkdirOSErrorerrnoZEEXISTrFrGrHrIrJ)rrrootrQr]r,exrrrr1s   zAdjacentTempDirectory._create)N)r#r$r%r&rYr'rr(r classmethodrr_r1rMrrr5rrNs rN)"rcrWZloggingZos.pathrErG contextlibrrtypingrrrrrr Zpip._internal.utils.miscr r Z getLoggerr#rIr Z tempdir_kindsr__annotations__rrr)r*r+r0r rNrrrrs2      ^