3 \=&@s^dZdZdZdZdZdZdZdZdZddl Z ddl Z ddl Z ddl Z dd l Td d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/g&Z d0d1Zd2d Zd3d Zd4d Zd5dZd6dZe jje_d7d Zd8dZd9dZd:dZd;dZddZd?dZd@d Z dAd,Z!dBdCZ"e j#dDkZ$dGdEd.Z%dFd/Z&dS)HaCommon 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. .z../:z:/bin:/usr/binNz /dev/null)*normcaseisabsjoin splitdrivesplitsplitextbasenamedirname commonprefixgetsizegetmtimegetatimegetctimeislinkexistslexistsisdirisfileismount expanduser expandvarsnormpathabspathsamefile sameopenfilesamestatcurdirpardirseppathsepdefpathaltsepextsepdevnullrealpathsupports_unicode_filenamesrelpath commonpathcCst|trdSdSdS)N/r) isinstancebytes)pathr0!/usr/lib64/python3.6/posixpath.py_get_sep)s r2cCs.tj|}t|ttfs*tdj|jj|S)z6Normalize case of pathname. Has no effect under Posixz2normcase() argument must be str or bytes, not '{}') osfspathr-r.str TypeErrorformat __class____name__)sr0r0r1r4s   cCstj|}t|}|j|S)zTest whether a path is absolute)r3r4r2 startswith)r:r"r0r0r1r@s c Gstj|}t|}|}yd|s,|dd|xJttj|D]:}|j|rN|}q:| s^|j|rh||7}q:|||7}q:WWn.tttfk rt j d|f|YnX|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.Nrr) r3r4r2mapr;endswithr6AttributeError BytesWarning genericpath_check_arg_types)apr"r/br0r0r1rKs    cCs`tj|}t|}|j|d}|d|||d}}|rX||t|krX|j|}||fS)zSplit a pathname. Returns tuple "(head, tail)" where "tail" is everything after the final slash. Either part may be empty.N)r3r4r2rfindlenrstrip)rCr"iheadtailr0r0r1r hs  cCs6tj|}t|trd}d}nd}d}tj||d|S)Nr,.rr)r3r4r-r.r@ _splitext)rCr"r&r0r0r1r ys  cCstj|}|dd|fS)zJSplit a pathname into drive and path. On Posix, drive is always empty.Nr)r3r4)rCr0r0r1r s cCs,tj|}t|}|j|d}||dS)z)Returns the final component of a pathnamerEN)r3r4r2rF)rCr"rIr0r0r1r s cCsNtj|}t|}|j|d}|d|}|rJ||t|krJ|j|}|S)z-Returns the directory component of a pathnamerEN)r3r4r2rFrGrH)rCr"rIrJr0r0r1r s   c Cs4ytj|}Wnttfk r&dSXtj|jS)z&Test whether a path is a symbolic linkF)r3lstatOSErrorr>statS_ISLNKst_mode)r/str0r0r1rs c Cs(ytj|Wntk r"dSXdS)zCTest whether a path exists. Returns True for broken symbolic linksFT)r3rNrO)r/r0r0r1rs cCsytj|}Wntk r"dSXtj|jr4dSt|trJt|d}n t|d}t |}ytj|}Wntk r~dSX|j }|j }||krdS|j }|j }||krdSdS)z$Test whether a path is a mount pointFs..z..T) r3rNrOrPrQrRr-r.rr(st_devst_ino)r/s1parents2dev1dev2ino1ino2r0r0r1rs.    c Cs4tj|}t|trd}nd}|j|s,|St|}|j|d}|dkrPt|}|dkrdtjkrddl }y|j tj j }Wqt k r|SXqtjd}nRddl }|d|}t|trt|d}y|j|}Wnt k r|SX|j }t|trtj|}d}nd }|j|}|||dp2|S) zOExpand ~ and ~user constructions. If user or $HOME is unknown, do nothing.~~rErHOMENASCIIr,r)r3r4r-r.r;r2findrGenvironpwdgetpwuidgetuidpw_dirKeyErrorr5getpwnamfsencoderH) r/tilder"rIrcuserhomenamepwentrootr0r0r1rsB            c Cs\tj|}t|trVd|kr |Sts:ddl}|jd|jatj}d}d}t tdd}n:d|krb|St s|ddl}|jd |ja t j}d }d }tj }d}x|||}|sP|j d\}}|j d } | j|r| j|r| d d } y.|dkrtjtj 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+|\{[^}]*\}){}rE)r3r4r-r. _varprogbrecompiler`searchgetattr_varprogrbspangroupr;r=rifsdecodergrG) r/rxrzstartendrbrImjrlvaluerKr0r0r1rsP          c Cstj|}t|tr&d}d}d}d}nd}d}d}d}||krB|S|j|}|rr|j|d rr|j|d  rrd }|j|}g}xV|D]N}|||fkrq||ks| r| s|r|d |kr|j|q|r|jqW|}|j|}|r|||}|p|S) z0Normalize path, eliminating double slashes, etc.r,rLs..rrz..rErv) r3r4r-r.r;r appendpopr) r/r"emptydotdotdotinitial_slashescomps new_compscompr0r0r1rRs>          cCs@tj|}t|s8t|tr&tj}ntj}t||}t|S)zReturn an absolute path.) r3r4rr-r.getcwdbgetcwdrr)r/cwdr0r0r1rxs    cCs*tj|}t|dd|i\}}t|S)zlReturn the canonical path of the specified filename, eliminating any symbolic links encountered in the path.Nr)r3r4 _joinrealpathr)filenamer/okr0r0r1r(s c Cst|trd}d}d}n d}d}d}t|r<|dd}|}x|r|j|\}}}| s>||krdq>||kr|rt|\}}||krt|||}q>|}q>t||}t|s|}q>||kr||}|dk rq>t||dfSd||<t|tj ||\}} | s t||dfS|||<q>W|d fS) Nr,rLs..rrz..rEFT) r-r.r partitionr rrrr3readlink) r/restseenr"r r!rl_newpathrr0r0r1rsH     rdarwinc Cs|s tdtj|}t|tr.d}d}d}n d}d}d}|dkrH|}n tj|}ynd d t|j|D}d d t|j|D}tt||g}|gt||||d}|s|St |St t t t fk rtjd ||YnXdS) z#Return a relative version of a pathzno path specifiedrLr,s..rrz..NcSsg|] }|r|qSr0r0).0xr0r0r1 szrelpath..cSsg|] }|r|qSr0r0)rrr0r0r1rsr*) ValueErrorr3r4r-r.rr rGrrr6r>r?DeprecationWarningr@rA) r/rr r"r! start_list path_listrIrel_listr0r0r1r*s0   c s2|s tdtttj|}t|dtr4ddnddyƇfdd|D}ytfd d |D\}Wntk rtd d YnXfd d|D}t|}t |}|}x.t |D]"\}}|||kr|d |}PqW|rn d d}|j |St t fk r,tjd|YnXd S)zDGiven a sequence of path names, returns the longest common sub-path.z%commonpath() arg is an empty sequencerr,rLrrcsg|]}|jqSr0)r )rr/)r"r0r1rszcommonpath..c3s|]}|ddkVqdS)NrEr0)rrC)r"r0r1 szcommonpath..z%Can't mix absolute and relative pathsNcsg|]}fdd|DqS)csg|]}|r|kr|qSr0r0)rc)r r0r1rsz)commonpath...r0)rr:)r r0r1rsr+)r+)rtupler<r3r4r-r.setminmax enumeraterr6r>r@rA) paths split_pathsrrVrXcommonrIrprefixr0)r r"r1r+s6  )N)'__doc__r r!r&r"r#r$r%r'r3sysrPr@__all__r2rrrr r rMr r r rrrrr|rwrrrr(rplatformr)r*r+r0r0r0r1 sZ           *25& 3  )