U
    k]e=                  &   @   s^  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 d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/g&Zd0d1 Zd2d
 Zd3d Zd4d Zd5d Zd6d Zejj e_ d7d Zd8d Zd9d Zd:d Zd;d Zd<d Zd=d Zdadad>d Zd?d Zd@d  Z dAd, Z!dBdC Z"e
j#dDkZ$dGdEd.Z%dFd/ Z&dS )Ha  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                 C   s   t | trdS dS d S )N   /r   )
isinstancebytespath r2   /usr/lib/python3.8/posixpath.py_get_sep)   s    
r4   c                 C   s
   t | S )z6Normalize case of pathname.  Has no effect under Posixosfspath)sr2   r2   r3   r   4   s    c                 C   s   t | } t| }| |S )zTest whether a path is absolute)r6   r7   r4   
startswith)r8   r#   r2   r2   r3   r   <   s    
c              
   G   s   t | } t| }| }z^|s,|dd |  tt j|D ]8}||rL|}q8|rZ||rd||7 }q8||| 7 }q8W n. tttfk
r   t	j
d| f|   Y nX |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	   )r6   r7   r4   mapr9   endswith	TypeErrorAttributeErrorBytesWarninggenericpath_check_arg_types)apr#   r1   br2   r2   r3   r	   G   s     


c                 C   s`   t | } t| }| |d }| d| | |d  }}|rX||t| krX||}||fS )zSplit a pathname.  Returns tuple "(head, tail)" where "tail" is
    everything after the final slash.  Either part may be empty.   Nr6   r7   r4   rfindlenrstrip)rB   r#   iheadtailr2   r2   r3   r   d   s    

c                 C   s6   t | } t| trd}d}nd}d}t| |d |S )Nr-      .r   r   )r6   r7   r.   r/   r?   	_splitext)rB   r#   r'   r2   r2   r3   r   u   s    

c                 C   s   t | } | dd | fS )zJSplit a pathname into drive and path. On Posix, drive is always
    empty.Nr   r5   )rB   r2   r2   r3   r
      s    
c                 C   s,   t | } t| }| |d }| |d S )z)Returns the final component of a pathnamerD   N)r6   r7   r4   rF   )rB   r#   rI   r2   r2   r3   r      s    
c                 C   sN   t | } t| }| |d }| d| }|rJ||t| krJ||}|S )z-Returns the directory component of a pathnamerD   NrE   )rB   r#   rI   rJ   r2   r2   r3   r      s    

c              
   C   s8   zt | }W n tttfk
r*   Y dS X t|jS )z&Test whether a path is a symbolic linkF)r6   lstatOSError
ValueErrorr=   statS_ISLNKst_mode)r1   str2   r2   r3   r      s
    c              	   C   s.   zt |  W n ttfk
r(   Y dS X dS )zCTest whether a path exists.  Returns True for broken symbolic linksFT)r6   rN   rO   rP   r0   r2   r2   r3   r      s
    c              	   C   s   zt | }W n ttfk
r(   Y dS X t|jr:dS t| trPt	| d}n
t	| d}t
|}zt |}W n ttfk
r   Y dS X |j}|j}||krdS |j}|j}||krdS dS )z$Test whether a path is a mount pointF   ..r   T)r6   rN   rO   rP   rQ   rR   rS   r.   r/   r	   r)   st_devst_ino)r1   s1parents2dev1dev2ino1ino2r2   r2   r3   r      s.    

c           	      C   s<  t | } t| trd}nd}| |s,| S t| }| |d}|dk rPt| }|dkrdt jkrddl	}z|
t  j}W q tk
r   |  Y S X n
t jd }nVddl	}| d| }t|trt|d}z||}W n tk
r   |  Y S X |j}t| trt |}d}nd	}||}|| |d  p:|S )
zOExpand ~ and ~user constructions.  If user or $HOME is unknown,
    do nothing.   ~~rD   r   HOMENASCIIr-   r   )r6   r7   r.   r/   r9   r4   findrG   environpwdgetpwuidgetuidpw_dirKeyErrorstrgetpwnamfsencoderH   )	r1   tilder#   rI   re   userhomenamepwentrootr2   r2   r3   r      sB    








c                 C   sZ  t | } t| trVd| kr | S ts:ddl}|d|jatj}d}d}t	t dd}n:d| krb| S t
s|ddl}|d	|ja
t
j}d
}d}t j}d}|| |}|sqV|d\}}|d}	|	|r|	|r|	dd }	z.|dkrt t jt |	 }
n||	 }
W n tk
r&   |}Y qX | |d }| d| |
 } t| }| |7 } q| S )zZExpand shell variables of form $var and ${var}.  Unknown variables
    are left unchanged.   $r   Ns   \$(\w+|\{[^}]*\})   {   }environb$z\$(\w+|\{[^}]*\}){}rD   )r6   r7   r.   r/   	_varprogbrecompilerb   searchgetattr_varprogrd   spangroupr9   r;   rl   fsdecoderi   rG   )r1   r{   r}   startendrd   rI   mjro   valuerK   r2   r2   r3   r     sN    






c           	      C   s   t | } t| tr&d}d}d}d}nd}d}d}d}| |krB|S | |}|rp| |d	 rp| |d
 spd	}| |}g }|D ]J}|||fkrq||ks|s|r|r|d |kr|| q|r|  q|}||} |r|| |  } | p|S )z0Normalize path, eliminating double slashes, etc.r-       rL   rU   r    r   r         ry   )	r6   r7   r.   r/   r9   r   appendpopr	   )	r1   r#   emptydotdotdotinitial_slashescomps	new_compscompr2   r2   r3   r   N  sJ    






c                 C   s@   t | } t| s8t| tr&t  }nt  }t|| } t| S )zReturn an absolute path.)	r6   r7   r   r.   r/   getcwdbgetcwdr	   r   )r1   cwdr2   r2   r3   r   t  s    



c                 C   s*   t | } t| dd | i \}}t|S )zlReturn the canonical path of the specified filename, eliminating any
symbolic links encountered in the path.Nr   )r6   r7   _joinrealpathr   )filenamer1   okr2   r2   r3   r)     s    
c           
      C   s  t | trd}d}d}nd}d}d}t|r<|dd  }|} |r||\}}}|r<||kr`q<||kr| rt| \} }||krt| ||} q<|} q<t| |}t|s|} q<||kr|| } | d k	rq<t||dfS d ||< t| t	||\} }	|	st| |dfS | ||< q<| d	fS )
Nr-   rL   rU   r   r   r   rD   FT)
r.   r/   r   	partitionr   r	   r   r   r6   readlink)
r1   restseenr#   r!   r"   ro   _newpathr   r2   r2   r3   r     sH    


r   darwinc           	      C   s   | st dt| } t| tr.d}d}d}nd}d}d}|dkrH|}n
t|}zrd	d
 t||D }dd
 t| |D }tt||g}|gt||  ||d  }|s|W S t	| W S  t
tttfk
r   td| |  Y nX dS )z#Return a relative version of a pathzno path specifiedrL   r-   rU   r   r   r   Nc                 S   s   g | ]}|r|qS r2   r2   .0xr2   r2   r3   
<listcomp>  s      zrelpath.<locals>.<listcomp>c                 S   s   g | ]}|r|qS r2   r2   r   r2   r2   r3   r     s      r+   )rP   r6   r7   r.   r/   r   r   rG   r   r	   r<   r=   r>   DeprecationWarningr?   r@   )	r1   r   r!   r#   r"   
start_list	path_listrI   rel_listr2   r2   r3   r+     s0    



c           	   	      s2  | st dtttj| } t| d tr4dd ndd zƇfdd| D }ztfd	d
| D \}W n t k
r   t ddY nX  fdd|D }t|}t	|}|}t
|D ]$\}}||| kr|d| } qq|rn
dd }|| W S  ttfk
r,   tjd|    Y nX dS )zDGiven a sequence of path names, returns the longest common sub-path.z%commonpath() arg is an empty sequencer   r-   rL   r   r   c                    s   g | ]}|  qS r2   )r   )r   r1   r#   r2   r3   r     s     zcommonpath.<locals>.<listcomp>c                 3   s   | ]}|d d  kV  qd S )NrD   r2   )r   rB   r   r2   r3   	<genexpr>  s     zcommonpath.<locals>.<genexpr>z%Can't mix absolute and relative pathsNc                    s   g | ]} fd d|D qS )c                    s   g | ]}|r| kr|qS r2   r2   )r   cr!   r2   r3   r      s       z)commonpath.<locals>.<listcomp>.<listcomp>r2   )r   r8   r   r2   r3   r      s     r,   )r,   )rP   tupler:   r6   r7   r.   r/   setminmax	enumerater	   r<   r=   r?   r@   )	pathssplit_pathsr   rX   rZ   commonrI   r   prefixr2   )r!   r#   r3   r,     s6    )N)'__doc__r!   r"   r'   r#   r$   r%   r&   r(   r6   sysrQ   r?   __all__r4   r   r   r	   r   r   rM   r
   r   r   r   r   r   r   r   rz   r   r   r   r)   r   platformr*   r+   r,   r2   r2   r2   r3   <module>   s                            
	
	

*25&	3

)