
    $TXgD                        d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZ d
dlmZmZmZ erd
dlmZmZ  e	e      Zd Zd Zd Z	 d	 	 	 	 	 	 	 	 	 ddZ	 ddd	 	 	 	 	 	 	 ddZ	 ddd	 	 	 	 	 	 	 ddZ y)zCommon Windows path utilities.    )annotationsN)	getLogger)Path)which)TYPE_CHECKING   )on_win   )nt_to_posixposix_to_ntresolve_paths)	PathsTypePathTypec                6    t         r| j                  dd      S | S )N/\r	   replacepaths    9lib/python3.12/site-packages/conda/common/path/windows.pywin_path_okr      s    &,4<<T"6$6    c                6    t         r| j                  dd      S | S )Nr   z\\r   r   s    r   win_path_double_escaper      s    )/4<<f%9T9r   c                P    t        j                  dd|       j                  dd      S )Nz	(\\(?! ))r   z:////z://)resubr   r   s    r   win_path_backoutr   "   s$     66,d+33GUCCr   c          	        | y t        | t        t        j                  f      r| n
t	        |       } | s$t        | t        t        j                  f      rdS dS t
        r|ddlm} |j                  }|r9t        j                  }d}t        }t        j                  }t        j                  }	n8t        j                  }d}t        }t        j                  }t        j                  }	t        d      }
|
r!t        t!        |
      j"                  dz        nd}t        | t        t        j                  f      rt        |       n|j%                  t'        t        |             }d }	 t)        j*                  ||d	|gd
d
d
      j,                  j/                         }t1        |||	      }|
 ||||      }t        | t        t        j                  f      r|S |syt	        |jE                  |            S # t2        $ r t4        j7                  d       Y kt(        j8                  $ rg}t4        j;                  d|j<                  j>                  ||j,                  j/                         |j@                  j/                                Y d }~d }~wtB        $ r6}t4        j;                  d|j<                  j>                  |       Y d }~d }~ww xY w)N.    )contextz--unixz	--windowsbashcygpathz--pathT)textcapture_outputcheckz<cygpath is not available, fallback to manual path conversionz_Unexpected cygpath error, fallback to manual path conversion
  %s: %s
  stdout: %s
  stderr: %szEUnexpected cygpath error, fallback to manual path conversion
  %s: %s)#
isinstancestrosPathLiketupler	   base.contextr$   target_prefixntpathpathsepr   	posixpathsepr   r   r   parentjoinmap
subprocessrunstdoutstripr   FileNotFoundErrorlogwarningCalledProcessErrorerror	__class____name__stderr	Exceptionsplit)pathsprefixcygdriveto_unixr$   from_pathsepcygpath_argcygpath_fallback
to_pathsepto_sepr%   r&   joined	convertederrs                  r   _path_torR   )   sJ    }  R[['9:EeE bkk(:;sCC&.+&&~~&&&
 ((!&^^
 =D48c$t*##i/0iG ec2;;/0 	E
s3/  !IANNk8V4	

 & 	6 ")Z@	$VVX>	%#r{{+,Y__Z011?  TRS(( 
		pMM""JJJJ	
 	
  
		TMM""	
 	

s+   !5G. .KK AJK+J??KF)rH   c                    t        | ||d      S )a}  Convert Windows paths to Unix paths.

    .. note::
        Produces unexpected results when run on Unix.

    Args:
        paths: The path(s) to convert.
        prefix: The (Windows path-style) prefix directory to use for the conversion.
              If not provided, no checks for prefix paths will be made.
        cygdrive: Whether to use the Cygwin-style drive prefix.
    T)rG   rH   rI   rR   rF   rG   rH   s      r   win_path_to_unixrV      s    " E&8TJJr   c                    t        | ||d      S )a  Convert Unix paths to Windows paths.

    .. note::
        Produces unexpected results when run on Unix.

    Args:
        paths: The path(s) to convert.
        prefix: The (Windows path-style) prefix directory to use for the conversion.
              If not provided, no checks for prefix paths will be made.
        cygdrive: Unused. Present to keep the signature consistent with `win_path_to_unix`.
    F)rH   rI   rT   rU   s      r   unix_path_to_winrX      s    " E6HeDDr   )N)
rF   PathType | PathsType | NonerG   PathType | NonerH   boolrI   r[   returnstr | tuple[str, ...] | None)rF   rY   rG   rZ   rH   r[   r\   r]   )!__doc__
__future__r   r1   r,   r3   r   r8   loggingr   pathlibr   shutilr   typingr   compatr	   _cygpathr   r   r    r   r   rB   r=   r   r   r   rR   rV   rX   r"   r   r   <module>rg      s   % "  	  	        = =%7:D #X2&X2X2 	X2
 X2 "X2z #K 	K&KK 	K
 "K, #E 	E&EE 	E
 "Er   