
    RhVE                     f   d Z dZdZdZdZdZdZdZdZddl	Z	ddl
Z
ddlZddlZdd	l g d
Zd Zd Zd Zd Zd Zd Zej(                  j                   e_         d Zd Zd Zd Zd Zd Zd Zd Zdadad Z	 ddl m!Z! d Z"d Z$ddd Z%d! Z&e
jN                  d"k(  Z(d%d#Z)d$ Z*y# e#$ r d Z"Y -w xY w)&a  Common operations on Posix pathnames.

Instead of importing this module directly, import os and refer to
this module as os.path.  The "os.path" name is an alias for this
module on Posix systems; on other systems (e.g. Windows),
os.path provides the same operations in a manner specific to that
platform, and is an alias to another module (e.g. ntpath).

Some of this can actually be useful on non-Posix systems too, e.g.
for manipulation of the pathname component of URLs.
.../:z/bin:/usr/binNz	/dev/null    )*))normcaseisabsjoin
splitdrive	splitrootsplitsplitextbasenamedirnamecommonprefixgetsizegetmtimegetatimegetctimeislinkexistslexistsisdirisfileismount
expanduser
expandvarsnormpathabspathsamefilesameopenfilesamestatcurdirpardirseppathsepdefpathaltsepextsepdevnullrealpathsupports_unicode_filenamesrelpath
commonpath
isjunctionALLOW_MISSINGc                 &    t        | t              ryy)N   /r   )
isinstancebytespaths     /usr/lib/python3.12/posixpath.py_get_sepr8   )   s    $    c                 ,    t        j                  |       S )z6Normalize case of pathname.  Has no effect under Posixosfspath)ss    r7   r   r   4   s    99Q<r9   c                 d    t        j                  |       } t        |       }| j                  |      S )zTest whether a path is absolute)r<   r=   r8   
startswith)r>   r%   s     r7   r	   r	   <   s'    
		!A
1+C<<r9   c                 j   t        j                  |       } t        |       }| }	 |s|dd |z    t        t         j                  |      D ]7  }|j	                  |      r|}|r|j                  |      r||z  }0|||z   z  }9 	 |S # t        t        t        f$ r t        j                  d| g|   w xY w)zJoin two or more pathname components, inserting '/' as needed.
    If any component is an absolute path, all previous path components
    will be discarded.  An empty last part will result in a path that
    ends with a separator.Nr   r
   )r<   r=   r8   mapr@   endswith	TypeErrorAttributeErrorBytesWarninggenericpath_check_arg_types)apr%   r6   bs        r7   r
   r
   G   s    
 			!A
1+CD!HsNRYY" 	 A||C T]]3/	a	  K ~|4 $$VQ33s   AB -B2c                     t        j                  |       } t        |       }| j                  |      dz   }| d| | |d }}|r"||t	        |      z  k7  r|j                  |      }||fS )zSplit a pathname.  Returns tuple "(head, tail)" where "tail" is
    everything after the final slash.  Either part may be empty.   Nr<   r=   r8   rfindlenrstrip)rJ   r%   iheadtails        r7   r   r   d   sk     			!A
1+C	qA2A!"$DCI%{{3:r9   c                     t        j                  |       } t        | t              rd}d}nd}d}t	        j
                  | |d |      S )Nr2      .r   r   )r<   r=   r3   r4   rG   	_splitext)rJ   r%   r)   s      r7   r   r   u   sD    
		!A!U  Cv66r9   c                 :    t        j                  |       } | dd | fS )zJSplit a pathname into drive and path. On Posix, drive is always
    empty.Nr   r;   )rJ   s    r7   r   r      s      			!ARa5!8Or9   c                     t        j                  |       } t        | t              rd}d}nd}d}| dd |k7  r||| fS | dd |k7  s| dd |k(  r||| dd fS || dd | dd fS )	a  Split a pathname into drive, root and tail. On Posix, drive is always
    empty; the root may be empty, a single slash, or two slashes. The tail
    contains anything after the root. For example:

        splitroot('foo/bar') == ('', '', 'foo/bar')
        splitroot('/foo/bar') == ('', '/', 'foo/bar')
        splitroot('//foo/bar') == ('', '//', 'foo/bar')
        splitroot('///foo/bar') == ('', '/', '//foo/bar')
    r2   r9   r    NrM         )r<   r=   r3   r4   )rJ   r%   emptys      r7   r   r      s     			!A!U!u|eQ	
1Q3!Aa&C-c1QR5   aeQqrU""r9   c                 t    t        j                  |       } t        |       }| j                  |      dz   }| |d S )z)Returns the final component of a pathnamerM   N)r<   r=   r8   rO   )rJ   r%   rR   s      r7   r   r      s5    
		!A
1+C	qAQR5Lr9   c                     t        j                  |       } t        |       }| j                  |      dz   }| d| }|r"||t	        |      z  k7  r|j                  |      }|S )z-Returns the directory component of a pathnamerM   NrN   )rJ   r%   rR   rS   s       r7   r   r      sZ    
		!A
1+C	qARa5DCI%{{3Kr9   c                 .    t        j                  |        y)zQTest whether a path is a junction
    Junctions are not a part of posix semanticsFr;   r5   s    r7   r/   r/      s     IIdOr9   c                 Z    	 t        j                  |        y# t        t        f$ r Y yw xY w)zCTest whether a path exists.  Returns True for broken symbolic linksFT)r<   lstatOSError
ValueErrorr5   s    r7   r   r      s0    
  Z  s    **c                    	 t        j                  |       }t        j                  |j                        ryt        j                  |       } t        | t              rt        | d      }nt        | d      }t        |      }	 t        j                  |      }|j                  }|j                  }||k7  ry|j                  }|j                  }||k(  ryy# t
        t        f$ r Y yw xY w# t
        t        f$ r Y yw xY w)z$Test whether a path is a mount pointF   ..r   T)r<   rb   statS_ISLNKst_moderc   rd   r=   r3   r4   r
   r+   st_devst_ino)r6   s1parents2dev1dev2ino1ino2s           r7   r   r      s    XXd^ <<

#99T?D$dE"dD!fFXXf 99D99Dt|99D99Dt|7 Z    Z  s#   C C( C%$C%(C:9C:c                 `   t        j                  |       } t        | t              rd}nd}| j	                  |      s| S t        |       }| j                  |d      }|dk  rt        |       }|dk(  rZdt         j                  vr4	 ddl	}	 |j                  t        j                               j                  }nXt         j                  d   }nD	 ddl	}| d| }t        |t              rt        |d      }	 |j!                  |      }|j                  }|t"        j$                  dk(  r| S t        | t              rt        j&                  |      }d	}nd
}|j)                  |      }|| |d z   xs |S # t        $ r | cY S w xY w# t        $ r | cY S w xY w# t        $ r | cY S w xY w# t        $ r | cY S w xY w)zOExpand ~ and ~user constructions.  If user or $HOME is unknown,
    do nothing.   ~~rM   r   HOMENASCIIvxworksr2   r   )r<   r=   r3   r4   r@   r8   findrP   environpwdImportErrorgetpwuidgetuidpw_dirKeyErrorstrgetpwnamsysplatformfsencoderQ   )	r6   tilder%   rR   r{   userhomenamepwentroots	            r7   r   r      s    99T?D$??5!
4.C		#qA1uIAv#<<		4;; zz&)H	 AaydE"tW%D	LL&E
 <<CLLI5$;;x(t$HtABx(D(I  
     	K	  	 K	sH   E, -E= F 1F ,E:9E:=F
FFFF-,F-c                 ,   t        j                  |       } t        | t              rRd| vr| S t        s ddl}|j                  d|j                        at        j                  }d}d}t        t         dd      }nPd| vr| S t        s ddl}|j                  d	|j                        a
t        j                  }d
}d}t         j                  }d}	  || |      }|s	 | S |j                  d      \  }}|j                  d      }	|	j                  |      r|	j                  |      r|	dd }		 |:t        j                   t         j                  t        j"                  |	               }
n||	   }
| |d }| d| |
z   } t%        |       }| |z  } # t&        $ r |}Y w xY w)zZExpand shell variables of form $var and ${var}.  Unknown variables
    are left unchanged.   $r   Ns   \$(\w+|\{[^}]*\})   {   }environb$z\$(\w+|\{[^}]*\}){}rM   )r<   r=   r3   r4   	_varprogbrecompilerw   searchgetattr_varprogrz   spangroupr@   rC   r   fsdecoderP   r   )r6   r   r   startendrz   rR   mjr   valuerT   s               r7   r   r   @  s    99T?D$tK

#8"((CI!!"j$/d?Kzz"6AH**	A
4O" K! vvay1wwqz??5!dmmC&8":D	BJJr{{4/@$AB 8D8e#DD	ADLD'   	A	s   &AF FF)_path_normpathc                     t        j                  |       } t        | t              r5t        j                  t        t        j                  |                   xs dS t        |       xs dS )0Normalize path, eliminating double slashes, etc.rV   r   )r<   r=   r3   r4   r   r   r   r5   s    r7   r   r     sK    yydE";;~bkk$.?@AITId#*s*r9   c                    t        j                  |       } t        | t              r	d}d}d}d}nd}d}d}d}| |k(  r|S t	        |       \  }}} | j                  |      }g }|D ]A  }	|	||fv r
|	|k7  s|s|r
|r|d	   |k(  r|j                  |	       /|s2|j                          C |}||j                  |      z   } | xs |S )
r   r2   r9   rV   rf   r   rZ   r   r   r   )	r<   r=   r3   r4   r   r   appendpopr
   )
r6   r%   r]   dotdotdot_initial_slashescomps	new_compscomps
             r7   r   r   y  s    yydE"CECFCECF5=J#,T? ?D

3	 	 Ds|#y	" 7  &	  %0{sr9   c                     t        j                  |       } t        |       sEt        | t              rt        j
                         }nt        j                         }t        ||       } t        |       S )zReturn an absolute path.)	r<   r=   r	   r3   r4   getcwdbgetcwdr
   r   )r6   cwds     r7   r   r     sK    99T?D;dE"**,C))+CCD>r9   F)strictc                j    t        j                  |       } t        | dd | |i       \  }}t        |      S )zlReturn the canonical path of the specified filename, eliminating any
symbolic links encountered in the path.Nr   )r<   r=   _joinrealpathr   )filenamer   r6   oks       r7   r+   r+     s6     yy"HXbq\8VR@HD"4=r9   c                    t        | t              rd}d}d}nd}d}d}t        j                  }|t        u rt
        }n|rd}nt        }d }	t        |      r|dd  }|} |r|j                  |      \  }
}}|
r|
|k(  r |
|k(  r&| r!t        |       \  } }
|
|k(  rt        | ||      } n|} Kt        | |
      }	 t        j                  |      }t        j                  |j                        }|s|} ||v r.||   } | |rt        j                  |       nt        ||      d	fS d ||<   t        | t        j                   |      ||      \  } }|st        | |      d	fS | ||<   |r| d
fS # |$ r d	}Y w xY w)Nr2   rV   rf   r   r   r    rM   FT)r3   r4   r<   r   r0   FileNotFoundErrorrc   r	   	partitionr   r
   rb   rg   rh   ri   r   readlink)r6   restr   seenr%   r#   r$   r   ignored_errormaxlinksr   r   newpathstis_linkr   s                   r7   r   r     s   $)	HT{ABx
s+atv~6>"4[
d6>ff5DtT"	/'"B ll2::.GDd?=D  GT*E11W r{{7';VTJbd#U**WU X :7  	G	s   4E% %E/.E/darwinc                 P   | st        d      t        j                  |       } t        | t              rd}d}d}nd}d}d}||}nt        j                  |      }	 t        |      j                  |      D cg c]  }|s|	 }}t        |       j                  |      D cg c]  }|s|	 }}t        t        ||g            }|gt        |      |z
  z  ||d z   }	|	s|S t        |	 S c c}w c c}w # t        t        t        t        f$ r t        j                  d	| |        w xY w)
z#Return a relative version of a pathzno path specifiedrV   r2   rf   r   r   r   Nr-   )rd   r<   r=   r3   r4   r   r   rP   r   r
   rD   rE   rF   DeprecationWarningrG   rH   )
r6   r   r#   r%   r$   x
start_list	path_listrR   rel_lists
             r7   r-   r-      s,    ,--99T?D$}		% !(!5!5c!:@Aaa@
@ ' 3 3C 8>1AQ>	>j)4568s:q01IabMAMX A> ~|5GH $$Ye<s<   C3 7C)?C)C3 !C.)C.-3C3 !C3 )
C3 32D%c           	         | st        d      t        t        t        j                  |             } t        | d   t              rdd}ndd}	 | D cg c]  }|j                         }}	 t        fd| D              \  }|D cg c]  }|D cg c]  }|s||k7  s| c} }}}t        |      }t        |      }|}	t        |      D ]  \  }
}|||
   k7  s|d	|
 }	 n |rnd	d }|j                  |	      z   S c c}w # t         $ r t        d      d	w xY wc c}w c c}}w # t        t        f$ r t        j                   d
g|    w xY w)zDGiven a sequence of path names, returns the longest common sub-path.z%commonpath() arg is an empty sequencer   r2   rV   r   r   c              3   .   K   | ]  }|d d k(    y w)NrM   r   ).0rJ   r%   s     r7   	<genexpr>zcommonpath.<locals>.<genexpr>;  s     5!2A#5s   z%Can't mix absolute and relative pathsNr.   )rd   tuplerB   r<   r=   r3   r4   r   setminmax	enumerater
   rD   rE   rG   rH   )pathsr#   r6   split_pathsr	   r>   crl   rn   commonrR   prefixr%   s               @r7   r.   r.   )  st    @AA#bii'(E%(E"3894tzz#99	P5u55FE EPPq1:aa6k:PPbM 	DAqBqEzBQ	
 3r7(((# :  	PDE4O	P ;P ~& $$\:E:sl   D, D+D, .D D, 		D&D!D! D!$D&)4D, $D, D, DD, !D&&D, ,'E)N)+__doc__r#   r$   r)   r%   r&   r'   r(   r*   r<   r   rg   rG   __all__r8   r   r	   r
   r   r   rW   r   r   r   r   r/   r   r   r   r   r   r   posixr   r   r|   r   r+   r   r   r,   r-   r.   r   r9   r7   <module>r      s  
 
			

	
 	 
   8:	"7 ((00 
#>V6)z 	.j(+$D+	 "' CL "llh6 !R#c  s   9B% %B0/B0