e f4%@sdZddlZddlZddlZddlZddlTdddddd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(g%Zd)Zd*Zd)Zd+Z d,Z d-Z dZ d.Z d/d0Zd1dZd2dZd3dZd4dZd5d Zejje_d6dZd7d Zd8d Zd9dZd:dZd;dZd<dZdadad=dZd>dZd?dZ d@d&Z!dAdBZ"ej#dCkZ$ddDd(Z%dS)EaCommon operations on Posix pathnames. Instead of importing this module directly, import os and refer to this module as os.path. The "os.path" name is an alias for this module on Posix systems; on other systems (e.g. Mac, Windows), os.path provides the same operations in a manner specific to that platform, and is an alias to another module (e.g. macpath, ntpath). Some of this can actually be useful on non-Posix systems too, e.g. for manipulation of the pathname component of URLs. N)*normcaseisabsjoin splitdrivesplitsplitextbasenamedirname commonprefixgetsizegetmtimegetatimegetctimeislinkexistslexistsisdirisfileismount expanduser expandvarsnormpathabspathsamefile sameopenfilesamestatcurdirpardirseppathsepdefpathaltsepextsepdevnullrealpathsupports_unicode_filenamesrelpath.z../:z:/bin:/usr/binz /dev/nullcCst|trdSdSdS)N/r)) isinstancebytes)pathr/./opt/alt/python34/lib64/python3.4/posixpath.py_get_sep&sr1cCs7t|ttfs3tdj|jjn|S)z6Normalize case of pathname. Has no effect under Posixz2normcase() argument must be str or bytes, not '{}')r,r-str TypeErrorformat __class____name__)sr/r/r0r1s cCst|}|j|S)zTest whether a path is absolute)r1 startswith)r7rr/r/r0r<s c Gst|}|}y^xW|D]O}|j|r:|}q| sP|j|r]||7}q|||7}qWWnGtk rtdd|f|DrtddnYnX|S)zJoin two or more pathname components, inserting '/' as needed. If any component is an absolute path, all previous path components will be discarded. An empty last part will result in a path that ends with a separator.css$|]}t|ttfVqdS)N)r,r2r-).0r7r/r/r0 Vszjoin..z.Can't mix strings and bytes in path componentsN)r1r8endswithr3all)aprr.br/r/r0rFs        cCsxt|}|j|d}|d|||d}}|rn||t|krn|j|}n||fS)zSplit a pathname. Returns tuple "(head, tail)" where "tail" is everything after the final slash. Either part may be empty.N)r1rfindlenrstrip)r>riheadtailr/r/r0rcs  !cCs@t|trd}d}n d}d}tj||d|S)Nr+.r)r()r,r- genericpath _splitext)r>rr#r/r/r0rss  cCs|dd|fS)zJSplit a pathname into drive and path. On Posix, drive is always empty.Nrr/)r>r/r/r0rscCs-t|}|j|d}||dS)z)Returns the final component of a pathnamer@N)r1rA)r>rrDr/r/r0r s cCsat|}|j|d}|d|}|r]||t|kr]|j|}n|S)z-Returns the directory component of a pathnamer@N)r1rArBrC)r>rrDrEr/r/r0r s  c CsBytj|}Wnttfk r1dSYnXtj|jS)z&Test whether a path is a symbolic linkF)oslstatOSErrorAttributeErrorstatS_ISLNKst_mode)r.str/r/r0rs  c Cs.ytj|Wntk r)dSYnXdS)zCTest whether a path exists. Returns True for broken symbolic linksFT)rJrKrL)r.r/r/r0rs   cCsytj|}Wntk r+dSYnXtj|jrBdSt|trct|d}nt|d}ytj|}Wntk rdSYnX|j }|j }||krdS|j }|j }||krdSdS)z$Test whether a path is a mount pointFs..z..T) rJrKrLrNrOrPr,r-rst_devst_ino)r.s1parents2dev1dev2ino1ino2r/r/r0rs,          c Cst|trd}nd}|j|s1|St|}|j|d}|dkrjt|}n|dkrdtjkrddl}|j tj j }q.tjd}nrddl}|d|}t|trt |d}ny|j |}Wntk r$|SYnX|j }t|trUtj|}d}nd }|j|}|||dp|S) zOExpand ~ and ~user constructions. If user or $HOME is unknown, do nothing.~~r@rHOMENASCIIr+r))r,r-r8r1findrBrJenvironpwdgetpwuidgetuidpw_dirr2getpwnamKeyErrorfsencoderC) r.tilderrDrauserhomenamepwentrootr/r/r0rs:          c Cst|trsd|kr|StsIddl}|jd|jantj}d}d}ttdd}nXd|kr|St sddl}|jd |ja nt j}d }d }tj }d}x|||}|sPn|j d\}}|j d } | j |rB| j|rB| d d } ny<|dkrstjtj tj| } n || } Wntk r|}YqX||d} |d|| }t|}|| 7}qW|S)zZExpand shell variables of form $var and ${var}. Unknown variables are left unchanged.$rNs\$(\w+|\{[^}]*\}){}environb$z\$(\w+|\{[^}]*\}){}r@)r,r- _varprogbrecompiler^searchgetattrrJ_varprogr`spangroupr8r;rgfsdecoderfrB) r.rvrxstartendr`rDmjrjvaluerFr/r/r0r sN        "   c Cs^t|tr*d}d}d}d}nd}d}d}d}||krR|S|j|}|r|j|d r|j|d  rd }n|j|}g}xy|D]q}|||fkrqn||ks| r| s|r|d |kr|j|q|r|jqqW|}|j|}|rT|||}n|p]|S) z0Normalize path, eliminating double slashes, etc.r+rGs..r)r(z..r@rt)r,r-r8rappendpopr) r.remptydotdotdotinitial_slashescomps new_compscompr/r/r0r>s<  '  cCsRt|sHt|tr*tj}n tj}t||}nt|S)zReturn an absolute path.)rr,r-rJgetcwdbgetcwdrr)r.cwdr/r/r0rcs   cCs,t|dd|i\}}t|S)zlReturn the canonical path of the specified filename, eliminating any symbolic links encountered in the path.Nr) _joinrealpathr)filenamer.okr/r/r0r%qs"c Cst|tr$d}d}d}nd}d}d}t|r[|dd}|}nx?|r|j|\}}}| s^||krq^n||kr|rt|\}}||krt|||}qq^|}q^nt||}t|s|}q^n||krK||}|dk r8q^nt||dfSd||s zrelpath..cSsg|]}|r|qSr/r/)r9rr/r/r0rs ) ValueErrorr,r-rrrBr r) r.r~rrr start_list path_listrDrel_listr/r/r0r's$   ""%)&__doc__rJsysrNrH__all__rrr#rr r!r"r$r1rrrrrrIrr r rrrrrzrurrrr%rplatformr&r'r/r/r/r0 sV           ) * 4 %   3