B Y6d=&@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 commonprefixZgetsizeZgetmtimeZgetatimeZgetctimeislinkexistslexistsisdirisfileismount expanduser expandvarsnormpathabspathZsamefileZ sameopenfilesamestatcurdirpardirseppathsepdefpathaltsepextsepdevnullrealpathsupports_unicode_filenamesrelpath commonpathcCst|trdSdSdS)N/r) isinstancebytes)pathr*%/usr/local/lib/python3.7/posixpath.py_get_sep)s r,cCs.t|}t|ttfs*td|jj|S)z6Normalize case of pathname. Has no effect under Posixz2normcase() argument must be str or bytes, not '{}') osfspathr'r(str TypeErrorformat __class____name__)sr*r*r+r4s   cCst|}t|}||S)zTest whether a path is absolute)r-r.r, startswith)r4rr*r*r+r@s c Gst|}t|}|}yb|s,|dd|xHttj|D]8}||rN|}q:|r\||rf||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) r-r.r,mapr5endswithr0AttributeError BytesWarning genericpath_check_arg_types)aprr)br*r*r+rKs    cCs`t|}t|}||d}|d|||d}}|rX||t|krX||}||fS)zSplit a pathname. Returns tuple "(head, tail)" where "tail" is everything after the final slash. Either part may be empty.N)r-r.r,rfindlenrstrip)r=riheadtailr*r*r+r hs  cCs6t|}t|trd}d}nd}d}t||d|S)Nr&.rr)r-r.r'r(r: _splitext)r=rr r*r*r+r ys  cCst|}|dd|fS)zJSplit a pathname into drive and path. On Posix, drive is always empty.Nr)r-r.)r=r*r*r+r s cCs,t|}t|}||d}||dS)z)Returns the final component of a pathnamer?N)r-r.r,r@)r=rrCr*r*r+r s cCsNt|}t|}||d}|d|}|rJ||t|krJ||}|S)z-Returns the directory component of a pathnamer?N)r-r.r,r@rArB)r=rrCrDr*r*r+r s   c Cs4yt|}Wnttfk r&dSXt|jS)z&Test whether a path is a symbolic linkF)r-lstatOSErrorr8statS_ISLNKst_mode)r)str*r*r+rs cCs(yt|Wntk r"dSXdS)zCTest whether a path exists. Returns True for broken symbolic linksFT)r-rHrI)r)r*r*r+rs cCsyt|}Wntk r"dSXt|jr4dSt|trJt|d}n t|d}t |}yt|}Wntk r~dSX|j }|j }||krdS|j }|j }||krdSdS)z$Test whether a path is a mount pointFs..z..T) r-rHrIrJrKrLr'r(rr"st_devst_ino)r)s1parents2Zdev1Zdev2Zino1Zino2r*r*r+rs.    c Cs4t|}t|trd}nd}||s,|St|}||d}|dkrPt|}|dkrdtjkrddl }y| t j }Wqt k r|SXqtjd}nRddl }|d|}t|trt|d}y||}Wnt k r|SX|j }t|trt|}d}nd }||}|||dp2|S) zOExpand ~ and ~user constructions. If user or $HOME is unknown, do nothing.~~r?rZHOMENASCIIr&r)r-r.r'r(r5r,findrAenvironpwdZgetpwuidgetuidZpw_dirKeyErrorr/ZgetpwnamfsencoderB) r)ZtilderrCrXZuserhomenameZpwentZrootr*r*r+rsB            c Cs\t|}t|trVd|kr |Sts:ddl}|d|jatj}d}d}t tdd}n:d|krb|St s|ddl}|d |ja t j}d }d }tj }d}x|||}|sP| d\}}| d } | |r| |r| d d } y.|dkrttj t| } 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.r'r( _varprogbrecompilerUsearchgetattr_varprogrWZspanZgroupr5r7r[fsdecoderZrA) r)rfrhstartendrWrCmjr\valuerEr*r*r+rsP          c Cst|}t|tr&d}d}d}d}nd}d}d}d}||krB|S||}|rp||d rp||d spd }||}g}xR|D]J}|||fkrq||ks|s|r|r|d |kr||q|r|qW|}||}|r|||}|p|S) z0Normalize path, eliminating double slashes, etc.r&rFs..rrz..rd) r-r.r'r(r5r appendpopr) r)rZemptydotZdotdotZinitial_slashesZcompsZ new_compsZcompr*r*r+rRs>          cCs@t|}t|s8t|tr&t}nt}t||}t|S)zReturn an absolute path.) r-r.rr'r(getcwdbgetcwdrr)r)Zcwdr*r*r+rxs    cCs*t|}t|dd|i\}}t|S)zlReturn the canonical path of the specified filename, eliminating any symbolic links encountered in the path.Nr)r-r. _joinrealpathr)filenamer)okr*r*r+r"s c Cst|trd}d}d}n d}d}d}t|r<|dd}|}x|r||\}}}|r>||krbq>||kr|rt|\}}||krt|||}q>|}q>t||}t|s|}q>||kr||}|dk rq>t||dfSd||<t|t ||\}} | st||dfS|||<q>W|d fS) Nr&rFs..rrz..r?FT) r'r(r partitionr rrrzr-readlink) r)restseenrrrr\_Znewpathr|r*r*r+rzsH      rzdarwinc Cs|s tdt|}t|tr.d}d}d}n d}d}d}|dkrH|}n t|}ynd d t||D}d d t||D}tt||g}|gt||||d}|s|St |St t t t fk rtd ||YnXdS) z#Return a relative version of a pathzno path specifiedrFr&s..rrz..NcSsg|] }|r|qSr*r*).0xr*r*r+ szrelpath..cSsg|] }|r|qSr*r*)rrr*r*r+rsr$) ValueErrorr-r.r'r(rr rArrr0r8r9DeprecationWarningr:r;) r)rlrrrZ start_list path_listrCZrel_listr*r*r+r$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}| |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&rFrrcsg|]}|qSr*)r )rr))rr*r+rszcommonpath..c3s|]}|ddkVqdS)Nr?r*)rr=)rr*r+ szcommonpath..z%Can't mix absolute and relative pathsNcsg|]}fdd|DqS)csg|]}|r|kr|qSr*r*)rc)rr*r+rsz)commonpath...r*)rr4)rr*r+rsr%)r%)rtupler6r-r.r'r(setminmax enumeraterr0r8r:r;) pathsZ split_pathsrrPrRZcommonrCrprefixr*)rrr+r%s6  )N)'__doc__rrr rrrrr!r-sysrJr:__all__r,rrrr r rGr r r rrrrrjrerrrr"rzplatformr#r$r%r*r*r*r+ sZ           *25& 3  )