3 \dh?'@sfdZdZdZdZdZdZdZdZdZddl 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/d0g'Z d1d2Zd3d Zd4d Zd5d Zd6dZd7dZe jje_d8d Zd9dZd:dZd;dZddZdadad?dZd@dZdAd Z dBdCdDd,Z!dEdFZ"e j#dGkZ$dJdHd.Z%dId/Z&dS)KaCommon 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 commonpath ALLOW_MISSINGcCst|trdSdSdS)N/r) isinstancebytes)pathr1!/usr/lib64/python3.6/posixpath.py_get_sep)s r3cCs.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__)sr1r1r2r4s   cCstj|}t|}|j|S)zTest whether a path is absolute)r4r5r3 startswith)r;r"r1r1r2r@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) r4r5r3mapr<endswithr7AttributeError BytesWarning genericpath_check_arg_types)apr"r0br1r1r2rKs    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)r4r5r3rfindlenrstrip)rDr"iheadtailr1r1r2r hs  cCs6tj|}t|trd}d}nd}d}tj||d|S)Nr-.rr)r4r5r.r/rA _splitext)rDr"r&r1r1r2r ys  cCstj|}|dd|fS)zJSplit a pathname into drive and path. On Posix, drive is always empty.Nr)r4r5)rDr1r1r2r s cCs,tj|}t|}|j|d}||dS)z)Returns the final component of a pathnamerFN)r4r5r3rG)rDr"rJr1r1r2r s cCsNtj|}t|}|j|d}|d|}|rJ||t|krJ|j|}|S)z-Returns the directory component of a pathnamerFN)r4r5r3rGrHrI)rDr"rJrKr1r1r2r s   c Cs4ytj|}Wnttfk r&dSXtj|jS)z&Test whether a path is a symbolic linkF)r4lstatOSErrorr?statS_ISLNKst_mode)r0str1r1r2rs c Cs(ytj|Wntk r"dSXdS)zCTest whether a path exists. Returns True for broken symbolic linksFT)r4rOrP)r0r1r1r2rs 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) r4rOrPrQrRrSr.r/rr(st_devst_ino)r0s1parents2dev1dev2ino1ino2r1r1r2rs.    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.~~rFrHOMENASCIIr-r)r4r5r.r/r<r3findrHenvironpwdgetpwuidgetuidpw_dirKeyErrorr6getpwnamfsencoderI) r0tilder"rJrduserhomenamepwentrootr1r1r2rsB            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+|\{[^}]*\}){}rF)r4r5r.r/ _varprogbrecompilerasearchgetattr_varprogrcspangroupr<r>rjfsdecoderhrH) r0ryr{startendrcrJmjrmvaluerLr1r1r2rsP          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-rMs..rrz..rFrw) r4r5r.r/r<r appendpopr) r0r"emptydotdotdotinitial_slashescomps new_compscompr1r1r2rRs>          cCs@tj|}t|s8t|tr&tj}ntj}t||}t|S)zReturn an absolute path.) r4r5rr.r/getcwdbgetcwdrr)r0cwdr1r1r2rxs    F)strictcCs,tj|}t|dd||i\}}t|S)zlReturn the canonical path of the specified filename, eliminating any symbolic links encountered in the path.Nr)r4r5 _joinrealpathr)filenamerr0okr1r1r2r(s c Cst|trd}d}d}nd}d}d}tj}|tkr8t}n|rBf}nt}d} t|rb|dd}|}x"|r|j|\} } }| sf| |krqf| |kr|rt |\}} | |krt |||}qf|}qft || } ytj | } Wn|k rd}YnXt j | j}|s | }qf| |krH|| }|dk r(qf|r:tj | nt | |dfSd|| <t|tj| ||\}}|s|t ||dfS||| <qfW|d fS) Nr-rMs..rrz..rFFT)r.r/r4rr,FileNotFoundErrorrPr partitionr rrOrQrRrSrreadlink)r0restrseenr"r r!r ignored_errormaxlinksrm_newpathrTis_linkrr1r1r2rsd           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 specifiedrMr-s..rrz..NcSsg|] }|r|qSr1r1).0xr1r1r2 szrelpath..cSsg|] }|r|qSr1r1)rrr1r1r2rsr*) ValueErrorr4r5r.r/rr rHrrr7r?r@DeprecationWarningrArB) r0rr r"r! start_list path_listrJrel_listr1r1r2r*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-rMrrcsg|]}|jqSr1)r )rr0)r"r1r2rszcommonpath..c3s|]}|ddkVqdS)NrFr1)rrD)r"r1r2 szcommonpath..z%Can't mix absolute and relative pathsNcsg|]}fdd|DqS)csg|]}|r|kr|qSr1r1)rc)r r1r2rsz)commonpath...r1)rr;)r r1r2rsr+)r+)rtupler=r4r5r.r/setminmax enumeraterr7r?rArB) paths split_pathsrrWrYcommonrJrprefixr1)r r"r2r+s6  )N)'__doc__r r!r&r"r#r$r%r'r4sysrQrA__all__r3rrrr r rNr r r rrrrr}rxrrrr(rplatformr)r*r+r1r1r1r2 sZ           *25& F  )