
    si?                    X   S r SSKJr  SSKrSSKrSSKrSSKJrJr  SSK	J
r
  SSKJrJrJrJrJr  SSKJr  SSKJr  SS	KJr  S
SKJr  S
SKJr  S
SKJrJr  S
SKJrJ r   S
SK!J"r"  S
SK#J$r$  \(       a  SSK%J&r&  \RN                  " \(5      r)\$" SSSS9S'S j5       r*\$RV                  " SSS\*5        C*S r,\"=r-r.\S 5       r/S r0\ (       a(  \Rb                  " S5      r2\Rb                  " S5      r3S r4OSSK5Jr4  \$" SS 5      S(S! j5       r6\$Rn                  " SS S"S#S9  S)S$ j5       r8S% r9S& r:g)*zUtility functions.    )annotationsN)cachewraps)environ)abspathbasenamedirnameisfilejoin)Path)which)TYPE_CHECKING   )
CondaError)_build_activator_cls)Utf8NamedTemporaryFileshlex_split_unicode)
isiterableon_win)path_to_url)
deprecated)Sequencez25.3z26.3z1Use `conda.common.path.unix_path_to_win` instead.)addendumc                  ^ [        U 5      S:  a6  SU ;   d  U S   S:X  a'  U R                  S5      S:X  a  U R                  SS5      $ TS-   nU4S jn[        R                  " X#U 5      n[        R                  " SS	 U5      nU$ )
zConvert a path or :-separated string of paths into a Windows representation
Does not add cygdrive.  If you need that, set root_prefix to "/cygdrive"
r   ;:/\z$(/[a-zA-Z]/(?:(?![:\s]/)[^:*?"<>])*)c                   > U R                  S5      nSR                  U[        T5      S-      U[        T5      S-   S  R                  SS5      5      $ )Nr   z{}:{}r      r   r   )groupformatlenreplace)
found_pathr!   root_prefixs     +lib/python3.13/site-packages/conda/utils.py_translation&unix_path_to_win.<locals>._translation,   sX      #~~#k"Q&'#k"Q&()11#t<
 	
    z:([a-zA-Z]):\\c                6    SU R                  S5      S   -   S-   $ )Nr   r   r   z:\)r!   )matchs    r'   <lambda>"unix_path_to_win.<locals>.<lambda>5   s    #Aq0A*AE*Ir*   )r#   countr$   resub)pathr&   path_rer(   translations    `   r'   unix_path_to_winr5      s     4y1}#+$q'S.TZZ_PQ=Q||C&&CCG
 &&5K&&I;K r*   r5   c                    U S:  a  SU -  $ U S-  nUS:  a  S[        U5      -  $ US-  nUS:  a  US S3$ US-  nUS S3$ )a;  
Return the number of bytes n in more human readable form.

Note: Uses SI prefixes (KB, MB, GB) instead of binary prefixes (KiB, MiB, GiB).

Examples:
    >>> human_bytes(42)
    '42 B'
    >>> human_bytes(1042)
    '1 KB'
    >>> human_bytes(10004242)
    '9.5 MB'
    >>> human_bytes(100000004242)
    '93.13 GB'
i   z%d Bz%d KBz.1fz MBz.2fz GB)round)nkmgs       r'   human_bytesr<   >   si      	4xz	DA4xq!!	DA4xC}	DAWC=r*   c                 j    [        [        [        R                  " 5       R	                  5       5      5      n U R
                  (       a  U R
                  n U R
                  (       a  M  U R                  nUR                  n[        [        U5      5      nU$ ! [         a    [        R                  s $ f = f)az  Since conda is installed into non-root environments as a symlink only
and because sys.prefix follows symlinks, this function can be used to
get the 'unfollowed' sys.prefix.

This value is usually the same as the prefix of the environment into
which conda has been symlinked. An example of when this is necessary
is when conda looks for external sub-commands in find_commands.py
)nextitersys_current_framesvaluesf_backf_codeco_filenamer	   	Exceptionprefix)framecodefilename
unfolloweds       r'   sys_prefix_unfollowedrL   a   s    T#--/6689:llLLE lll||##WX./
   zzs   A#B ',B B21B2c                 f    [        U 5      S:X  a  [        U S   5      (       a  U S   n [        U 5      $ )a  Properly quote arguments for command line passing.

For POSIX uses `shlex.join`, for Windows uses a custom implementation to properly escape
metacharacters.

:param arguments: Arguments to quote.
:type arguments: list of str
:return: Quoted arguments.
:rtype: str
r   r   )r#   r   
_args_join)	argumentss    r'   quote_for_shellrP   w   s2     9~z)A,77aL	i  r*   z["%\s^<>&|]z(["%])c                @   ^ S mSR                  U4S jU  5       5      $ )z*Return a shell-escaped string from *args*.c                    U (       d  g[         R                  U 5      (       d  U $ [        R                  SU 5      n SU  S3$ )Nz""z\1\1")
_RE_UNSAFEsearch_RE_DBLr1   )ss    r'   quote_args_join.<locals>.quote   s;    $$Q''GQ'Aqc8Or*    c              3  4   >#    U  H  nT" U5      v   M     g 7fN ).0argrX   s     r'   	<genexpr>_args_join.<locals>.<genexpr>   s     3dsc

ds   r   )argsrX   s    @r'   rN   rN      s    
	 xx3d333r*   rb   z26.9z27.3c                   [        U [        5      (       a1  US:X  a  [        S5      e[        U 5      n [        R                  S5        [        U 5      (       d  U 4n [        S U  5       5      (       a  [        S5      e[        U 5      n U $ )Nassertz'Please ensure arguments are not stringszKPlease ensure arguments is not a string; used `shlex_split_unicode()` on itc              3  8   #    U  H  n[        U5      v   M     g 7fr\   )r   r^   r_   s     r'   r`   $massage_arguments.<locals>.<genexpr>   s     
0is:c??is   z)Individual arguments must not be iterable)

isinstancestrRuntimeErrorr   logwarningr   any
ValueErrorlist)rO   errorss     r'   massage_argumentsrr      s     )S!!XHII+I6IKK5
 i  L	

0i
000DEEYIr*   use_system_tmp_pathzbUse the TMPDIR, TEMP, or TMP environment variables to set the system temporary directory location.c           
        [        U5      (       d  [        S5      e[        [        [        U5      5      nS nSn[        U5      S:X  a  SUS   ;   a  Sn[        (       Ga.  [        5       n[        SSSS	9 nU(       a  S
OSn	UR                  U	 S35        UR                  U	 S35        UR                  U	 S35        UR                  U	 S35        UR                  U	 S35        U(       a~  SSK
Jn
  UR                  U	 S35        UR                  U	 SU
 S35        UR                  U	 S[        R                   S35        UR                  U	 S35        UR                  U	 S35        U(       a"  UR                  S5        UR                  S5        [        S5      nS/nU(       a  UR                  S5        UR                  U5        U" U5      nUR!                  5         UR#                  5       nUR%                  5        H  nUR                  U	 U S35        M     UR                  U	 S35        U(       a"  UR                  S5        UR                  S5        U(       a  UR                  US    S35        O>['        S U 5       5      (       a  [)        S5      eUR                  U	 [+        U6  S35        UR                  U	 S 35        [-        U5      S!-  S"-  S#-  nUR/                  5       (       aR  [1        UR3                  S$5      S% SS&9nU H1  nUR5                  5       (       d  M  UR                  U	 S'U S(35        M3     UR                  U	 S)35        UR                  U	 S*35        UR6                  nS S S 5        US+S,U/nUU4$ [9        S-5      =(       d    [9        S.5      nUc  [;        S/5      eU(       a  [=        [?        U S0S15      5      S2S"/nSnU/nO0[@        RB                  " S3[=        [?        U S0S"5      5      5      /nS
n/ n[        SSS49 nUR                  S55        U(       a  SSK
Jn
  UR                  S6U
-   S-   5        [+        / UQS7PS8PUQ76 nU(       a&  UR                  S95        UR                  S:U S;35        UR                  S<U S;35        [        S=5      nS/nU(       a  UR                  S5        UR                  U5        U" U5      nUR!                  5         UR#                  5       nUR                  U5        U(       a  UR                  S>5        UR                  S?5        U(       a0  UR                  S@RE                  SAR?                  U5      5      5        OUR                  [+        U6  S35        UR                  SB5        [-        U5      S!-  S"-  S#-  nUR/                  5       (       aP  [1        UR3                  SC5      SD SS&9nU H/  nUR5                  5       (       d  M  UR                  SEU S(35        M1     UR                  SF5        UR6                  nS S S 5        U(       a	  USGU/nUU4$ UU/nUU4$ ! , (       d  f       GN= f! , (       d  f       N8= f)HNz`arguments` must be iterableFr   
r   Twz.bat)modesuffixdelete @z	ECHO OFF
zSET PYTHONIOENCODING=utf-8
zSET PYTHONUTF8=1
z]FOR /F "tokens=2 delims=:." %%A in ('chcp') do for %%B in (%%A) do set "_CONDA_OLD_CHCP=%%B"
zchcp 65001 > NUL
)CONDA_SOURCE_ROOTzSET CONDA_DEV=1
zSET PYTHONPATH=zSET CONDA_EXE=zSET _CE_M=-m
zSET _CE_CONDA=conda
z%echo *** environment before *** 1>&2
z	SET 1>&2
zcmd.exe.runactivatez--devz+IF %ERRORLEVEL% NEQ 0 EXIT /b %ERRORLEVEL%
z$echo *** environment after *** 1>&2
c              3  ,   #    U  H
  nS U;   v   M     g7f)ru   Nr]   rg   s     r'   r`   'wrap_subprocess_call.<locals>.<genexpr>  s     8ists{is   aW  Support for scripts where arguments contain newlines not implemented.
.. requires writing the script to an external file and knowing how to transform the command-line (e.g. `python -c args` => `python file`) in a tool dependent way, or attempting something like:
.. https://stackoverflow.com/a/15032476 (adds unacceptable escapingrequirements)z!SET "_CONDA_EXE_RC=%ERRORLEVEL%"
etccondazdeactivate.dz*.batc                    U R                   $ r\   nameps    r'   r-   &wrap_subprocess_call.<locals>.<lambda>(      !&&r*   )keyreversezCALL "z"
zchcp %_CONDA_OLD_CHCP%>NUL
zEXIT /B %_CONDA_EXE_RC%
z/dz/cbashshzNo compatible shell found!binpythonz-m	CONDA_EXE)rw   ry   zset -e
z>&2 export PYTHONPATH=zshell.posixhookz.>&2 echo '*** environment before ***'
>&2 env
z>&2 echo "$(z)"
zeval "$(posixz->&2 echo '*** environment after ***'
>&2 env
zset +e
z{}
rZ   z_CONDA_EXE_RC=$?
z*.shc                    U R                   $ r\   r   r   s    r'   r-   r   u  r   r*   z. "zexit $_CONDA_EXE_RC
z-x)#r   	TypeErrortuplemaprj   r#   r   get_comspecr   writerz   r|   r@   
executabler   append_parse_and_set_argsr}   
splitlinesrn   NotImplementedErrorrP   r   is_dirsortedglobis_filer   r   rF   r   r   r   getr"   )r&   rG   dev_modedebug_wrapper_scriptsrO   script_caller	multilinecomspecfhsilencerr|   activator_clsactivator_args	activatoractivate_scriptlinedeactivate_ddeactivate_scriptsscriptcommand_args
shell_path	conda_exedev_argdev_argshook_quotedactivate_codes                             r'   wrap_subprocess_callr      s%    i  677c#y)*IMI
9~ty|3	v-#VEJb2rHHHz,-HHz!=>?HHz!345HH*|} HHz!345/H:%678 H:_5F4GrJKH:^CNN3C2FGH:^45H:%:;<$AB& 1?M(\N%%g.!!&)%n5I))+'002O'224H:dV2./ 5 HHz!MNO$@A& IaL>,-8i888-(  H:oy&A%B"EF HHz!CDE<%/'9NJL""$$%+ %%g.( &"
 1F~~''H:VF83!?@ 1 HHz!=>? HHz!:;<GGMc Kd  t];` ,&&] 6]1eDk
899
  k5(!CDdGTIGyH Kk5'1R)STI GH#U;r HHZ /14EELM)W9WmWVWhWK$KL<}D9:HHx}D12 19M(\N%%g.!!&)%n5I))+%..0MHH]#$JKHHZ  sxx	':;<OY78;< HH)*<%/'9NJL""$$%+ %%f-( &"
 1F~~''3vhc!23 1
 HH,-GGMo <p !&m<L ,&& '6L,&&E KJJ <;s'   4J4Y,AYG Y$<6Y$
Y!$
Y2c                    [        [        R                  " SS5      5      R                  5       S:w  a  [        R                  " S5      =(       a    [	        [        S   SS5      [        R                  " S5      =(       a    [	        [        S   SS5      4 H/  n U (       d  M  [        U 5      (       d  M  U [        S'     [        S   $    [        R                  S5        [        S   $ )zReturns COMSPEC from envvars.

Ensures COMSPEC envvar is set to cmd.exe, if not attempt to find it.

:raises KeyError: COMSPEC is undefined and cannot be found.
:returns: COMSPEC value.
:rtype: str
COMSPECrz   zcmd.exe
SystemRootSystem32windirzFcmd.exe could not be found. Looked in SystemRoot and windir env vars.
)r   r   r   lowerr   r
   rl   rm   )r   s    r'   r   r     s     Ir*+113y@ KK% CW\*J	BKK!Td78+<j)&T
G w6'??%,	" 9!
 KKY
 9r*   c                0   ^  [        T 5      U 4S j5       nU$ )z`
Ensures that the directory exists for functions returning
a Path object containing a directory
c                    > T" U 0 UD6n[        U[        5      (       a   UR                  SSS9  U$ U$ ! [         a  n[	        SU SU 35      eS nAff = f)NT)parentsexist_okzKError encountered while attempting to create cache directory.
  Directory: z
  Exception: )ri   r   mkdirOSErrorr   )rc   kwargsresultexcfuncs       r'   wrapper"ensure_dir_exists.<locals>.wrapper  st    t&v&fd##TD9 v   &&,X%cU, s   4 
AAA)r   )r   r   s   ` r'   ensure_dir_existsr     s"     4[  Nr*   )rz   )re   )rO   zSequence[str]);__doc__
__future__r   loggingr0   r@   	functoolsr   r   osr   os.pathr   r   r	   r
   r   pathlibr   shutilr   typingr   rz   r   r}   r   auxlib.compatr   r   common.compatr   r   
common.urlr   deprecationsr   collections.abcr   	getLogger__name__rl   r5   constantr<   urlpathurl_pathrL   rP   compilerT   rV   rN   shlexrr   argumentr   r   r   r]   r*   r'   <module>r      sG    "  	 
 "  < <      * F - # $(! 

@

.   FF$68H I@ !  (  *!$ 
 N+Jjj#G4$ ) FF @ 

q	u'
 u'u'p:r*   