
[[\O              &   @   sN  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Td 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 d* Z d+ Z d* Z d, Z	 d- Z
 d. Z d/ Z d0 e j k r d1 Z n  d2 Z d3 d4   Z d5 d6   Z d7 d8   Z d9 d:   Z d; d<   Z d= d>   Z d? d@   Z dA d   Z dB d   Z dC d   Z dD d   Z dE d   Z dF d   Z dG d	   Z e j j  e _  dH d
   Z dI d   Z dJ d   Z  dK d   Z! y d dL l" m# Z# Wn e$ k
 rd Z# Yn XdM d   Z% dN d   Z& dO d   Z' dP d   Z( y d dQ l" m) Z) Wn e$ k
 rzdR d   Z* Yn XdS d   Z* e* Z+ e, e dT  oe j-   dU dV k Z. e dW d&  Z/ y9 e j-   d dV  d] k rd dY l" m0 Z0 n e$  Wn$ e1 e$ f k
 r dZ d[   Z0 Yn Xy d d\ l" m2 Z3 Wn e$ k
 rIYn Xd S)^zCommon pathname manipulations, WindowsNT/95 version.

Instead of importing this module directly, import os and refer to this
module as os.path.
    N)*normcaseisabsjoin
splitdrivesplitsplitextbasenamedirnamecommonprefixgetsizegetmtimegetatimegetctimeislinkexistslexistsisdirisfileismount
expanduser
expandvarsnormpathabspathsplitunccurdirpardirseppathsepdefpathaltsepextsepdevnullrealpathsupports_unicode_filenamesrelpathsamefilesameopenfilesamestat.z..\;/z.;C:\binZcez\WindowsZnulc             C   s   t  |  t  r d Sd Sd  S)N     )
isinstancebytes)path r2   /usr/lib/python3.4/ntpath.py
_get_empty#   s    r4   c             C   s   t  |  t  r d Sd Sd  S)Ns   \r*   )r/   r0   )r1   r2   r2   r3   _get_sep)   s    r5   c             C   s   t  |  t  r d Sd Sd  S)N   /r,   )r/   r0   )r1   r2   r2   r3   _get_altsep/   s    r7   c             C   s   t  |  t  r d Sd Sd  S)Ns   \/z\/)r/   r0   )r1   r2   r2   r3   _get_bothseps5   s    r8   c             C   s   t  |  t  r d Sd Sd  S)N   .r)   )r/   r0   )r1   r2   r2   r3   _get_dot;   s    r:   c             C   s   t  |  t  r d Sd Sd  S)N   ::)r/   r0   )r1   r2   r2   r3   
_get_colonA   s    r=   c             C   s   t  |  t  r d Sd Sd  S)N   \\.\   \\?\\\.\\\?\)r>   r?   )r@   rA   )r/   r0   )r1   r2   r2   r3   _get_specialG   s    rB   c             C   sU   t  |  t t f  s3 t d j |  j j    n  |  j t |   t	 |    j
   S)zaNormalize case of pathname.

    Makes all characters lowercase and all slashes into backslashes.z2normcase() argument must be str or bytes, not '{}')r/   r0   str	TypeErrorformat	__class____name__replacer7   r5   lower)sr2   r2   r3   r   Q   s    c             C   s<   t  |   d }  t |   d k o; |  d d  t |   k S)zTest whether a path is absolute   r   N)r   lenr8   )rJ   r2   r2   r3   r   a   s    c       
      G   sI  t  |   } t |   } t |   } t |   \ } } x | D] } t |  \ } }	 |	 r |	 d | k r | sx | r | } n  |	 } q= nE | r | | k r | j   | j   k r | } |	 } q= n  | } n  | r | d | k r | | } n  | |	 } q= W| rA| d | k rA| rA| d d   | k rA| | | S| | S)Nr   rK   rM   )r5   r8   r=   r   rI   )
r1   Zpathsr   sepsZcolonZresult_driveZresult_pathpZp_driveZp_pathr2   r2   r3   r   h   s0    		c             C   sJ  t  |   } t |   d k r@t |   } |  j t |   |  } | d d  | d k r| d d  | k r| j | d  } | d k r | |  f S| j | | d  } | | d k r | |  f S| d k r t |   } n  |  d |  |  | d  f S| d d  t |   k r@|  d d  |  d d  f Sn  | |  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.

    rK   r         NrM   rM   )r4   rL   r5   rH   r7   findr=   )rO   emptyr   ZnormpindexZindex2r2   r2   r3   r      s"    0

!c             C   sa   d d l  } | j d t d  t |   \ } } t |  d k rW |  d d  |  f S| | f S)a  Deprecated since Python 3.1.  Please use splitdrive() instead;
    it now handles UNC paths.

    Split a pathname into UNC mount point and relative path specifiers.

    Return a 2-tuple (unc, rest); either part may be empty.
    If unc is not empty, it has the form '//host/mount' (or similar
    using backslashes).  unc+rest is always the input path.
    Paths containing drive letters never have an UNC part.
    r   Nz<ntpath.splitunc is deprecated, use ntpath.splitdrive insteadrP   )warningswarnDeprecationWarningr   rL   )rO   rU   driver1   r2   r2   r3   r      s    	
c             C   s   t  |   } t |   \ } }  t |   } x( | rT |  | d | k rT | d 8} q- W|  d |  |  | d  } } | } x0 | r | d d  | k r | d d  } q W| p | } | | | f S)z~Split a pathname.

    Return tuple (head, tail) where tail is everything after the final slash.
    Either part may be empty.rK   NrM   rM   )r8   r   rL   )rO   rN   diheadtailZhead2r2   r2   r3   r      s    !c             C   s(   t  j |  t |   t |   t |    S)N)genericpath	_splitextr5   r7   r:   )rO   r2   r2   r3   r      s    c             C   s   t  |   d S)z)Returns the final component of a pathnamerK   )r   )rO   r2   r2   r3   r	      s    c             C   s   t  |   d S)z-Returns the directory component of a pathnamer   )r   )rO   r2   r2   r3   r
      s    c             C   sB   y t  j |   } Wn t t f k
 r1 d SYn Xt j | j  S)zhTest whether a path is a symbolic link.
    This will always return false for Windows prior to 6.0.
    F)oslstatOSErrorAttributeErrorstatS_ISLNKst_mode)r1   str2   r2   r3   r     s
    	c             C   s0   y t  j |   } Wn t k
 r+ d SYn Xd S)zCTest whether a path exists.  Returns True for broken symbolic linksFT)r_   r`   ra   )r1   rf   r2   r2   r3   r     s
    	)_getvolumepathnamec             C   s   t  |   } t |   }  t |   \ } } | rQ | d | k rQ | pP | | k S| | k ra d St r |  j |  t |   j |  k Sd Sd S)zaTest whether a path is a mount point (a drive root, the root of a
    share, or a mounted volume)r   TFN)r8   r   r   rg   rstrip)r1   rN   rootrestr2   r2   r3   r   $  s    "c             C   sq  t  |  t  r d } n d } |  j |  s1 |  Sd t |   } } x0 | | k  rv |  | t |   k rv | d 7} qG Wd t j k r t j d } nt d t j k r t j d } nU d t j k r |  Sy t j d } Wn t k
 r d } Yn Xt | t j d  } t  |  t  r1| j	 t
 j    } n  | d k r_t t |  |  d |   } n  | |  | d	  S)
zLExpand ~ and ~user constructs.

    If user or $HOME is unknown, do nothing.   ~~rK   HOMEZUSERPROFILEZHOMEPATHZ	HOMEDRIVEr.   N)r/   r0   
startswithrL   r8   r_   environKeyErrorr   encodesysgetfilesystemencodingr
   )r1   tilderZ   nuserhomerX   r2   r2   r3   r   >  s0    	%"c             C   su  t  |  t  r t d  |  k r7 t d  |  k r7 |  Sd d l } t | j | j d d  } d } d } d	 } d
 } t t d d  } n] d |  k r d |  k r |  Sd d l } | j | j d } d } d } d } d } t j } |  d d  } d }	 t	 |   }
 xb|	 |
 k  rp|  |	 |	 d  } | | k r|  |	 d d  }  t	 |   }
 y/ |  j
 |  }	 | | |  d |	 d  7} Wqct k
 r| |  7} |
 d }	 YqcXn| | k r|  |	 d |	 d  | k r| | 7} |	 d 7}	 qc|  |	 d d  }  t	 |   }
 y |  j
 |  }	 Wn* t k
 rV| | |  7} |
 d }	 YqcX|  d |	  } y< | d k rt j t j t j |   } n
 | | } Wn  t k
 r| | | } Yn X| | 7} n| | k rY|  |	 d |	 d  | k r| | 7} |	 d 7}	 qc|  |	 d |	 d  | k ro|  |	 d d  }  t	 |   }
 y4 t  |  t  rv|  j
 d  }	 n |  j
 d  }	 WnJ t k
 rt  |  t  r| d |  7} n | d |  7} |
 d }	 YqVX|  d |	  } y< | d k rt j t j t j |   } n
 | | } Wn@ t k
 rat  |  t  rOd | d } n d | d } Yn X| | 7} qc|  d d  } |	 d 7}	 |  |	 |	 d  } x> | r| | k r| | 7} |	 d 7}	 |  |	 |	 d  } qWy< | d k rt j t j t j |   } n
 | | } Wn t k
 r8| | } Yn X| | 7} | rc|	 d 8}	 qcn
 | | 7} |	 d 7}	 qW| S)zfExpand shell variables of the forms $var, ${var} and %var%.

    Unknown variables are left unchanged.$%r   Nz_-asciis   '   %   {   $environb'{rK   rP      }}s   ${z${)r/   r0   ordstringZascii_lettersZdigitsgetattrr_   ro   rL   rT   
ValueErrorfsencodefsdecoderp   )r1   r   ZvarcharsZquoteZpercentZbraceZdollarro   ZresrT   ZpathlencZvarvaluer2   r2   r3   r   o  s    $	 

"
"


"

c             C   s  t  |   } t |   d } t |   } |  j |  r; |  S|  j t |   |  }  t |   \ } }  |  j |  r | | 7} |  j |  }  n  |  j |  } d } x | t	 |  k  r|| | s | | t |   k r | | =q | | | k ro| d k r7| | d | k r7| | d | d  =| d 8} qy| d k rb| j
 t  |    rb| | =qy| d 7} q | d 7} q W| r| r| j t |    n  | | j |  S)z0Normalize path, eliminating double slashes, etc.rP   r   rK   )r5   r:   rB   rn   rH   r7   r   lstripr   rL   endswithappendr   )r1   r   dotdotZspecial_prefixesprefixcompsrZ   r2   r2   r3   r     s4    
!
 !
)_getfullpathnamec             C   sR   t  |   sH t |  t  r* t j   } n t j   } t | |   }  n  t |   S)z&Return the absolute version of a path.)r   r/   r0   r_   getcwdbgetcwdr   r   )r1   cwdr2   r2   r3   r     s    c             C   sb   |  r. y t  |   }  WqX t k
 r* YqX Xn* t |  t  rL t j   }  n t j   }  t |   S)z&Return the absolute version of a path.)r   ra   r/   r0   r_   r   r   r   )r1   r2   r2   r3   r     s    getwindowsversionrQ   rP   c             C   s  t  |   } | t k r' t |   } n  |  s< t d   n  t t |   } t t |    } t |  \ } } t |  \ } } t |  t |  k r d j | |  }	 t |	   n  d d   | j	 |  D }
 d d   | j	 |  D } d } xC t
 |
 |  D]2 \ } } t |  t |  k r3Pn  | d 7} qWt |  t  rYd } n d	 } | g t |
  | | | d
  } | st |   St |   S)z#Return a relative version of a pathzno path specifiedz,path is on mount '{0}', start on mount '{1}'c             S   s   g  |  ] } | r |  q Sr2   r2   ).0xr2   r2   r3   
<listcomp>E  s   	 zrelpath.<locals>.<listcomp>c             S   s   g  |  ] } | r |  q Sr2   r2   )r   r   r2   r2   r3   r   F  s   	 r   rK   s   ..z..N)r5   r   r:   r   r   r   r   r   rE   r   zipr/   r0   rL   r   )r1   startr   Z	start_absZpath_absZstart_driveZ
start_restZ
path_driveZ	path_resterror
start_list	path_listrZ   Ze1Ze2r   rel_listr2   r2   r3   r%   2  s6    	%
   )_getfinalpathnamec             C   s   t  t |    S)N)r   r   )fr2   r2   r3   r   e  s    r   )_isdir)r   r   )4__doc__r_   rr   rc   r]   __all__r   r   r!   r   r   r    r   builtin_module_namesr"   r4   r5   r7   r8   r:   r=   rB   r   r   r   r   r   r   r   r^   r	   r
   r   r   ntrg   ImportErrorr   r   r   r   r   r   r#   hasattrr   r$   r%   r   rb   r   r   r2   r2   r2   r3   <module>   s   
	
#-1w)'
