B
    ^DW              &   @   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dirnameZcommonprefixZgetsizeZgetmtimeZgetatimeZgetctimeislinkexistslexistsisdirisfileismount
expanduser
expandvarsnormpathabspathcurdirpardirseppathsepdefpathaltsepextsepdevnullrealpathsupports_unicode_filenamesrelpathZsamefileZsameopenfilesamestat
commonpathc             C   s   t | trdS dS d S )Ns   \/z\/)
isinstancebytes)path r)   ;G:\Soft\LibreOffice\program\python-core-3.7.7\lib\ntpath.py_get_bothseps"   s    
r+   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__)sr)   r)   r*   r   ,   s    

c             C   s2   t | } t| d } t| dko0| d t| kS )zTest whether a path is absolute   r   )r.   r/   r
   lenr+   )r7   r)   r)   r*   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 )
Nr-   s   \/   :r   z\/:r   r	   )r.   r/   r&   r'   r
   mapr1   r2   r3   BytesWarninggenericpath_check_arg_types)
r(   pathsr   sepscolonZresult_driveZresult_pathpZp_driveZp_pathr)   r)   r*   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.

       r-   r,   r:   r   r   r;   r      r<   Nr8   )r.   r/   r9   r&   r'   r0   find)rD   r   r   rC   ZnormpindexZindex2r)   r)   r*   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.r8   N)r.   r/   r+   r
   r9   rstrip)rD   rB   diheadtailr)   r)   r*   r      s    
c             C   s8   t | } t| tr$t| dddS t| dddS d S )Nr-   r,      .r   r   r   )r.   r/   r&   r'   r?   	_splitext)rD   r)   r)   r*   r      s    

c             C   s   t | d S )z)Returns the final component of a pathnamer8   )r   )rD   r)   r)   r*   r      s    c             C   s   t | d S )z-Returns the directory component of a pathnamer   )r   )rD   r)   r)   r*   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)r.   lstatOSErrorr3   statS_ISLNKst_mode)r(   str)   r)   r*   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)r.   rP   rQ   )r(   rU   r)   r)   r*   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)r.   r/   r+   r   r
   rV   rI   )r(   rB   Zrootrestr)   r)   r*   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.   ~~r8   ZHOMEZUSERPROFILEZHOMEPATHZ	HOMEDRIVE N)r.   r/   r&   r'   
startswithr9   r+   environKeyErrorr	   fsencoder   )r(   ZtilderK   nZuserhomedriver)   r)   r*   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$%'{}r8   rE   )r.   r/   r&   r'   stringZascii_lettersZdigitsgetattrr\   r9   rH   
ValueErrorr^   fsdecoder]   )r(   rm   ZvarcharsZquoteZpercentZbraceZrbraceZdollarr\   ZresrH   Zpathlencvarvaluer)   r)   r*   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.r-   r,   rN   s   ..)s   \\.\s   \\?\r   r   r   z..)z\\.\z\\?\r   r8   )r.   r/   r&   r'   r[   r0   r
   lstripr   r9   endswithappendr	   )	r(   r   r   r   r   Zspecial_prefixesprefixZcompsrK   r)   r)   r*   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.

    )	r.   r/   r   r&   r'   getcwdbgetcwdr	   r   )r(   Zcwdr)   r)   r*   _abspath_fallback  s    



rz   )_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{   rQ   ro   rz   )r(   r)   r)   r*   r     s    getwindowsversionrF   rE   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 pathr-   rN   s   ..r   r   z..Nzno path specifiedz&path is on mount %r, start on mount %rc             S   s   g | ]}|r|qS r)   r)   ).0xr)   r)   r*   
<listcomp>4  s    zrelpath.<locals>.<listcomp>c             S   s   g | ]}|r|qS r)   r)   )r}   r~   r)   r)   r*   r   5  s    r   r8   r#   )r.   r/   r&   r'   ro   r   r   r
   r   r   zipr9   r	   r2   r3   r>   DeprecationWarningr?   r@   )r(   startr   r   r   Z	start_absZpath_absZstart_driveZ
start_restZ
path_driveZ	path_restZ
start_list	path_listrK   Ze1Ze2Zrel_listr)   r)   r*   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   r-   r,   rN   r   r   r   c                s    g | ]}t |  qS r)   )r
   r0   r1   )r}   rD   )r   r   r)   r*   r   a  s    zcommonpath.<locals>.<listcomp>c                s   g | ]\}}|  qS r)   )r   )r}   rJ   rD   )r   r)   r*   r   b  s    c             3   s"   | ]\}}|d d  kV  qd S )Nr8   r)   )r}   rJ   rD   )r   r)   r*   	<genexpr>e  s    zcommonpath.<locals>.<genexpr>z%Can't mix absolute and relative pathsNc             s   s   | ]\}}|V  qd S )Nr)   )r}   rJ   rD   r)   r)   r*   r   l  s    r8   zPaths don't have the same drivec                s   g | ]}|r| kr|qS r)   r)   )r}   rq   )r   r)   r*   r   q  s    c                s   g | ]} fd d|D qS )c                s   g | ]}|r| kr|qS r)   r)   )r}   rq   )r   r)   r*   r   s  s    z)commonpath.<locals>.<listcomp>.<listcomp>r)   )r}   r7   )r   r)   r*   r   s  s    r%   )r%   )ro   tupler=   r.   r/   r&   r'   setr9   r
   r0   r   minmax	enumerater	   r2   r3   r?   r@   )rA   ZdrivesplitsZsplit_pathsr   r`   r(   ZcommonZs1Zs2rK   rq   rw   r)   )r   r   r   r*   r%   P  sF    
)   r   )_getfinalpathnamec             C   s   t t| S )N)r   r   )fr)   r)   r*   r     s    r   )_isdir)N).__doc__r   r   r   r   r   r   r   r    r.   sysrR   r?   __all__r+   r   r   r	   r
   r   r   rO   r   r   r   r   ntrV   ImportErrorr   r   r   r   rz   r{   r   r!   hasattrr|   r"   r#   r%   r   r3   r   r   r)   r)   r)   r*   <module>   sz   



/8

2q1

85