B
    \ cDW              &   @   s4  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/d0g&Zd1d2 Zd3d Zd4d Zd5d Zd6d Zd7d Zd8d Zejj e_ d9d Zd:d Zd;d Zd<d Zydd=lmZ W n ek
r(   d	ZY nX d>d Zd?d Zd@d ZdAd  Z dBdC Z!yddDlm"Z" W n ek
r|   e!Z#Y n
X dEd! Z#e#Z$e%e
dFoe
& dG dHkZ'dPdId,Z(dJd0 Z)y,e
& d	dH dKkrddLlm*Z* neW n" e+efk
r   dMdN Z*Y nX yddOlm,Z- W n ek
r.   Y nX d	S )QzCommon pathname manipulations, WindowsNT/95 version.

Instead of importing this module directly, import os and refer to this
module as os.path.
.z..\;/z.;C:\binZ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 )Ns   \/z\/)
isinstancebytes)path r0   lib/python3.7/ntpath.py_get_bothseps"   s    
r2   c          	   C   sx   t | } y.t| tr&| dd S | dd S W n: ttfk
rr   t| ttfsltd| j	j
 d Y nX dS )zaNormalize case of pathname.

    Makes all characters lowercase and all slashes into backslashes.   /   \r   r   z0normcase() argument must be str or bytes, not %rN)osfspathr-   r.   replacelower	TypeErrorAttributeErrorstr	__class____name__)sr0   r0   r1   r   ,   s    

c             C   s2   t | } t| d } t| dko0| d t| kS )zTest whether a path is absolute   r   )r5   r6   r
   lenr2   )r>   r0   r0   r1   r   C   s    
c       
   
   G   sT  t | } t| tr"d}d}d}nd}d}d}y|sD| d d |  t| \}}xtt j|D ]~}t|\}}	|	r|	d |kr|s|s|}|	}q^n*|r||kr| | kr|}|	}q^|}|r|d |kr|| }||	 }q^W |r|d |kr|r|dd  |kr|| | S || S  ttt	fk
rN   t
jd	| f|   Y nX d S )
Nr4   s   \/   :r   z\/:r   r	   )r5   r6   r-   r.   r
   mapr8   r9   r:   BytesWarninggenericpath_check_arg_types)
r/   pathsr    sepscolonZresult_driveZresult_pathpZp_driveZp_pathr0   r0   r1   r	   K   sF    

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 )a  Split a pathname into drive/UNC sharepoint and relative path specifiers.
    Returns a 2-tuple (drive_or_unc, path); either part may be empty.

    If you assign
        result = splitdrive(p)
    It is always true that:
        result[0] + result[1] == p

    If the path contained a drive letter, drive_or_unc will contain everything
    up to and including the colon.  e.g. splitdrive("c:/dir") returns ("c:", "/dir")

    If the path contained a UNC path, the drive_or_unc will contain the host name
    and share up to but not including the fourth directory separator character.
    e.g. splitdrive("//host/computer/dir") returns ("//host/computer", "/dir")

    Paths cannot contain both a drive letter and a UNC path.

       r4   r3   rA   r   r   rB   r      rC   Nr?   )r5   r6   r@   r-   r.   r7   find)rK   r    r#   rJ   ZnormpindexZindex2r0   r0   r1   r
   z   s.    

$c             C   s|   t | } t| }t| \}} t| }x |rF| |d  |krF|d8 }q(W | d| | |d  }}||pn|}|| |fS )z~Split a pathname.

    Return tuple (head, tail) where tail is everything after the final slash.
    Either part may be empty.r?   N)r5   r6   r2   r
   r@   rstrip)rK   rI   diheadtailr0   r0   r1   r      s    
c             C   s8   t | } t| tr$t| dddS t| dddS d S )Nr4   r3      .r   r   r   )r5   r6   r-   r.   rF   	_splitext)rK   r0   r0   r1   r      s    

c             C   s   t | d S )z)Returns the final component of a pathnamer?   )r   )rK   r0   r0   r1   r      s    c             C   s   t | d S )z-Returns the directory component of a pathnamer   )r   )rK   r0   r0   r1   r      s    c          	   C   s4   yt | }W n ttfk
r&   dS X t|jS )zhTest whether a path is a symbolic link.
    This will always return false for Windows prior to 6.0.
    F)r5   lstatOSErrorr:   statS_ISLNKst_mode)r/   str0   r0   r1   r      s
    c             C   s(   yt | }W n tk
r"   dS X dS )zCTest whether a path exists.  Returns True for broken symbolic linksFT)r5   rW   rX   )r/   r\   r0   r0   r1   r      s
    )_getvolumepathnamec             C   st   t | } t| }t| } t| \}}|rD|d |krD| pB||kS ||krPdS trl| |t| |kS dS dS )zaTest whether a path is a mount point (a drive root, the root of a
    share, or a mounted volume)r   TFN)r5   r6   r2   r   r
   r]   rP   )r/   rI   rootrestr0   r0   r1   r     s    
c             C   s  t | } t| trd}nd}| |s,| S dt|  }}x$||k r^| | t| kr^|d7 }q<W dt jkrvt jd }n\dt jkrt jd }nFdt jkr| S yt jd }W n tk
r   d}Y nX t	|t jd }t| trt 
|}|dkrt	t|| d| }|| |d	  S )
zLExpand ~ and ~user constructs.

    If user or $HOME is unknown, do nothing.   ~~r?   HOMEZUSERPROFILEZHOMEPATHZ	HOMEDRIVE N)r5   r6   r-   r.   
startswithr@   r2   environKeyErrorr	   fsencoder   )r/   tilderR   nuserhomedriver0   r0   r1   r     s2    









c             C   s<  t | } t| trhd| kr(d| kr(| S ddl}t|j|j d d}d}d}d}d	}d}tt d
d}nFd| kr|d| kr|| S ddl}|j|j d }d}d}d}d}d}t j}| dd }	d}
t	| }xn|
|k r6| |
|
d  }||kr\| |
d d } t	| }y&| 
|}
|	|| d|
d   7 }	W n* tk
rV   |	||  7 }	|d }
Y nX n||krN| |
d |
d  |kr|	|7 }	|
d7 }
n| |
d d } t	| }y| 
|}
W n* tk
r   |	||  7 }	|d }
Y nhX | d|
 }y.|dkrt t jt | }n|| }W n" tk
r@   || | }Y nX |	|7 }	n||kr$| |
d |
d  |kr|	|7 }	|
d7 }
q,| |
d |
d  |krb| |
d d } t	| }y| 
|}
W n. tk
r   |	|| |  7 }	|d }
Y nlX | d|
 }y.|dkr&t t jt | }n|| }W n& tk
rV   || | | }Y nX |	|7 }	n| dd }|
d7 }
| |
|
d  }x6|r||kr||7 }|
d7 }
| |
|
d  }qW y.|dkrt t jt | }n|| }W n tk
r
   || }Y nX |	|7 }	|r,|
d8 }
n|	|7 }	|
d7 }
qW |	S )zfExpand shell variables of the forms $var, ${var} and %var%.

    Unknown variables are left unchanged.   $   %r   Nz_-ascii   '   {   }environb$%'{}r?   rL   )r5   r6   r-   r.   stringZascii_lettersZdigitsgetattrre   r@   rO   
ValueErrorrg   fsdecoderf   )r/   rx   ZvarcharsZquoteZpercentZbraceZrbraceZdollarre   ZresrO   Zpathlencvarvaluer0   r0   r1   r   Q  s    











c       	      C   sT  t | } t| tr*d}d}d}d}d}nd}d}d}d	}d
}| |rL| S | ||} t| \}} | |r||7 }| |} | |}d}x|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 }qW |sF|sF|| ||| S )z0Normalize path, eliminating double slashes, etc.r4   r3   rU   s   ..)s   \\.\s   \\?\r   r   r   z..)z\\.\z\\?\r   r?   )r5   r6   r-   r.   rd   r7   r
   lstripr   r@   endswithappendr	   )	r/   r    r#   r   r   Zspecial_prefixesprefixcompsrR   r0   r0   r1   r     sF    








c             C   s@   t | } t| s8t| tr&t  }nt  }t|| } t| S )zReturn the absolute version of a path as a fallback function in case
    `nt._getfullpathname` is not available or raises OSError. See bpo-31047 for
    more.

    )	r5   r6   r   r-   r.   getcwdbgetcwdr	   r   )r/   cwdr0   r0   r1   _abspath_fallback  s    



r   )_getfullpathnamec          	   C   s.   yt t| S  ttfk
r(   t| S X dS )z&Return the absolute version of a path.N)r   r   rX   rz   r   )r/   r0   r0   r1   r     s    getwindowsversionrM   rL   c             C   sd  t | } t| tr"d}d}d}nd}d}d}|dkr:|}| sFtdt |}ytt|}tt| }t|\}}t|\}	}
t|t|	krtd	|	|f d
d |	|D }dd |
	|D }d}x0t
||D ]"\}}t|t|krP |d7 }qW |gt||  ||d  }|s(|S t| S  tttttfk
r^   td| |  Y nX dS )z#Return a relative version of a pathr4   rU   s   ..r   r   z..Nzno path specifiedz&path is on mount %r, start on mount %rc             S   s   g | ]}|r|qS r0   r0   ).0xr0   r0   r1   
<listcomp>4  s    zrelpath.<locals>.<listcomp>c             S   s   g | ]}|r|qS r0   r0   )r   r   r0   r0   r1   r   5  s    r   r?   r(   )r5   r6   r-   r.   rz   r   r   r
   r   r   zipr@   r	   r9   r:   rE   DeprecationWarningrF   rG   )r/   startr    r   r   Z	start_absZpath_absZstart_driveZ
start_restZ
path_driveZ	path_rest
start_list	path_listrR   Ze1Ze2rel_listr0   r0   r1   r(     sF    


c          	      s  | st dtttj| } t| d tr8dd dndd dy> fd	d
| D }fdd
|D }ytfdd|D \}W n t k
r   t ddY nX ttdd |D dkrt dt	| d 
 \}}|}fdd
|D }fdd
|D }t|}t|}xBt|D ]&\}	}
|
||	 kr,|d|	 }P q,W |dt| }|rt| n|}|| 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   r4   r3   rU   r   r   r   c                s    g | ]}t |  qS r0   )r
   r7   r8   )r   rK   )r#   r    r0   r1   r   a  s    zcommonpath.<locals>.<listcomp>c                s   g | ]\}}|  qS r0   )r   )r   rQ   rK   )r    r0   r1   r   b  s    c             3   s"   | ]\}}|d d  kV  qd S )Nr?   r0   )r   rQ   rK   )r    r0   r1   	<genexpr>e  s    zcommonpath.<locals>.<genexpr>z%Can't mix absolute and relative pathsNc             s   s   | ]\}}|V  qd S )Nr0   )r   rQ   rK   r0   r0   r1   r   l  s    r?   zPaths don't have the same drivec                s   g | ]}|r| kr|qS r0   r0   )r   r|   )r   r0   r1   r   q  s    c                s   g | ]} fd d|D qS )c                s   g | ]}|r| kr|qS r0   r0   )r   r|   )r   r0   r1   r   s  s    z)commonpath.<locals>.<listcomp>.<listcomp>r0   )r   r>   )r   r0   r1   r   s  s    r,   )r,   )rz   tuplerD   r5   r6   r-   r.   setr@   r
   r7   r   minmax	enumerater	   r9   r:   rF   rG   )rH   Zdrivesplitssplit_pathsr   rk   r/   commons1s2rR   r|   r   r0   )r#   r   r    r1   r,   P  sF    
)   r   )_getfinalpathnamec             C   s   t t| S )N)r   r   )fr0   r0   r1   r     s    r   )_isdir)N).__doc__r   r   r$   r    r!   r#   r"   r%   r5   sysrY   rF   __all__r2   r   r   r	   r
   r   r   rV   r   r   r   r   ntr]   ImportErrorr   r   r   r   r   r   r   r&   hasattrr   r'   r(   r,   r   r:   r   r   r0   r0   r0   r1   <module>   sz   



/8

2q1

85