Yf Y'@sdZddlZddlZddlZddlZddlTdddddd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*g'Zd+Zd,Zd+Zd-Z d.Z d/Z d0Z d1ej krd2Z d3Zd4d5Zd6dZd7dZd8dZd9dZd:dZd;dZd<d Zejje_d=d Zd>d Zd?dZd@dZyddAlmZWnek rdZYnXdBdZdCdZ dDdZ!dEdZ"yddFlm#Z#Wnek r2dGdZ$Yn XdHdZ$e$Z%e&edIogej'dJdKkZ(ddLd&Z)dMd*Z*y9ej'ddKdSkrddOlm+Z+neWn$e,efk rdPdQZ+YnXyddRlm-Z.Wnek r YnXdS)TzCommon pathname manipulations, WindowsNT/95 version. Instead of importing this module directly, import os and refer to this module as os.path. N)*normcaseisabsjoin splitdrivesplitsplitextbasenamedirname commonprefixgetsizegetmtimegetatimegetctimeislinkexistslexistsisdirisfileismount expanduser expandvarsnormpathabspathsplitunccurdirpardirseppathsepdefpathaltsepextsepdevnullrealpathsupports_unicode_filenamesrelpathsamefile sameopenfilesamestat commonpath.z..\;/z.;C:\binZcez\WindowsZnulcCst|trdSdSdS)Ns\/z\/) isinstancebytes)pathr1+/opt/alt/python35/lib64/python3.5/ntpath.py _get_bothseps#sr3c Csy?t|tr(|jddjS|jddjSWnIttfk rt|ttfstd|jjdYnXdS)zaNormalize case of pathname. Makes all characters lowercase and all slashes into backslashes./s\r-r+z0normcase() argument must be str or bytes, not %rN) r.r/replacelower TypeErrorAttributeErrorstr __class____name__)sr1r1r2r-scCs6t|d}t|dko5|dt|kS)zTest whether a path is absoluter)rlenr3)r<r1r1r2rCsc Gst|tr$d}d}d}nd}d}d}y5|sQ|dd|t|\}}x|D]}t|\}} | r| d|kr|s| r|}| }qjn?|r||kr|j|jkr|}| }qj|}|r|d |kr||}|| }qjW|rb|d|krb|rb|d d|krb|||S||SWn1tttfk rtjd ||YnXdS) Ns\s\/:r+z\/:rr=rrA) r.r/rr6r7r8 BytesWarning genericpath_check_arg_types) r0pathsrsepscolonZ result_driveZ result_pathpZp_driveZp_pathr1r1r2rJsD      cCstt|dkr`t|tr6d}d}d}nd}d}d}|j||}|dd|dkr,|dd |kr,|j|d}|d kr|d d|fS|j||d }||d kr|d d|fS|d krt|}|d |||d fS|d d|kr`|d d|dd fS|d d|fS)aSplit 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. s\r4r?r+r-r@rr=NrArA)r>r.r/r5find)rHrr rGZnormpindexZindex2r1r1r2rxs, 0   cCsaddl}|jdtdt|\}}t|dkrW|dd|fS||fS)aDeprecated 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 a UNC part. rNz)rHrMdriver0r1r1r2rs   cCst|}t|\}}t|}x(|rT||d|krT|d8}q-W|d|||d}}|j|p|}|||fS)z~Split a pathname. Return tuple (head, tail) where tail is everything after the final slash. Either part may be empty.r=N)r3rr>rstrip)rHrFdiheadtailr1r1r2rs  !cCs?t|tr%tj|dddStj|dddSdS)Ns\r4.r+r-r*)r.r/rC _splitext)rHr1r1r2rscCst|dS)z)Returns the final component of a pathnamer=)r)rHr1r1r2r scCst|dS)z-Returns the directory component of a pathnamer)r)rHr1r1r2r sc CsBytj|}Wnttfk r1dSYnXtj|jS)zhTest whether a path is a symbolic link. This will always return false for Windows prior to 6.0. F)oslstatOSErrorr8statS_ISLNKst_mode)r0str1r1r2rs  c Cs0ytj|}Wntk r+dSYnXdS)zCTest whether a path exists. Returns True for broken symbolic linksFT)rXrYrZ)r0r^r1r1r2rs   )_getvolumepathnamecCst|}t|}t|\}}|rQ|d|krQ| pP||kS||kradStr|j|t|j|kSdSdS)zaTest whether a path is a mount point (a drive root, the root of a share, or a mounted volume)rTFN)r3rrr_rQ)r0rFrootrestr1r1r2rs   "c Cset|trd}nd}|j|s1|Sdt|}}x0||krv||t|krv|d7}qGWdtjkrtjd}ntdtjkrtjd}nUdtjkr|Sytjd}Wntk rd}YnXt|tjd}t|tr(tj |}|dkrStt ||d|}|||d S) zLExpand ~ and ~user constructs. If user or $HOME is unknown, do nothing.~~r=HOMEZ USERPROFILEZHOMEPATHZ HOMEDRIVEN) r.r/ startswithr>r3rXenvironKeyErrorrfsencoder )r0tilderSnuserhomerPr1r1r2r0s0 %   cCst|trd|kr+d|kr+|Sddl}t|j|jdd}d}d}d}d }d}ttd d}ncd |krd |kr|Sddl}|j|jd}d }d }d}d}d }tj}|dd} d} t|} x | | kr|| | d} | |kr|| dd}t|} y/|j | } | | |d| d7} Wq t k r| | |7} | d} Yq XnQ| |kr|| d| d|kr| | 7} | d7} q || dd}t|} y|j |} Wn*t k rZ| ||7} | d} Yq X|d| } y<|dkrtj tjtj | }n || }Wn t k r|| |}YnX| |7} n4| |kr|| d| d|kr| | 7} | d7} q || d| d|kr|| dd}t|} y|j |} Wn.t k r| |||7} | d} YqX|d| } y<|dkrtj tjtj | }n || }Wn$t k r ||| |}YnX| |7} q |dd} | d7} || | d} x>| r| |kr| | 7} | d7} || | d} qKWy<|dkrtj tjtj | }n || }Wnt k r|| }YnX| |7} | r | d8} n | | 7} | d7} qW| S)zfExpand shell variables of the forms $var, ${var} and %var%. Unknown variables are left unchanged.$%rNz_-asciis'{}environb$%'{}r=rI)r.r/stringZ ascii_lettersZdigitsgetattrrXrgr>rL ValueErrorrifsdecoderh)r0rxZvarcharsZquoteZpercentZbraceZrbraceZdollarrgresrLZpathlencvarvaluer1r1r2ras              "        "      "    c Cst|tr0d}d}d}d}d}nd}d}d }d }d}|j|ra|S|j||}t|\}}|j|r||7}|j|}|j|}d }x|t|kr|| s|||kr||=q|||kr|d krN||d|krN||d|d=|d8}q|d krs|j|rs||=q|d7}q|d7}qW| r| r|j |||j |S)z0Normalize path, eliminating double slashes, etc.s\r4rVs..\\.\\\?\r+r-r*z..\\.\\\?\rr=)rr)rr) r.r/rfr5rlstriprr>endswithappendr) r0rr rrZspecial_prefixesprefixcompsrSr1r1r2rsD        )_getfullpathnamecCsOt|sEt|tr*tj}n tj}t||}t|S)z&Return the absolute version of a path.)rr.r/rXgetcwdbgetcwdrr)r0cwdr1r1r2rs   c Csb|r.yt|}WqXtk r*YqXXn*t|trLtj}n tj}t|S)z&Return the absolute version of a path.)rrZr.r/rXrrr)r0r1r1r2rs  getwindowsversionrJrIcCst|tr$d}d}d}nd}d}d}|dkrH|}|sZtdy4tt|}tt|}t|\}}t|\} } t|t| krtd | |fd d |j|D} d d | j|D} d } x@t| | D]/\}}t|t|krFP| d7} q!W|gt | | | | d}|s|St |SWn7t tt t tfk rtjd||YnXdS)z#Return a relative version of a paths\rVs..r+r*z..Nzno path specifiedz&path is on mount %r, start on mount %rcSsg|]}|r|qSr1r1).0xr1r1r2 @s zrelpath..cSsg|]}|r|qSr1r1)rrr1r1r2rAs rr=r%)r.r/rzrrrrrzipr>rr7r8rBrOrCrD)r0startrrrZ start_absZpath_absZ start_driveZ start_restZ path_driveZ path_rest start_list path_listrSZe1Ze2rel_listr1r1r2r%&sB   %c s(|stdt|dtr:dddndddyfd d |D}fd d |D}y&tfd d |D\}Wn!tk rtddYnXttdd |Ddkrtdt|dj\}}|j}fdd |D}fdd |D}t|}t |}xQt |D]-\} } | || kr|d| }PqW|dt|}|r|n|} | j |SWn+t t fk r#tjd|YnXdS)zDGiven a sequence of path names, returns the longest common sub-path.z%commonpath() arg is an empty sequencers\r4rVr+r-r*cs.g|]$}t|jjqSr1)rr5r6)rrH)r rr1r2rls zcommonpath..cs%g|]\}}|jqSr1)r)rrRrH)rr1r2rms c3s+|]!\}}|ddkVqdS)Nr=r1)rrRrH)rr1r2 pszcommonpath..z%Can't mix absolute and relative pathsNcss|]\}}|VqdS)Nr1)rrRrHr1r1r2rwsr=zPaths don't have the same drivecs(g|]}|r|kr|qSr1r1)rr})rr1r2r|s cs)g|]}fdd|DqS)cs(g|]}|r|kr|qSr1r1)rr})rr1r2r~s z)commonpath...r1)rr<)rr1r2r~s r))rzr.r/setr>rr5rminmax enumeraterr7r8rCrD) rEZ drivesplits split_pathsrrPr0commons1s2rSr}rr1)r rrr2r)\sD  & % "  )_getfinalpathnamecCstt|S)N)rr)fr1r1r2rsr)_isdir)rr)/__doc__rXsysr[rC__all__rrr!rrr rbuiltin_module_namesr"r3rrrrrrrrWr r rrntr_ ImportErrorrrrrrrr#hasattrrr$r%r)rr8rrr1r1r1r2s~        . 3          1 p 2  6 4