Yf@sPddlZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z mZmZddlmZddlmZmZmZmZmZmZmZddlmZdZejd krUddlZej dd d dfkrFdd lm!Z!n d ZdZ!ndZddddddgZ"ddZ#Gddde$Z%Gddde%Z&Gddde%Z'e&Z(e'Z)GdddZ*Gddde*Z+e+Z,e d d!Z-d"d#Z.e/ed$rDej0e.Z.Gd%d&d&Z1Gd'd(d(Z2Gd)d*d*e1Z3Gd+d,d,e1Z4Gd-d.d.e1Z5Gd/d0d0e Z6Gd1dde$Z7Gd2dde7Z8Gd3dde7Z9Gd4dde7Z:Gd5dde:e8Z;Gd6dde:e9Z<dS)7N)Sequence)contextmanager)EINVALENOENTENOTDIR) attrgetter)S_ISDIRS_ISLNKS_ISREGS_ISSOCKS_ISBLKS_ISCHRS_ISFIFO)quote_from_bytesTnt)_getfinalpathnameFPurePath PurePosixPathPureWindowsPathPath PosixPath WindowsPathcCs"d|kp!d|kp!d|kS)N*?[)patrr,/opt/alt/python35/lib64/python3.5/pathlib.py_is_wildcard_pattern&sr c@s:eZdZdZddZddZddZdS) _FlavourzPA flavour implements a particular (platform-specific) set of path semantics.cCs|jj|_dS)N)sepjoin)selfrrr__init__0sz_Flavour.__init__c Csg}|j}|j}d}}t|}x%|D]}|sDq5|r\|j||}|j|\}}} || krxpt| j|D].} | r| dkr|jtj| qWn(| r| dkr|jtj| |s|r5|sQxI|D]A}|sq |r3|j||}|j|d}|r Pq WPq5W|sb|rs|j|||j |||fS)N.r) r"altsepreversedreplace splitrootsplitappendsysinternreverse) r$partsZparsedr"r(drvrootitpartZrelxrrr parse_parts3s@          z_Flavour.parse_partscCs|r8| r|r||||g|ddfSn_|r||ksh|j||j|kr||||ddfSn||||fS|||fS)z Join the two paths represented by the respective (drive, root, parts) tuples. Return a new (drive, root, parts) tuple. N)casefold)r$r2r3r1Zdrv2Zroot2Zparts2rrrjoin_parsed_partsYs %*z_Flavour.join_parsed_partsN)__name__ __module__ __qualname____doc__r%r7r:rrrrr!,s   &r!c@sWeZdZdZdZdZeZej dkZ e dde e de dd De d de e d e d d DBZd Zddddhdde d dDBdde d dDBZeddZddZddZddZeddZd d!Zd"d#Zd$d%Zd&d'Zd(S))_WindowsFlavour\/Trccs|]}t|VqdS)N)chr).0r6rrr wsz_WindowsFlavour.azr8ccs|]}t|VqdS)N)rB)rCr6rrrrDxsAZz\\?\ZCONZPRNZAUXZNULcCsh|]}d|qS)zCOM%dr)rCirrr ~s z_WindowsFlavour. cCsh|]}d|qS)zLPT%dr)rCrIrrrrJs c Cs|dd}|dd}||krp||krp|j|\}}|dd}|dd}nd}|dd}||krZ||krZ||krZ|j|d}|dkrZ|j||d}||dkrZ|dkrt|}|r5||d||||ddfS|d||||ddfSd} } |dkr||jkr|dd} |dd}|}||kr|} |j|}|| | |fS) Nrr8rr&:rN)_split_extended_pathfindlen drive_letterslstrip) r$r5r"firstsecondprefixZthirdindexZindex2r2r3rrrr+s6$   )%  z_WindowsFlavour.splitrootcCs |jS)N)lower)r$srrrr9sz_WindowsFlavour.casefoldcCsdd|DS)NcSsg|]}|jqSr)rX)rCprrr s z2_WindowsFlavour.casefold_parts..r)r$r1rrrcasefold_partssz_WindowsFlavour.casefold_partscCs?t|}|stjStdk r;|jt|SdS)N)strosgetcwdr_ext_to_normal)r$pathrYrrrresolves    z_WindowsFlavour.resolvecCsvd}|j|rl|dd}|dd}|jdrl||dd7}d|dd}||fS)Nr&zUNC\rLr@) startswith)r$rYZ ext_prefixrVrrrrOsz$_WindowsFlavour._split_extended_pathcCs|j|dS)Nr8)rO)r$rYrrrr`sz_WindowsFlavour._ext_to_normalcCsE|s dS|djdr!dS|djddj|jkS)NFrz\\r8r'rN)rd partitionupperreserved_names)r$r1rrr is_reserveds z_WindowsFlavour.is_reservedcCs|j}t|dkrg|ddkrg|jddjd}d|t|jdfSdt|jjdSdS)Nrr8rMrAz file:///%s/%szutf-8zfile:)driverQas_posixrSurlquote_from_bytesencode)r$rarirestrrrmake_uris  "z_WindowsFlavour.make_uric CsAdtjkrtjd}nzdtjkr>tjd}n[dtjkrytjd}Wntk rxd}YnX|tjd}n td|r=tjd|kr=|j|f\}}}|d tjdkrtd |||d <|s |r.|||j|dd}n|j|}|S) NHOMEZ USERPROFILEZHOMEPATHZ HOMEDRIVEr&zCan't determine home directoryZUSERNAMEr8z%Can't determine home directory for %rrNrN)r^environKeyError RuntimeErrorr7r#)r$usernameuserhomer2r3r1rrr gethomedirs,      $z_WindowsFlavour.gethomedirN)r;r<r=r"r(has_drvntpathpathmodr^name is_supportedsetrangeordrRZext_namespace_prefixrgr+r9r\rbrOr`rhrnrurrrrr?ks& /3) '     r?c@seZdZdZdZdZeZej dkZ eddZ ddZ d d Z d d Zd dZddZddZdS) _PosixFlavourrAr&FrcCss|rb|d|krb|j|}t|t|dkrRd|d|fSd||fSn dd|fSdS)Nrrr&)rSrQ)r$r5r"Z stripped_partrrrr+ s z_PosixFlavour.splitrootcCs|S)Nr)r$rYrrrr9sz_PosixFlavour.casefoldcCs|S)Nr)r$r1rrrr\sz_PosixFlavour.casefold_partscsj|j|jifdd|jrEdn tj}|t|piS)Ncs)|jrd}x |jD]}| s%|dkrAq%|dkrh|j\}}}q%||}|kr|}|dk rq%td|yj|}Wn=tk r}z|jtkr|}WYdd}~Xq%Xd|<||}||._resolver&)r" _accessor is_absoluter^r_r])r$rabaser)rrrr"rrb s   %z_PosixFlavour.resolvecCsdS)NFr)r$r1rrrrhLsz_PosixFlavour.is_reservedcCst|}dt|S)Nzfile://)bytesrk)r$raZbpathrrrrnOs z_PosixFlavour.make_uric Cs|sOytjdSWqtk rKddl}|jtjjSYqXnEddl}y|j|jSWn"tk rtd|YnXdS)Nrorz%Can't determine home directory for %r) r^rprqpwdgetpwuidgetuidpw_dirgetpwnamrr)r$rsrrrrruUs    z_PosixFlavour.gethomedirN)r;r<r=r"r(rv posixpathrxr^ryrzr+r9r\rbrhrnrurrrrr~s    ,  r~c@seZdZdZdS) _AccessorzjAn accessor implements a particular (system-specific or not) way of accessing paths on the filesystem.N)r;r<r=r>rrrrris rc@sEeZdZddZddZeejZeejZeejZeej Z eej Z e edreej Z n ddZ eej Z eejZeejZeejZeejZerereejZq&dd Zned d ZeejZd d Zd S)_NormalAccessorcs+tjfdd}t|S)Ncst||S)N)r])pathobjargs)strfuncrrwrappedqsz._NormalAccessor._wrap_strfunc..wrapped) functoolswraps staticmethod)rrr)rr _wrap_strfuncps!z_NormalAccessor._wrap_strfunccs+tjfdd}t|S)Ncst|t||S)N)r])ZpathobjAZpathobjBr)rrrrwsz5_NormalAccessor._wrap_binary_strfunc..wrapped)rrr)rrr)rr_wrap_binary_strfuncvs!z$_NormalAccessor._wrap_binary_strfunclchmodcCstddS)Nz%lchmod() not available on this system)NotImplementedError)r$rmoderrrrsz_NormalAccessor.lchmodcCstddS)Nz&symlink() not available on this system)r)rEbtarget_is_directoryrrrsymlinksz_NormalAccessor.symlinkcCstjt|t|S)N)r^rr])rErrrrrrscCs tj|S)N)r^r)r$rarrrrsz_NormalAccessor.readlinkN)r;r<r=rrr^statlstatopenlistdirchmodhasattrrmkdirunlinkrmdirrenamer*rsupports_symlinksrrutimerrrrrrns,    rc#sdyjVWnMtk r_ifdd}d|_z |VWdjXYnXdS)Nc s=y |SWn*tk r8|}|<|SYnXdS)N)rq)rvalue)cachefuncrrwrappers   z_cached..wrapperT) __cached__AttributeErrorclear)rrr)rrr_cacheds    rcCsr|d}|dd}|dkr/t}n6d|krJtdnt|r_t}nt}|||S)Nrr8z**z:Invalid pattern: '**' can only be an entire path component)_RecursiveWildcardSelector ValueErrorr _WildcardSelector_PreciseSelector) pattern_partsr child_partsclsrrr_make_selectors      r lru_cachec@s.eZdZdZddZddZdS) _SelectorzYA selector matches a specific glob pattern part against the children of a given path.cCs1||_|r!t||_n t|_dS)N)rr successor_TerminatingSelector)r$rrrrr%s z_Selector.__init__cCs@t|}|j}|j}|jj}|j||||S)zuIterate over all child paths of `parent_path` matched by this selector. This can contain parent_path itself.)typeis_direxistsrr _select_from)r$ parent_pathZpath_clsrrrrrr select_froms     z_Selector.select_fromN)r;r<r=r>r%rrrrrrs  rc@seZdZddZdS)rccs |VdS)Nr)r$rrrrrrrrsz!_TerminatingSelector._select_fromN)r;r<r=rrrrrrs rc@s(eZdZddZddZdS)rcCs||_tj||dS)N)ryrr%)r$ryrrrrr%s z_PreciseSelector.__init__c cszy]||sdS|j|j}||r\x(|jj||||D] }|VqMWWntk rudSYnXdS)N)_make_child_relpathryrrPermissionError)r$rrrrrarZrrrrs  "  z_PreciseSelector._select_fromN)r;r<r=r%rrrrrrs  rc@s(eZdZddZddZdS)rcCs/tjtj||_tj||dS)N)recompilefnmatch translaterrr%)r$rrrrrr%sz_WildcardSelector.__init__c csy||sdS|jj}xl||D]^}||}|jj|r,|j|}x(|jj||||D] } | Vq{Wq,WWntk rdSYnXdS)N)_flavourr9rmatchrrrr) r$rrrrcfryZ casefoldedrarZrrrrs   " z_WildcardSelector._select_fromN)r;r<r=r%rrrrrrs  rc@s4eZdZddZddZddZdS)rcCstj||dS)N)rr%)r$rrrrrr%sz#_RecursiveWildcardSelector.__init__c cs|Vyhxa||D]S}|j|}||r|j rx"|j|||D] }|VqYWqWWntk rdSYnXdS)N)r is_symlink_iterate_directoriesr)r$rrrryrarZrrrrs z/_RecursiveWildcardSelector._iterate_directoriesc csy||sdSt|}t}zn|jj}x[|j|||D]D}x;|||||D]$}||krl|V|j|qlWqPWWd|jXWdQRXWntk rdSYnXdS)N)rr{rrraddrr) r$rrrrZyieldedZsuccessor_selectZstarting_pointrZrrrr's     z'_RecursiveWildcardSelector._select_fromN)r;r<r=r%rrrrrrrs   rc@sLeZdZdZdZddZdd Zd d Zd d ZdS) _PathParentszvThis object provides sequence-like access to the logical ancestors of a path. Don't try to construct it yourself._pathcls_drv_root_partscCs7t||_|j|_|j|_|j|_dS)N)rrrrr)r$rarrrr%Cs  z_PathParents.__init__cCs4|js|jr#t|jdSt|jSdS)Nr8)rrrQr)r$rrr__len__Jsz_PathParents.__len__cCsX|dks|t|kr*t||jj|j|j|jd| dS)Nrr8)rQ IndexErrorr_from_parsed_partsrrr)r$idxrrr __getitem__Ps z_PathParents.__getitem__cCsdj|jjS)Nz <{}.parents>)formatrr;)r$rrr__repr__Vsz_PathParents.__repr__N)rrrr) r;r<r=r> __slots__r%rrrrrrrr>s    rc@s\eZdZdZdXZd d Zd d Zed dZedddZ edddZ eddZ ddZ ddZ ddZddZddZd d!Zd"d#Zed$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zeedd2d3Zeedd2d4Zed5d6Zed7d8Zed9d:Z ed;d<Z!ed=d>Z"d?d@Z#dAdBZ$dCdDZ%edEdFZ&dGdHZ'dIdJZ(dKdLZ)edMdNZ*edOdPZ+dQdRZ,dSdTZ-dUdVZ.dWS)YraHPurePath represents a filesystem path and offers operations which don't imply any actual filesystem I/O. Depending on your system, instantiating a PurePath will return either a PurePosixPath or a PureWindowsPath object. You can also instantiate either of these classes directly, regardless of your system. rrr_str_hash_pparts_cached_cpartscGs4|tkr'tjdkr!tnt}|j|S)zConstruct a PurePath from one or several strings and or existing PurePath objects. The strings and path objects are combined so as to yield a canonicalized path, which is incorporated into the new PurePath object. r)rr^ryrr _from_parts)rrrrr__new__fs zPurePath.__new__cCs|jt|jfS)N) __class__tupler)r$rrr __reduce__pszPurePath.__reduce__cCsg}xh|D]`}t|tr2||j7}q t|trW|jt|q tdt|q W|jj|S)Nz/argument should be a path or str object, not %r) isinstancerrr]r- TypeErrorrrr7)rrr1rErrr _parse_argsus zPurePath._parse_argsTcCsVtj|}|j|\}}}||_||_||_|rR|j|S)N)objectrrrrr_init)rrinitr$r2r3r1rrrrs    zPurePath._from_partscCs>tj|}||_||_||_|r:|j|S)N)rrrrrr)rr2r3r1rr$rrrrs    zPurePath._from_parsed_partscCsB|s |r.|||jj|ddS|jj|SdS)Nr8)rr#)rr2r3r1rrr_format_parsed_partss "zPurePath._format_parsed_partscCsdS)Nr)r$rrrrszPurePath._initcCs^|j|\}}}|jj|j|j|j|||\}}}|j|||S)N)rrr:rrrr)r$rr2r3r1rrr _make_childs *zPurePath._make_childc CsRy |jSWn@tk rM|j|j|j|jp<d|_|jSYnXdS)z[Return the string representation of the path, suitable for passing to system calls.r'N)rrrrrr)r$rrr__str__s   zPurePath.__str__cCs"|j}t|j|jdS)zNReturn the string representation of the path with forward (/) slashes.rA)rr]r*r")r$frrrrjs zPurePath.as_posixcCstjt|S)zaReturn the bytes representation of the path. This is only recommended to use under Unix.)r^fsencoder])r$rrr __bytes__szPurePath.__bytes__cCsdj|jj|jS)Nz{}({!r}))rrr;rj)r$rrrrszPurePath.__repr__cCs(|jstd|jj|S)z Return the path as a 'file' URI.z.relative path can't be expressed as a file URI)rrrrn)r$rrras_uris  zPurePath.as_uric CsCy |jSWn1tk r>|jj|j|_|jSYnXdS)N)rrrr\r)r$rrr_cpartss   zPurePath._cpartscCs5t|tstS|j|jko4|j|jkS)N)rrNotImplementedrr)r$otherrrr__eq__szPurePath.__eq__c CsCy |jSWn1tk r>tt|j|_|jSYnXdS)N)rrhashrr)r$rrr__hash__s   zPurePath.__hash__cCs6t|t s"|j|jk r&tS|j|jkS)N)rrrrr)r$rrrr__lt__s"zPurePath.__lt__cCs6t|t s"|j|jk r&tS|j|jkS)N)rrrrr)r$rrrr__le__s"zPurePath.__le__cCs6t|t s"|j|jk r&tS|j|jkS)N)rrrrr)r$rrrr__gt__s"zPurePath.__gt__cCs6t|t s"|j|jk r&tS|j|jkS)N)rrrrr)r$rrrr__ge__s"zPurePath.__ge__docz.The drive prefix (letter or UNC path), if any.zThe root of the path, if any.cCs|j|j}|S)z/The concatenation of the drive and root, or ''.)rr)r$anchorrrrrszPurePath.anchorcCs?|j}t||js$|jr*dndkr7dS|dS)z!The final path component, if any.r8rr&rN)rrQrr)r$r1rrrrys *z PurePath.namecCsT|j}|jd}d|ko9t|dknrL||dSdSdS)z*The final component's last suffix, if any.r'rr8Nr&)ryrfindrQ)r$ryrIrrrsuffix s  &zPurePath.suffixcCsO|j}|jdrgS|jd}dd|jdddDS)z1A list of the final component's suffixes, if any.r'cSsg|]}d|qS)r'r)rCrrrrr[s z%PurePath.suffixes..r8N)ryendswithrSr,)r$ryrrrsuffixess  zPurePath.suffixescCsT|j}|jd}d|ko9t|dknrL|d|S|SdS)z0The final path component, minus its last suffix.r'rr8N)ryrrQ)r$ryrIrrrstems  &z PurePath.stemcCs|jstd|f|jj|f\}}}| s|d|jj|jjgks|s|st|dkrtd||j|j|j |j dd|gS)z-Return a new path with the file name changed.z%r has an empty namer8zInvalid name %rNrNrN) ryrrr7r"r(rQrrrr)r$ryr2r3r1rrr with_name&s )zPurePath.with_namecCs|j}|j|ks0|jr@|j|kr@td||rV|jd sb|dkrrtd||j}|std|f|j}|s||}n|dt| |}|j|j |j |j dd|gS)zCReturn a new path with the file suffix changed (or added, if none).zInvalid suffix %rr'z%r has an empty nameNr8rN) rr"r(rrdryrrQrrrr)r$rrryZ old_suffixrrr with_suffix1s '"   zPurePath.with_suffixc GsQ|std|j}|j}|j}|rP||g|dd}n|}|j|\}}}|r||g|dd} n|} t| } |jj} | dkr|p|n| |d| | | kr"|j|||} t dj t |t | |j d| dkr=|nd|| dS)zReturn the relative path to another path identified by the passed arguments. If the operation is not possible (because this is not a subpath of the other path), raise ValueError. zneed at least one argumentr8Nrz{!r} does not start with {!r}r&) rrrrrrQrr\rrrr]r) r$rr1r2r3Z abs_partsZto_drvZto_rootZto_partsZ to_abs_partsnrZ formattedrrr relative_toDs(       : zPurePath.relative_toc Cs=y |jSWn+tk r8t|j|_|jSYnXdS)zZAn object providing sequence-like access to the components in the filesystem path.N)rrrr)r$rrrr1ds   zPurePath.partscGs |j|S)zCombine this path with one or several arguments, and return a new path representing either a subpath (if all arguments are relative paths) or a totally different path (if one of the arguments is anchored). )r)r$rrrrjoinpathpszPurePath.joinpathcCs|j|fS)N)r)r$keyrrr __truediv__xszPurePath.__truediv__cCs|j|g|jS)N)rr)r$rrrr __rtruediv__{szPurePath.__rtruediv__cCsZ|j}|j}|j}t|dkr=|s9|r=|S|j|||ddS)zThe logical parent of the path.r8NrN)rrrrQr)r$r2r3r1rrrparent~s    zPurePath.parentcCs t|S)z*A sequence of this path's logical parents.)r)r$rrrparentsszPurePath.parentscCs'|js dS|jj p&t|jS)zSTrue if the path is absolute (has both a root and, if applicable, a drive).F)rrrvboolr)r$rrrrs zPurePath.is_absolutecCs|jj|jS)zaReturn True if the path contains one of the special names reserved by the system, if any.)rrhr)r$rrrrhszPurePath.is_reservedc Cs,|jj}||}|jj|f\}}}|sHtd|rg|||jkrgdS|r|||jkrdS|j}|s|rt|t|krdS|dd}nt|t|krdSx?tt |t |D]"\}}t j ||sdSqWdS)zE Return True if this path matches the given pattern. z empty patternFr8NT) rr9r7rrrrrQzipr)rZ fnmatchcase) r$Z path_patternrr2r3Z pat_partsr1r5rrrrrs(     (zPurePath.matchN)rrrrrrr)/r;r<r=r>rrr classmethodrrrrrrrrjrrrpropertyrrrrrrrrrir3rryrr r r r rr1rrrrrrrhrrrrrrZs\                            c@seZdZeZfZdS)rN)r;r<r=_posix_flavourrrrrrrrs c@seZdZeZfZdS)rN)r;r<r=_windows_flavourrrrrrrrs c@s\eZdZd`ZddZdddZdd Zd d Zd d ZddZ dddZ dddZ e ddZ e ddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,dadddd.d/Zd0d1Zddd2d3Zd4d5Zddd6d7Zdd8d9d:Zdd;d;d<d=Zd>d?Zd@dAZ dBdCZ!dDdEZ"dFdGZ#dHdIZ$dJdKZ%d;dLdMZ&dNdOZ'dPdQZ(dRdSZ)dTdUZ*dVdWZ+dXdYZ,dZd[Z-d\d]Z.d^d_Z/dS)brr_closedcOsl|tkr'tjdkr!tnt}|j|dd}|jjs^td|j f|j |S)NrrFz$cannot instantiate %r on your system) rr^ryrrrrrzrr;r)rrkwargsr$rrrrs   z Path.__new__NcCs1d|_|dk r$|j|_n t|_dS)NF)rr_normal_accessor)r$templaterrrrs  z Path._initcCs)|j|g}|j|j|j|S)N)rrrr)r$r5r1rrrrszPath._make_child_relpathcCs|jr|j|S)N)r _raise_closed)r$rrr __enter__s  zPath.__enter__cCs d|_dS)NT)r)r$tvtbrrr__exit__sz Path.__exit__cCstddS)NzI/O operation on closed path)r)r$rrrrszPath._raise_closedicCs|jj|||S)N)rr)r$ryflagsrrrr_openersz Path._openericCs)|jr|j|jj|||S)zm Open the file pointed by this path and return a file descriptor, as os.open() does. )rrrr)r$r%rrrr _raw_opens  zPath._raw_opencCs|tjS)zjReturn a new path pointing to the current working directory (as returned by os.getcwd()). )r^r_)rrrrcwdszPath.cwdcCs||jjdS)zrReturn a new path pointing to the user's home directory (as returned by os.path.expanduser('~')). N)rru)rrrrhomesz Path.homec CsS|j}y|j}Wn!tk r?tj|}YnXtjj||S)zoReturn whether other_path is the same or not as this file (as returned by os.path.samefile()). )rrr^rasamestat)r$Z other_pathstZother_strrrsamefiles   z Path.samefileccsd|jr|jxJ|jj|D]6}|dkr;q&|j|V|jr&|jq&WdS)zyIterate over the files in this directory. Does not yield any result for the special paths '.' and '..'. r'..N>r'r-)rrrrr)r$ryrrriterdirs    z Path.iterdirccs|stdj||jj|}|jj|f\}}}|sW|rctdtt|}x|j|D] }|VqWdS)zIterate over this subtree and yield all existing files (of any kind, including directories) matching the given pattern. zUnacceptable pattern: {!r}z%Non-relative patterns are unsupportedN) rrrr9r7rrrr)r$patternr2r3rselectorrZrrrglob!s  z Path.globccs|jj|}|jj|f\}}}|s<|rHtdtdt|}x|j|D] }|VqnWdS)zRecursively yield all existing files (of any kind, including directories) matching the given pattern, anywhere in this subtree. z%Non-relative patterns are unsupported**N)r2)rr9r7rrrr)r$r/r2r3rr0rZrrrrglob/s  z Path.rglobcCs\|jr|j|jr#|S|jtjg|jdd}|jd||S)aReturn an absolute version of this path. This function works even if the path doesn't point to anything. No normalization is done, i.e. all '.' and '..' will be kept along. Use resolve() to get the canonical path to a file. rFr)rrrrr^r_rr)r$objrrrabsolute;s   %z Path.absolutecCs|jr|j|jj|}|dkrM|jt|j}|jjj|}|j |fdd}|j d||S)z Make the path absolute, resolving all symlinks on the way and also normalizing it (for example turning slashes into backslashes under Windows). NrFr) rrrrbrr]r5rxnormpathrr)r$rYZnormedr4rrrrbMs    z Path.resolvecCs|jj|S)zh Return the result of the stat() system call on this path, like os.stat() does. )rr)r$rrrrasz Path.statcCs%ddl}|j|jjjS)z: Return the login name of the file owner. rN)rrrst_uidZpw_name)r$rrrrownerhs z Path.ownercCs%ddl}|j|jjjS)z8 Return the group name of the file gid. rN)grpZgetgrgidrst_gidZgr_name)r$r9rrrgroupos z Path.grouprr8c Cs>|jr|jtjt||||||d|jS)z| Open the file pointed by this path and return a file object, as the built-in open() function does. Zopener)rriorr]r&)r$r bufferingencodingerrorsnewlinerrrrvs  !z Path.openc Cs*|jdd}|jSWdQRXdS)zK Open the file in bytes mode, read it, and close the file. rrbN)rread)r$rrrr read_bytesszPath.read_bytesc Cs6|jddd|d|}|jSWdQRXdS)zJ Open the file in text mode, read it, and close the file. rr<r?r@N)rrC)r$r?r@rrrr read_texts!zPath.read_textc Cs9t|}|jdd}|j|SWdQRXdS)zO Open the file in bytes mode, write to it, and close the file. rwbN) memoryviewrwrite)r$dataZviewrrrr write_bytess zPath.write_bytesc Cs^t|ts%td|jj|jddd|d|}|j|SWdQRXdS)zN Open the file in text mode, write to it, and close the file. zdata must be str, not %srwr?r@N)rr]rrr;rrH)r$rIr?r@rrrr write_texts !zPath.write_textTc Cs|jr|j|rIy|jj|dWntk rDYnXdStjtjB}|sl|tjO}|j ||}tj |dS)zS Create this file with the given access mode, if it doesn't exist. N) rrrrrr^O_CREATO_WRONLYO_EXCLr'close)r$rexist_okr%fdrrrtouchs    z Path.touchFc Cs|jr|jy|jj||Wntk r| sP|j|krS|jjdddd|j|ddd|Yn)tk r| s|j rYnXdS)z< Create a new directory at this given path. rTrQFN)rrrrFileNotFoundErrorrrr)r$rrrQrrrrs    z Path.mkdircCs*|jr|j|jj||dS)zF Change the permissions of the path, like os.chmod(). N)rrrr)r$rrrrrs  z Path.chmodcCs*|jr|j|jj||dS)z Like chmod(), except if the path points to a symlink, the symlink's permissions are changed, rather than its target's. N)rrrr)r$rrrrrs  z Path.lchmodcCs'|jr|j|jj|dS)zd Remove this file or link. If the path is a directory, use rmdir() instead. N)rrrr)r$rrrrs  z Path.unlinkcCs'|jr|j|jj|dS)zF Remove this directory. The directory must be empty. N)rrrr)r$rrrrs  z Path.rmdircCs#|jr|j|jj|S)z Like stat(), except if the path points to a symlink, the symlink's status information is returned, rather than its target's. )rrrr)r$rrrrs  z Path.lstatcCs*|jr|j|jj||dS)z5 Rename this path to the given path. N)rrrr)r$rrrrrs  z Path.renamecCs*|jr|j|jj||dS)zo Rename this path to the given path, clobbering the existing destination if it exists. N)rrrr*)r$rrrrr*s  z Path.replacecCs-|jr|j|jj|||dS)z Make this path a symlink pointing to the given path. Note the order of arguments (self, target) is the reverse of os.symlink's. N)rrrr)r$rrrrr symlink_tos  zPath.symlink_tocCsVy|jWnAtk rQ}z!|jttfkr;dSWYdd}~XnXdS)z+ Whether this path exists. FNT)rrrrr)r$rrrrrsz Path.existscCs_yt|jjSWnAtk rZ}z!|jttfkrDdSWYdd}~XnXdS)z3 Whether this path is a directory. FN)rrst_moderrrr)r$rrrrrs z Path.is_dircCs_yt|jjSWnAtk rZ}z!|jttfkrDdSWYdd}~XnXdS)zq Whether this path is a regular file (also True for symlinks pointing to regular files). FN)r rrVrrrr)r$rrrris_file,s z Path.is_filecCs_yt|jjSWnAtk rZ}z!|jttfkrDdSWYdd}~XnXdS)z7 Whether this path is a symbolic link. FN)r rrVrrrr)r$rrrrr:s zPath.is_symlinkcCs_yt|jjSWnAtk rZ}z!|jttfkrDdSWYdd}~XnXdS)z6 Whether this path is a block device. FN)r rrVrrrr)r$rrrris_block_deviceFs zPath.is_block_devicecCs_yt|jjSWnAtk rZ}z!|jttfkrDdSWYdd}~XnXdS)z: Whether this path is a character device. FN)r rrVrrrr)r$rrrris_char_deviceSs zPath.is_char_devicecCs_yt|jjSWnAtk rZ}z!|jttfkrDdSWYdd}~XnXdS)z. Whether this path is a FIFO. FN)rrrVrrrr)r$rrrris_fifo`s z Path.is_fifocCs_yt|jjSWnAtk rZ}z!|jttfkrDdSWYdd}~XnXdS)z0 Whether this path is a socket. FN)r rrVrrrr)r$rrrr is_socketms zPath.is_socketcCs|jp|j r}|jr}|jddddkr}|jj|jddd}|j|g|jddS|S)zl Return a new path with expanded ~ and ~user constructs (as returned by os.path.expanduser) rNr8~)rrrrrur)r$Zhomedirrrr expanduserzs &#!zPath.expanduser)rrrN)0r;r<r=rrrrr r$rr&r'rr(r)r,r.r1r3r5rbrr8r;rrDrErJrLrSrrrrrrrr*rUrrrWrrXrYrZr[r]rrrrrs\                        c@seZdZfZdS)rN)r;r<r=rrrrrrs c@s.eZdZfZddZddZdS)rcCstddS)Nz*Path.owner() is unsupported on this system)r)r$rrrr8szWindowsPath.ownercCstddS)Nz*Path.group() is unsupported on this system)r)r$rrrr;szWindowsPath.groupN)r;r<r=rr8r;rrrrrs  )=rrr=rwr^rrr. collectionsr contextlibrrrrroperatorrrrr r r r r rZ urllib.parserrkrryrZgetwindowsversionr__all__r rr!r?r~rrrrrrrrrrrrrrrrrrrrrrrrrsd        4 "   ?b  ;  'Z