a
    zeVl                     @   s  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d Zdd Zdd Zdd Zdd Zdd Zdd Zejje_dd Zdd Zdd Zdd  Zzdd!lmZ W n ey   dZY n0 d"d# Zd$d% Zd&d' Zd(d) Z d*d+ Z!zdd,lm"Z" W n ey*   e!Z#Y n
0 d-d. Z#zdd/lm$Z$m%Z& W n ey`   e#Z'Y n0 d0d1 Z(d2d3 Z)d4d5 Z'e*e	d6oe	+ d7 d8kZ,d>d9d:Z-d;d< Z.zdd=lm/Z0 W n ey   Y n0 dS )?...\;/z.;C:\binnul    N)*)&normcaseisabsjoin
splitdrivesplitsplitextbasenamedirnamecommonprefixgetsizegetmtimegetatimegetctimeislinkexistslexistsisdirisfileismount
expanduser
expandvarsnormpathabspathcurdirpardirseppathsepdefpathaltsepextsepdevnullrealpathsupports_unicode_filenamesrelpathsamefilesameopenfilesamestat
commonpathc                 C   s   t | trdS dS d S )N   \/\/)
isinstancebytespath r5   /usr/lib/python3.9/ntpath.py_get_bothseps"   s    
r7   c                 C   s8   t | } t| tr$| dd S | dd S d S )N   /   \r   r   )osfspathr1   r2   replacelowersr5   r5   r6   r	   ,   s    

r	   c                 C   sj   t | } t| tr,| dddrBdS n| dddrBdS t| d } t| d	koh| d	 t| v S )
Nr8   r9      \\?\Tr   r   \\?\   r   )	r:   r;   r1   r2   r<   
startswithr   lenr7   r>   r5   r5   r6   r
   =   s    

r
   c           
   
   G   sT  t | } t| tr"d}d}d}nd}d}d}z|sD| d d |  t| \}}tt j|D ]~}t|\}}	|	r|	d |v r|s|s|}|	}q\n*|r||kr| | kr|}|	}q\|}|r|d |vr|| }||	 }q\|r|d |vr|r|dd  |kr|| | W S || W S  ttt	fyN   t
jd	| g|R    Y n0 d S )
Nr9   r/      :r   r0   :r   r   )r:   r;   r1   r2   r   mapr=   	TypeErrorAttributeErrorBytesWarninggenericpath_check_arg_types)
r4   pathsr"   sepscolonresult_driveresult_pathpp_drivep_pathr5   r5   r6   r   M   sL    



r   c                 C   s  t | } t| dkrt| tr0d}d}d}nd}d}d}| ||}|dd |d kr|dd	 |kr||d}|d
kr| d d | fS |||d }||d kr| d d | fS |d
krt| }| d | | |d  fS |dd |kr| d d | dd  fS | d d | fS )N   r9   r8   rE   r   r   rF   r      rG   rB   )r:   r;   rD   r1   r2   r<   find)rS   r"   r%   rP   normpindexindex2r5   r5   r6   r   |   s.    

$r   c                 C   sx   t | } t| }t| \}} t| }|rD| |d  |vrD|d8 }q&| d | | |d   }}||pj|}|| |fS NrB   )r:   r;   r7   r   rD   rstrip)rS   rO   diheadtailr5   r5   r6   r      s    

r   c                 C   s8   t | } t| tr$t| dddS t| dddS d S )Nr9   r8      .r   r   r   )r:   r;   r1   r2   rL   	_splitextrS   r5   r5   r6   r      s    

r   c                 C   s   t | d S r\   r   rd   r5   r5   r6   r      s    r   c                 C   s   t | d S )Nr   re   rd   r5   r5   r6   r      s    r   c              
   C   s6   zt | }W n tttfy(   Y dS 0 t|jS )NF)r:   lstatOSError
ValueErrorrJ   statS_ISLNKst_moder4   str5   r5   r6   r      s
    r   c              	   C   s,   zt | }W n ttfy&   Y dS 0 dS )NFT)r:   rf   rg   rh   rl   r5   r5   r6   r      s
    r   )_getvolumepathnamec                 C   st   t | } t| }t| } t| \}}|rD|d |v rD| pB||v S ||v rPdS trl| |t| |kS dS d S )Nr   TF)r:   r;   r7   r   r   rn   r]   )r4   rO   rootrestr5   r5   r6   r     s    
r   c                 C   s   t | } t| trd}nd}| |s,| S dt|  }}||k r\| | t| vr\|d7 }q:dt jv rrt jd }nDdt jvr| S zt jd }W n ty   d}Y n0 t	|t jd }t| trt 
|}|dkrt	t|| d| }|| |d   S )N   ~~rB   USERPROFILEHOMEPATH	HOMEDRIVE )r:   r;   r1   r2   rC   rD   r7   environKeyErrorr   fsencoder   )r4   tilder_   nuserhomedriver5   r5   r6   r   !  s.    








r   c                 C   s&  t | } t| trhd| vr(d| vr(| S dd l}t|j|j d d}d}d}d}d}d}tt d	d }nFd
| vr|d| vr|| S dd l}|j|j d }d}d}d}d}d
}t j}| d d }	d}
t	| }|
|k r"| |
|
d  }||krV| |
d d  } t	| }z&| 
|}
|	|| d |
d   7 }	W n( tyP   |	||  7 }	|d }
Y n0 n||krD| |
d |
d  |kr|	|7 }	|
d7 }
n| |
d d  } t	| }z| 
|}
W n( ty   |	||  7 }	|d }
Y nf0 | d |
 }z.|d u rt t jt | }n|| }W n  ty6   || | }Y n0 |	|7 }	n||kr| |
d |
d  |kr||	|7 }	|
d7 }
q| |
d |
d  |krT| |
d d  } t	| }z| 
|}
W n, ty   |	|| |  7 }	|d }
Y nj0 | d |
 }z.|d u rt t jt | }n|| }W n$ tyH   || | | }Y n0 |	|7 }	n| d d }|
d7 }
| |
|
d  }|r||v r||7 }|
d7 }
| |
|
d  }qxz.|d u rt t jt | }n|| }W n ty   || }Y n0 |	|7 }	|r|
d8 }
n|	|7 }	|
d7 }
q|	S )N   $   %r   z_-ascii   '   {   }environb$%'{}rB   rV   )r:   r;   r1   r2   stringascii_lettersdigitsgetattrrw   rD   rZ   rh   ry   fsdecoderx   )r4   r   varcharsquotepercentbracerbracedollarrw   resrZ   pathlencvarvaluer5   r5   r6   r   Q  s    













r   c           	      C   sP  t | } t| tr*d}d}d}d}d}nd}d}d}d	}d
}| |rL| S | ||} t| \}} | |r||7 }| |} | |}d}|t	|k r,|| r|| |kr||= q|| |kr"|dkr||d  |kr||d |d = |d8 }n&|dkr|
|r||= n|d7 }q|d7 }q|sB|sB|| ||| S )Nr9   r8   rb      ..)s   \\.\r@   r   r   r   r   )z\\.\rA   r   rB   )r:   r;   r1   r2   rC   r<   r   lstripr   rD   endswithappendr   )	r4   r"   r%   r    r!   special_prefixesprefixcompsr_   r5   r5   r6   r     sF    









r   c                 C   s@   t | } t| s8t| tr&t  }nt  }t|| } t| S N)	r:   r;   r
   r1   r2   getcwdbgetcwdr   r   )r4   cwdr5   r5   r6   _abspath_fallback  s    



r   )_getfullpathnamec              	   C   s2   zt t| W S  ttfy,   t|  Y S 0 d S r   )r   r   rg   rh   r   r3   r5   r5   r6   r     s    r   )_getfinalpathnamereadlinkc              
   C   s   d}t  }t| |vr|t|  z:| }t| } t| s\t|sJ|} W qttt|| } W q
 t	y } z$|j
|v rW Y d }~q W Y d }~q
d }~0  ty   Y qY q
0 q
| S )N)rB   rV   rW             2   C   W   i&  i(  i)  )setr	   add_nt_readlinkr
   r   r   r   r   rg   winerrorrh   )r4   allowed_winerrorseenZold_pathexr5   r5   r6   _readlink_deep  s&    
r   c                 C   s   d}d}| rzt | } |r$t| |n| W S  ty } z|j|vrD z4t| }|| krv|rdt||n|W W  Y d }~S W n ty   Y n0 t| \} }| r|s| | W  Y d }~S |rt||n|}W Y d }~qd }~0 0 q|S )N)rB   rV   rW   r   r   r   r   r   r   {   i  i  rv   )r   r   rg   r   r   r   )r4   r   ra   r   new_pathnamer5   r5   r6   _getfinalpathname_nonstrictC  s(    
$*r   c           	   
   C   sd  t | } t| trBd}d}d}t }t| tttkrjdS n(d}d}d}t }t| ttkrjdS | 	|}|st
| st|| } zt| } d	}W n2 ty } z|j}t| } W Y d }~n
d }~0 0 |s`| 	|r`| 	|r|| t|d   }n| t|d  }zt|| kr&|} W n6 ty^ } z|j|krJ|} W Y d }~n
d }~0 0 | S )
Nr@   s   \\?\UNC\s   \\s   \\.\NULrA   z\\?\UNC\z\\z\\.\NULr   )r   r1   r2   r:   r   r	   ry   r'   r   rC   r
   r   r   rg   r   r   rD   )	r4   r   Z
unc_prefixZnew_unc_prefixr   Z
had_prefixZinitial_winerrorr   Zspathr5   r5   r6   r(   q  sD    


r(   getwindowsversionrW   rV   c                 C   sd  t | } t| tr"d}d}d}nd}d}d}|d u r:|}| sFtdt |}ztt|}tt| }t|\}}t|\}	}
t|t|	krtd|	|f d	d
 |	|D }dd
 |
	|D }d}t
||D ]$\}}t|t|kr q|d7 }q|gt||  ||d   }|s(|W S t| W S  tttttfy^   td| |  Y n0 d S )Nr9   rb   r   r   r   r   zno path specifiedz&path is on mount %r, start on mount %rc                 S   s   g | ]}|r|qS r5   r5   .0xr5   r5   r6   
<listcomp>      zrelpath.<locals>.<listcomp>c                 S   s   g | ]}|r|qS r5   r5   r   r5   r5   r6   r     r   r   rB   r*   )r:   r;   r1   r2   rh   r   r   r   r	   r   ziprD   r   rI   rJ   rK   DeprecationWarningrL   rM   )r4   startr"   r    r!   	start_abspath_absstart_drive
start_rest
path_drive	path_rest
start_list	path_listr_   e1e2rel_listr5   r5   r6   r*     sH    




r*   c              	      s  | st dtttj| } t| d tr8dd dndd dz> fd	d
| D }fdd
|D }ztfdd|D \}W n t y   t dd Y n0 ttdd |D dkrt dt	| d 
 \}}|}fdd
|D }fdd
|D }t|}t|}t|D ]*\}	}
|
||	 kr(|d |	 } qdq(|d t| }|rr| n|}|| W S  ttfy   tjdg| R    Y n0 d S )Nz%commonpath() arg is an empty sequencer   r9   r8   rb   r   r   r   c                    s    g | ]}t |  qS r5   )r   r<   r=   )r   rS   )r%   r"   r5   r6   r     r   zcommonpath.<locals>.<listcomp>c                    s   g | ]\}}|  qS r5   re   r   r^   rS   r"   r5   r6   r     r   c                 3   s"   | ]\}}|d d  kV  qd S r\   r5   r   r   r5   r6   	<genexpr>  r   zcommonpath.<locals>.<genexpr>z%Can't mix absolute and relative pathsc                 s   s   | ]\}}|V  qd S r   r5   r   r5   r5   r6   r     r   rB   zPaths don't have the same drivec                    s   g | ]}|r| kr|qS r5   r5   r   r   r    r5   r6   r     r   c                    s   g | ]} fd d|D qS )c                    s   g | ]}|r| kr|qS r5   r5   r   r   r5   r6   r     r   z)commonpath.<locals>.<listcomp>.<listcomp>r5   )r   r?   r   r5   r6   r     r   r.   )rh   tuplerH   r:   r;   r1   r2   r   rD   r   r<   r   minmax	enumerater   rI   rJ   rL   rM   )rN   drivesplitssplit_pathsr
   r}   r4   commons1s2r_   r   r   r5   )r%   r    r"   r6   r.     sF    

r.   )_isdir)N)1r    r!   r&   r"   r#   r%   r$   r'   r:   sysri   rL   __all__r7   r	   r
   r   r   r   r   rc   __doc__r   r   r   r   ntrn   ImportErrorr   r   r   r   r   r   r   r   r   r   r(   r   r   hasattrr   r)   r*   r.   r   r   r5   r5   r5   r6   <module>   sn   
/8

0q2

*.2
84