
    duB                     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T 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adad Z	 ddlm Z  d Z!n# e"$ r d Z!Y nw xY wd Z#dddZ$d  Z%e
j&        d!k    Z'd$d"Z(d# Z)dS )%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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
commonpathc                 4    t          | t                    rdS dS )N   /r   )
isinstancebytespaths    lib/python3.11/posixpath.py_get_sepr5   )   s    $ ts    c                 *    t          j        |           S )z6Normalize case of pathname.  Has no effect under Posixosfspath)ss    r4   r   r   4   s    9Q<<r6   c                 r    t          j        |           } t          |           }|                     |          S )zTest whether a path is absolute)r9   r:   r5   
startswith)r;   r$   s     r4   r	   r	   <   s,    
	!A
1++C<<r6   c                    t          j        |           } t          |           }| }	 |s|dd         |z    t          t           j        |          D ]?}|                    |          r|}|r|                    |          r||z  }7|||z   z  }@n/# t          t          t          f$ r t          j
        d| g|R    w xY w|S )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
   )r9   r:   r5   mapr=   endswith	TypeErrorAttributeErrorBytesWarninggenericpath_check_arg_types)apr$   r3   bs        r4   r
   r
   G   s    
 		!A
1++CD 	!HsNNRY"" 	  	 A||C      T]]3//  	a	  ~|4   $VQ33333 Ks   A)B ,B=c                    t          j        |           } t          |           }|                     |          dz   }| d|         | |d         }}|r+||t	          |          z  k    r|                    |          }||fS )zSplit a pathname.  Returns tuple "(head, tail)" where "tail" is
    everything after the final slash.  Either part may be empty.   Nr9   r:   r5   rfindlenrstrip)rG   r$   iheadtails        r4   r   r   d   s     		!A
1++C	qA2A2!""$D  CII%%{{3:r6   c                     t          j        |           } t          | t                    rd}d}nd}d}t	          j        | |d |          S )Nr/      .r   r   )r9   r:   r0   r1   rD   	_splitext)rG   r$   r(   s      r4   r   r   u   sN    
	!A!U  Cv666r6   c                 B    t          j        |           } | dd         | fS )zJSplit a pathname into drive and path. On Posix, drive is always
    empty.Nr   r8   )rG   s    r4   r   r      s"     		!ARaR5!8Or6   c                     t          j        |           } t          |           }|                     |          dz   }| |d         S )z)Returns the final component of a pathnamerJ   N)r9   r:   r5   rL   )rG   r$   rO   s      r4   r   r      s;    
	!A
1++C	qAQRR5Lr6   c                     t          j        |           } t          |           }|                     |          dz   }| d|         }|r+||t	          |          z  k    r|                    |          }|S )z-Returns the directory component of a pathnamerJ   NrK   )rG   r$   rO   rP   s       r4   r   r      sm    
	!A
1++C	qARaR5D  CII%%{{3Kr6   c                     	 t          j        |           }n# t          t          t          f$ r Y dS w xY wt          j        |j                  S )z&Test whether a path is a symbolic linkF)r9   lstatOSError
ValueErrorrB   statS_ISLNKst_mode)r3   sts     r4   r   r      sQ    Xd^^Z0   uu<
###s    22c                 b    	 t          j        |            n# t          t          f$ r Y dS w xY wdS )zCTest whether a path exists.  Returns True for broken symbolic linksFT)r9   rY   rZ   r[   r2   s    r4   r   r      sB    
Z    uu4s    ,,c                    	 t          j        |           }t          j        |j                  rdS n# t
          t          f$ r Y dS w xY wt          j        |           } t          | t                    rt          | d          }nt          | d          }t          |          }	 t          j        |          }n# t
          t          f$ r Y dS w xY w|j        }|j        }||k    rdS |j        }|j        }||k    rdS dS )z$Test whether a path is a mount pointF   ..r   T)r9   rY   r\   r]   r^   rZ   r[   r:   r0   r1   r
   r*   st_devst_ino)r3   s1parents2dev1dev2ino1ino2s           r4   r   r      s'   Xd^^ <
## 	5	 Z    uu 9T??D$ "dE""dD!!fFXfZ    uu 9D9Dt||t9D9Dt||t5s!   2 AA$B9 9CCc                    t          j        |           } t          | t                    rd}nd}|                     |          s| S t          |           }|                     |d          }|dk     rt          |           }|dk    rxdt           j        vrW	 ddl	}n# t          $ r | cY S w xY w	 |                    t          j                              j        }n# t          $ r | cY S w xY wt           j        d         }nw	 ddl	}n# t          $ r | cY S w xY w| d|         }t          |t                    rt          |d          }	 |                    |          }n# t          $ r | cY S w xY w|j        }|t"          j        dk    r| S t          | t                    rt          j        |          }d	}nd
}|                    |          }|| |d         z   p|S )zOExpand ~ and ~user constructions.  If user or $HOME is unknown,
    do nothing.   ~~rJ   r   HOMENASCIIvxworksr/   r   )r9   r:   r0   r1   r=   r5   findrM   environpwdImportErrorgetpwuidgetuidpw_dirKeyErrorstrgetpwnamsysplatformfsencoderN   )	r3   tilder$   rO   rt   userhomenamepwentroots	            r4   r   r      s3    9T??D$ ??5!! 
4..C		#qA1uuIIAvv##



   <<	44;    
 z&)HH	JJJJ 	 	 	KKK	 AaCydE"" 	&tW%%D	LL&&EE 	 	 	 KKK	 <CLI55$ ;x((t$$HtABBx(D(sH   B B)(B)-+C C('C(?D DDE E+*E+c                 v   t          j        |           } t          | t                    rSd| vr| S t          sddl}|                    d|j                  at          j        }d}d}t          t           dd          }nHd| vr| S t          sddl}|                    d	|j                  a
t          j        }d
}d}t           j        }d}	  || |          }|sn|                    d          \  }}|                    d          }	|	                    |          r|	                    |          r
|	dd         }		 |7t          j        t           j        t          j        |	                             }
n||	         }
| |d         }| d|         |
z   } t%          |           }| |z  } n# t&          $ r |}Y nw xY w| S )zZExpand shell variables of form $var and ${var}.  Unknown variables
    are left unchanged.   $r   Ns   \$(\w+|\{[^}]*\})   {   }environb$z\$(\w+|\{[^}]*\}){}TrJ   )r9   r:   r0   r1   	_varprogbrecompilerp   searchgetattr_varprogrs   spangroupr=   r@   r~   fsdecoderM   ry   )r3   r   r   startendrs   rO   mjr   valuerQ   s               r4   r   r   %  s    9T??D$ tK 	DIII

#8"(CCI!"j$//d??K 	BIIIzz"6AAH*	AF4OO 	vvayy1wwqzz??5!! 	dmmC&8&8 	":D	BJr{4/@/@$ABB 8D8e#DD		ADLDD  	 	 	AAA	( Ks   9AF& &F54F5)_path_normpathc                     t          j        |           } t          | t                    r5t          j        t          t          j        |                               pdS t          |           pdS )0Normalize path, eliminating double slashes, etc.rS   r   )r9   r:   r0   r1   r~   r   r   r2   s    r4   r   r     s\    ydE"" 	J;~bk$.?.?@@AAITId##*s*r6   c                 0   t          j        |           } t          | t                    r	d}d}d}d}nd}d}d}d}| |k    r|S |                     |          }|r2|                     |d	z            r|                     |d
z            sd	}|                     |          }g }|D ]M}|||fv r	||k    s|s|r|r"|d         |k    r|                    |           7|r|                                 N|}|                    |          } |r||z  | z   } | p|S )r   r/   r6   rS   rb   r    r   r         r   )	r9   r:   r0   r1   r=   r   appendpopr
   )	r3   r$   emptydotdotdotinitial_slashescomps	new_compscomps	            r4   r   r   ^  sh   ydE"" 		CECFFCECF5==J//#..  	 OOCE""	 +/??3q5+A+A	 O

3	 	  	 Ds|##y  )" 7 7  &&&&  xx 	.&-D{sr6   c                     t          j        |           } t          |           sLt          | t                    rt          j                    }nt          j                    }t          ||           } t          |           S )zReturn an absolute path.)	r9   r:   r	   r0   r1   getcwdbgetcwdr
   r   )r3   cwds     r4   r   r     s`    9T??D;; dE"" 	*,,CC)++CCD>>r6   F)strictc                    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   )r9   r:   _joinrealpathr   )filenamer   r3   oks       r4   r*   r*     s>     y""HXbqb\8VR@@HD"4==r6   c                    t          | t                    rd}d}d}nd}d}d}t          |          r|dd          }|} |r0|                    |          \  }}}|r||k    r%||k    r/| r*t	          |           \  } }||k    rt          | ||          } n|} Zt          | |          }		 t          j        |	          }
t          j	        |
j
                  }n# t          $ r |r d}Y nw xY w|s|	} |	|v r4||	         } | |rt          j        |	           nt          |	|          dfS d ||	<   t          | t          j        |	          ||          \  } }|st          | |          dfS | ||	<   |0| d	fS )
Nr/   rS   rb   r   r   r   rJ   FT)r0   r1   r	   	partitionr   r
   r9   rY   r\   r]   r^   rZ   r   readlink)r3   restr   seenr$   r"   r#   r   _newpathr_   is_linkr   s                r4   r   r     s   $ T{{ ABBx
 ,s++a 	tv~~6>> "4[[
d6>>ff55DtT""	/'""B l2:..GG  	 	 	 GGG	  	Dd??=D 2     GT**E11W r{7';';VTJJb 	+d##U**WY  ,\ :s   )C C)(C)darwinc                 |   | st          d          t          j        |           } t          | t                    rd}d}d}nd}d}d}||}nt          j        |          }	 d	 t          |                              |          D             }d
 t          |                               |          D             }t          t          ||g                    }|gt          |          |z
  z  ||d         z   }|s|S t          | S # t          t          t          t          f$ r t          j        d| |            w xY w)z#Return a relative version of a pathzno path specifiedrS   r/   rb   r   r   r   Nc                     g | ]}||S  r   .0xs     r4   
<listcomp>zrelpath.<locals>.<listcomp>  s    @@@Aa@a@@@r6   c                     g | ]}||S r   r   r   s     r4   r   zrelpath.<locals>.<listcomp>  s    >>>1A>Q>>>r6   r,   )r[   r9   r:   r0   r1   r   r   rM   r   r
   rA   rB   rC   DeprecationWarningrD   rE   )	r3   r   r"   r$   r#   
start_list	path_listrO   rel_lists	            r4   r,   r,     sZ     .,---9T??D$ }	%  @@!5!5c!:!:@@@
>> 3 3C 8 8>>>	j)455668s:q01IabbMA 	MX~|5GH   $Ye<<<s   "BD =D 5D;c                   	
 | st          d          t          t          t          j        |                     } t          | d         t                    rd
d	nd
d		 
fd| D             }	 t          
fd| D                       \  }n# t           $ r t          d	          d
w xY w	fd|D             }t          |          }t          |          }|}t          |          D ]\  }}|||         k    r|d
|         } n|r
n	
d
d         }|
                    |          z   S # t          t          f$ r t          j        dg| R    w xY w)zDGiven a sequence of path names, returns the longest common sub-path.z%commonpath() arg is an empty sequencer   r/   rS   r   r   c                 :    g | ]}|                               S r   )r   )r   r3   r$   s     r4   r   zcommonpath.<locals>.<listcomp>  s#    9994tzz#999r6   c              3   4   K   | ]}|d d         k    V  d S )NrJ   r   )r   rG   r$   s     r4   	<genexpr>zcommonpath.<locals>.<genexpr>!  s/      55!2A2#555555r6   z%Can't mix absolute and relative pathsNc                 ,    g | ]}fd |D             S )c                 $    g | ]}||k    
|S r   r   )r   cr"   s     r4   r   z)commonpath.<locals>.<listcomp>.<listcomp>%  s#    :::a:a6kkkkkr6   r   )r   r;   r"   s     r4   r   zcommonpath.<locals>.<listcomp>%  s.    PPPq::::1:::PPPr6   r-   )r[   tupler?   r9   r:   r0   r1   setminmax	enumerater
   rA   rB   rD   rE   )pathssplit_pathsr	   re   rg   commonrO   r   prefixr"   r$   s            @@r4   r-   r-     s     B@AAA#bi''((E%(E"" 99995999	P5555u55555FEE 	P 	P 	PDEE4O	P QPPPKPPPbMM 	 	DAqBqEzzBQB  *3rr7((((~&   $\:E::::s%    D, /B D, B((BD, ,%E)N)*__doc__r"   r#   r(   r$   r%   r&   r'   r)   r9   r|   r\   rD   __all__r5   r   r	   r
   r   r   rT   r   r   r   r   r   r   r   r   r   r   posixr   r   ru   r   r*   r   r}   r+   r,   r-   r   r6   r4   <module>r      sL  
 
 
			

	
 				 



                   :	 	 	"7 7 7 (0 
      $ $ $    V6) 6) 6)z 	. . .j0+$$$$$$T+ + + +Q  % % %$ $ $ $ $%`	 	 	 "'     < < <~ "lh6 ! ! ! !R# # # # #s   +A5 5B ?B 