3 O`!@s|ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z y ddl Z Wne k rxddl Z YnXddl mZmZddlmZddlmZmZmZddlmZmZddlmZddlmZmZmZyddlm Z!m Z"Wn&e k rdd l#m Z!m$Z"YnXd Z%y ddl&Z&Wne k r@dZ&Yn:Xej'dd dAkrrej(dBkrrddl&m)Z)ndZ%dZ)ddddddgZ*ddZ+Gddde,Z-Gddde-Z.dZ/Gddde-Z0e.Z1e0Z2ee3Z4e j5Z6e6fddZ7e6fd d!Z8Gd"d#d#Z9ej(dCkrNej:ej;koJejej?ej@ejAejBejChkZDndZDeDrvd$d%ZEGd&d'd'e9ZFeFZGGd(d)d)e9ZHeHZIed*d+ZJd,d-ZKeLed.rejMeKZKGd/d0d0ZNGd1d2d2ZOGd3d4d4eNZPGd5d6d6eNZQGd7d8d8eNZRGd9d:d:eZSGd;dde,ZTGdddeTZWGd?ddeWeUZXGd@ddeWeVZYdS)DN)Sequence defaultdict)contextmanager)EINVALENOENTEEXIST)chaincount) attrgetter)S_ISDIRS_ISLNKS_ISREG)quoter)rquote_from_bytesT)_getfinalpathnameFPurePath PurePosixPath PureNTPathPath PosixPathNTPathcCsd|kpd|kpd|kS)N*?[)patrrG/gpfs/hps/nco/ops/nwprod/ens_tracker.v1.2.2/ush/FSUgenesisPY/pathlib.py_is_wildcard_patternGsr c@s eZdZdZddZddZdS)_FlavourzPA flavour implements a particular (platform-specific) set of path semantics.cCs|jj|_dS)N)sepjoin)selfrrr__init__Qsz_Flavour.__init__c Csg}|j}|j}d}}t|}x|D]|}|r:|j||}|j|\}}} | j|} |jddt| j|D|sz|r&|sx |D]}|j|d}|rPqWPq&W|s|r|j|||j |||fS)Ncss|]}|r|dkr|VqdS).Nr).0xrrr _sz'_Flavour.parse_parts..r) r"altsepreversedreplace splitrootrstripextendsplitappendreverse) r$partsZparsedr"r+drvrootitpartZrelrrr parse_partsTs,    z_Flavour.parse_partsN)__name__ __module__ __qualname____doc__r%r9rrrrr!Msr!c@seZdZdZdZdZeZedk Z e dde e de dd De d de e d e d d DBZ d Zddddhdde d dDBdde d dDBZefddZddZddZddZefddZd d!Zd"d#Zd$d%ZdS)& _NTFlavour\/TNccs|]}t|VqdS)N)chr)r(r)rrrr*|sz_NTFlavour.azccs|]}t|VqdS)N)rA)r(r)rrrr*}sAZz\\?\ZCONZPRNZAUXZNULcCsh|] }d|qS)zCOM%dr)r(irrr sz_NTFlavour. cCsh|] }d|qS)zLPT%dr)r(rGrrrrHsc Csb|dd}|dd}||krP||krP|j|\}}|dd}|dd}nd}|dd}||kov||kov||kr|j|d}|dkr|j||d}||dkr|dkrt|}|r||d||||ddfS|d||||ddfSd} } |dkr<||jkr<|dd} |dd}|}||krT|} |j|}|| | |fS) NrrDrr&r:rK)_split_extended_pathfindlen drive_letterslstrip) r$r8r"firstsecondprefixZthirdindexZindex2r5r6rrrr.s6      "    z_NTFlavour.splitrootcCs|jS)N)lower)r$srrrcasefoldsz_NTFlavour.casefoldcCsdd|DS)NcSsg|] }|jqSr)rU)r(prrr sz-_NTFlavour.casefold_parts..r)r$r4rrrcasefold_partssz_NTFlavour.casefold_partscCs.t|}|stjStdk r*|jt|SdS)N)strosgetcwdr_ext_to_normal)r$pathrVrrrresolves z_NTFlavour.resolvecCsXd}|j|rP|dd}|dd}|jdrP||dd7}d|dd}||fS)Nr&zUNC\rr?) startswith)r$rVZ ext_prefixrSrrrrLs    z_NTFlavour._split_extended_pathcCs|j|dS)NrD)rL)r$rVrrrr^sz_NTFlavour._ext_to_normalcCs6|sdS|djdrdS|djddj|jkS)NFrz\\rDr'rK)rb partitionupperreserved_names)r$r4rrr is_reserveds z_NTFlavour.is_reservedcCsd|j}t|dkrJ|ddkrJ|jddjd}d|t|jdfSdt|jjdSdS)NrrDrJr@z file:///%s/%szutf-8zfile:)driverNas_posixrPurlquote_from_bytesencode)r$r_rgrestrrrmake_uris z_NTFlavour.make_uri)r:r;r<r"r+has_drvntpathpathmodnt is_supportedsetrangeordrOZext_namespace_prefixrer.rWrZr`rLr^rfrlrrrrr>ps$"& '  r>c@sZeZdZdZdZdZeZej dkZ efddZ ddZ d d Z d d Zd dZddZdS) _PosixFlavourr@r&FrpcCsV|rH|d|krH|j|}t|t|dkr.split..)r1)rX)r"rrr1 sz$_PosixFlavour.resolve..splitcs*|jstj|S|SdS)N)rbr\r])rX)r"r1rrabsparts s z'_PosixFlavour.resolve..abspartscSs|tkrtj|dS)N)_NO_FDr\close)fdrrrrxsz$_PosixFlavour.resolve..closerDr&zSymlink loop from %r)dir_fdrKrK)r"r[ _accessorrwpoprN ValueErrorreadlinkOSErrorerrnor walk_downrbr0) r$r_rvrxr4ZaccessorZresolvedZcurZ resolved_fdZsymlinksr8targeter)r"r1rr` s<        z_PosixFlavour.resolvecCsdS)NFr)r$r4rrrrf:sz_PosixFlavour.is_reservedcCs|j}dt|S)Nzfile://)as_bytesri)r$r_Zbpathrrrrl=sz_PosixFlavour.make_uriN)r:r;r<r"r+rm posixpathror\namerqr.rWrZr`rfrlrrrrrus  1ruc Cs$|t|d7<WdQRXdS)NrD) _fds_refs)rylockrrr _add_fd_refKsrc CsB|4t|d}|dkr$|t|<nt|=tj|WdQRXdS)NrDr)rr\rx)ryrZnrefsrrr _sub_fd_refOs   rc@seZdZdZdS) _AccessorzjAn accessor implements a particular (system-specific or not) way of accessing paths on the filesystem.N)r:r;r<r=rrrrrYsrcCs,|j}|dk r||jdfStt|fSdS)ziGet a (parent fd, name) pair from a path object, suitable for use with the various *at functions.NrDrK) _parent_fd_partsrwr[)pathobj parent_fdrrr _fdnamepairhsrc@seZdZddZddZeejZeejZeejZeej Z ddZ eej Z eej Z eej Z ddZeejZejdkreejZd d ZeejZdd dZddZddZddZddZdS)_OpenatAccessorcstjfdd}t|S)Ncs$t|\}}|f|d|i|S)Nrz)r)rargskwargsrr)atfuncrrwrappedus z-_OpenatAccessor._wrap_atfunc..wrapped) functoolswraps staticmethod)rrr)rr _wrap_atfunctsz_OpenatAccessor._wrap_atfunccstjfdd}t|S)NcsNt|\}}t|tr$t|\}}ntt|}}||f|||d|S)N) src_dir_fd dst_dir_fd)r isinstancerrwr[)pathobjApathobjBrrZ parent_fd_AZnameAZ parent_fd_BZnameB)rrrr|s   z4_OpenatAccessor._wrap_binary_atfunc..wrapped)rrr)rrr)rr_wrap_binary_atfunc{s z#_OpenatAccessor._wrap_binary_atfunccCs|j||ddS)NF)follow_symlinks)chmod)r$rmoderrrlchmodsz_OpenatAccessor.lchmodcCs|j|dd}tj|S)NF)tolerant)_make_fdr\listdir)r$rryrrrrsz_OpenatAccessor.listdirrcCs$t|\}}tjt|||ddS)N)rz)rr\symlinkr[)r$rrtarget_is_directoryrrrrrrs z_OpenatAccessor.symlinkTcCs|j}|dk r|Sy|j|tj}Wn"ttfk rF|r@dSYnXytj|}|_Wntj|YnX|rt |j  rtj|dS||_|j ||SdS)N) _cached_fdopenr\O_RDONLYPermissionErrorFileNotFoundErrorfstat _cached_statrxr st_mode_add_managed_fd)r$rrrystrrrrs(   z_OpenatAccessor._make_fdcCs|j|dS)N)r)r$rrrr init_pathsz_OpenatAccessor.init_pathc Cs|jj|\}}}|s|rdS|j|dd}|sZ|j|j|j|jdd}|j||d|S|}x<|ddD],} tj | tj |d} ||krtj || }qlW|j|j|j|j|dd}|j||d|S) NF)r)init)templateryrD)rz)rrrK) _flavourr9r_from_parsed_parts_drv_rootr_initr\rrrx) r$rrr5r6r4Zpathfdnewpathrr8ryrrr make_childs& z_OpenatAccessor.make_childc Cs<|tkr*ztj|tj|dStj|Xntj|tjSdS)N)rz)rwr\rrrx)r$r_rrzrrrrs z_OpenatAccessor.walk_downcCs$|tkrtj||dStj|SdS)N)rz)rwr\r~)r$r_rrzrrrr~sz_OpenatAccessor.readlinkN)rr)T)r:r;r<rrr\statlstatrrrmkdirunlinkrmdirrrenamesys version_infor-rutimerrrrr~rrrrrrs*             rc@seZdZddZddZeejZeejZeejZeej Z eej Z e edr`eej Z nddZ eej Z eejZeejZeejZejdkreejZerereejZqd d Zn ed d ZeejZd d ZddZddZddZdS)_NormalAccessorcstjfdd}t|S)Ncst|f|S)N)r[)rr)strfuncrrrsz._NormalAccessor._wrap_strfunc..wrapped)rrr)rrr)rr _wrap_strfuncsz_NormalAccessor._wrap_strfunccstjfdd}t|S)Ncst|t|f|S)N)r[)rrr)rrrrsz5_NormalAccessor._wrap_binary_strfunc..wrapped)rrr)rrr)rr_wrap_binary_strfuncsz$_NormalAccessor._wrap_binary_strfuncrcCs tddS)Nz%lchmod() not available on this system)NotImplementedError)r$rrrrrrsz_NormalAccessor.lchmodrcCs tddS)Nz&symlink() not available on this system)r)rBbrrrrr&sz_NormalAccessor.symlinkcCstjt|t|S)N)r\rr[)rBrrrrrr*scCsdS)Nr)r$rrrrr0sz_NormalAccessor.init_pathcCsdS)Nr)r$rrrrrr3sz_NormalAccessor.make_childcCs|tks ttS)N)rwAssertionError)r$r_rrzrrrr7s z_NormalAccessor.walk_downcCs|tks ttj|S)N)rwrr\r~)r$r_rrzrrrr~;s z_NormalAccessor.readlinkN)rr)r:r;r<rrr\rrrrrhasattrrrrrrrrr-rpsupports_symlinksrrrrrrr~rrrrrs4                 rc#sXyjVWnBtk rRifdd}d|_z |VWdjXYnXdS)Ncs$|kr|S|}|<|S)Nr)rvalue)cachefuncrrwrapperMsz_cached..wrapperT) __cached__AttributeErrorclear)rrr)rrr_cachedFs  rcCsP|d}|dd}|dkr"t}n$d|kr4tdnt|rBt}nt}|||S)NrrDz**z:Invalid pattern: '**' can only be an entire path component)_RecursiveWildcardSelectorr}r _WildcardSelector_PreciseSelector) pattern_partsr child_partsclsrrr_make_selectorXs  r lru_cachec@s eZdZdZddZddZdS) _SelectorzYA selector matches a specific glob pattern part against the children of a given path.cCs"||_|rt||_nt|_dS)N)rr successor_TerminatingSelector)r$rrrrr%ms 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_direxistsr{r _select_from)r$ parent_pathZpath_clsrrrrrr select_fromts z_Selector.select_fromN)r:r;r<r=r%rrrrrrisrc@seZdZddZdS)rccs |VdS)Nr)r$rrrrrrrrsz!_TerminatingSelector._select_fromN)r:r;r<rrrrrr~src@seZdZddZddZdS)rcCs||_tj||dS)N)rrr%)r$rrrrrr%sz_PreciseSelector.__init__ccsF||s dS|j|j}||rBx |jj||||D] }|Vq4WdS)N)_make_child_relpathrrr)r$rrrrr_rXrrrrs  z_PreciseSelector._select_fromN)r:r;r<r%rrrrrrsrc@seZdZddZddZdS)rcCs"tjtj||_tj||dS)N)recompilefnmatch translaterrr%)r$rrrrrr%sz_WildcardSelector.__init__c csj||s dS|jj}xP||D]D}||}|jj|r|j|}x |jj||||D] } | VqTWqWdS)N)rrWrmatchrrr) r$rrrrcfrZ casefoldedr_rXrrrrs  z_WildcardSelector._select_fromN)r:r;r<r%rrrrrrsrc@s$eZdZddZddZddZdS)rcCstj||dS)N)rr%)r$rrrrrr%sz#_RecursiveWildcardSelector.__init__ccsL|Vx@||D]4}|j|}||rx|j|||D] }|Vq6WqWdS)N)r_iterate_directories)r$rrrrr_rXrrrrs  z/_RecursiveWildcardSelector._iterate_directoriesc cs||s dSt|l}t}zT|jj}xF|j|||D]4}x.|||||D]}||krJ|V|j|qJWq6WWd|jXWdQRXdS)N)rrrrrraddr) r$rrrrZyieldedZsuccessor_selectZstarting_pointrXrrrrs z'_RecursiveWildcardSelector._select_fromN)r:r;r<r%rrrrrrrsrc@s4eZdZdZd ZddZddZdd Zd d Zd S) _PathPartsziThis object provides sequence-like access to the parts of a path. Don't try to construct it yourself._pathclsrcCst||_|j|_dS)N)rrr)r$r_rrrr%s z_PathParts.__init__cCs t|jS)N)rNr)r$rrr__len__sz_PathParts.__len__cCs$t|tr|j|j|S|j|S)N)rslicerr)r$idxrrr __getitem__s z_PathParts.__getitem__cCsdj|jj|jS)Nz<{}.parts: {!r}>)formatrr:r)r$rrr__repr__sz_PathParts.__repr__N)rr) r:r;r<r= __slots__r%rrrrrrrrs rc@s|eZdZdZdTZd d Zd d Zed dZedUddZ edVddZ eddZ ddZ ddZ ddZddZddZeZd d!Zd"d#Zed$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zeedd4d5Zeedd6d5Zed7d8Z ed9d:Z!ed;d<Z"d=d>Z#d?d@Z$edAdBZ%dCdDZ&dEdFZ'edGdHZ(dIdJZ)dKdLZ*dMdNZ+dOdPZ,dQdRZ-dSS)WraCPurePath 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 PureNTPath object. You can also instantiate either of these classes directly, regardless of your system. rrr_str_hash_pparts_cached_cpartscGs$|tkrtjdkrtnt}|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. rp)rr\rrr _from_parts)rrrrr__new__szPurePath.__new__cCs|jt|jfS)N) __class__tupler)r$rrr __reduce__szPurePath.__reduce__cCsZg}xH|D]@}t|tr$||j7}q t|tr:|j|q tdt|q W|jj|S)Nz/argument should be a path or str object, not %r) rrrr[r2 TypeErrorrrr9)rrr4rBrrr _parse_argss     zPurePath._parse_argsTcCs<tj|}|j|\}}}||_||_||_|r8|j|S)N)objectrrrrrr)rrrr$r5r6r4rrrrs zPurePath._from_partscCs,tj|}||_||_||_|r(|j|S)N)rrrrrr)rr5r6r4rr$rrrrs zPurePath._from_parsed_partscCs4|s|r$|||jj|ddS|jj|SdS)NrD)rr#)rr5r6r4rrr_format_parsed_partsszPurePath._format_parsed_partscCsdS)Nr)r$rrrr$szPurePath._initcCs"|jdd}|j||j|S)N)rr0r)r$rr4rrr _make_child(s zPurePath._make_childc Cs<y|jStk r6|j|j|j|jp,d|_|jSXdS)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.r@)rr[r-r")r$frrrrh8szPurePath.as_posixcCs tjdkrtdtjt|S)zaReturn the bytes representation of the path. This is only recommended to use under Unix.rrzneeds Python 3.2 or later)rr)rrrr\fsencoder[)r$rrrr>s zPurePath.as_bytescCsdj|jjt|S)Nz{}({!r}))rrr:r[)r$rrrrGszPurePath.__repr__cCs|jstd|jj|S)z Return the path as a 'file' URI.z.relative path can't be expressed as a file URI) is_absoluter}rrl)r$rrras_uriJszPurePath.as_uric Cs2y|jStk r,|jj|j|_|jSXdS)N)rrrrZr)r$rrr_cpartsPs zPurePath._cpartscCs&t|tstS|j|jko$|j|jkS)N)rrNotImplementedr r)r$otherrrr__eq__Ys zPurePath.__eq__cCs ||k S)Nr)r$rrrr__ne__^szPurePath.__ne__c Cs2y|jStk r,tt|j|_|jSXdS)N)rrhashrr )r$rrr__hash__as zPurePath.__hash__cCs(t|t s|j|jk rtS|j|jkS)N)rrrrr )r$rrrr__lt__hszPurePath.__lt__cCs(t|t s|j|jk rtS|j|jkS)N)rrrrr )r$rrrr__le__mszPurePath.__le__cCs(t|t s|j|jk rtS|j|jkS)N)rrrrr )r$rrrr__gt__rszPurePath.__gt__cCs(t|t s|j|jk rtS|j|jkS)N)rrrrr )r$rrrr__ge__wszPurePath.__ge__z-The drive prefix (letter or UNC path), if any)doczThe root of the path, if anycCs|j|j}|S)z/The concatenation of the drive and root, or ''.)rr)r$anchorrrrrs zPurePath.anchorcCs.|j}t||js|jrdndkr&dS|dS)z!The final path component, if any.rDrr&rK)rrNrr)r$r4rrrrsz PurePath.namecCs<|j}|dks|dkrdS|jd}|dkr0dS||dS)z(The final component's extension, if any.r&r'rDNrK)rrM)r$basenamerGrrrexts z PurePath.extcCs8|js |jr$|jdd|jddS|jdd|jSdS)z6Return a new path without any drive and root. r&rDN)rrrr)r$rrrrelatives zPurePath.relativec Gs|s td|j}|j}|j}|s&|rT|r@||g|dd}qX|g|dd}n|}|j|\}}}|sp|r|r||g|dd} q|g|dd} n|} t| } | dkr|s|s|d| | kr|j|||} tdjt |t | |j dd|| 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 argumentrDNrz{!r} does not start with {!r}r&) rrrrrrNrr}rr[r) r$rr4r5r6Z abs_partsZto_drvZto_rootZto_partsZ to_abs_partsnZ formattedrrr relative_tos,  zPurePath.relative_toc Cs,y|jStk r&t||_|jSXdS)zZAn object providing sequence-like access to the components in the filesystem path.N)rrr)r$rrrr4s  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$rrrrr#sz PurePath.joincCs$t|tr|j|S|j|fSdS)N)rrr)r$keyrrrrs  zPurePath.__getitem__cCsdd}|dkrtd|j}|j}|jd| }|sV|t|jt|pF|krVtd|j|||S)zd?Z!dedAdBZ"dfdCdDZ#dEdFZ$dGdHZ%dIdJZ&dKdLZ'dMdNZ(dOdPZ)dQdRZ*dgdSdTZ+dUdVZ,dWdXZ-dYdZZ.d[d\Z/d S)hrr{r_closedrr _managed_fds __weakref__cOsZ|jdd}|tkr&tjdkr"tnt}|j|dd}|jjsLt d|j f|j ||S)N use_openatFrp)rz$cannot instantiate %r on your system) getrr\rrrrrrqrr:r)rrrr/r$rrrrCs   z Path.__new__FNcCs|d|_d|_||_||_|dk r*|j||dk r<|j||dk rN|j|_n|rfts^tdt|_nt |_|jj |dS)NFz$your system doesn't support openat()) r,r-rrrr{supports_openatr_openat_accessor_normal_accessorr)r$r/rrryrrrrNs    z Path._initcCs<|jj||}|dk r|S|jdd}|j||j|S)N)r{rrr0r)r$rchildr4rrrrds  zPath._make_childcCs:|jj||f}|dk r|S|j|g}|j|j|j|S)N)r{rrrrr)r$r8r4r4rrrrls  zPath._make_child_relpathc Cs2y|jStk rYnX|jj|}||_|S)N)rrr{r)r$rrrr_status z Path._statcCs*|dk r|j|=x|r$t|jqWdS)N)_wrsrr|)rfdswr_idrrr_cleanupsz Path._cleanupcsp|dkr dS|jdkrZg|_t|jt|jtj|fdd}||j<t|j |dS)z-Add a file descriptor managed by this object.Ncs S)Nr)wr)cleanupr7r8rrsz&Path._add_managed_fd..) r-rr9next_wr_idweakrefrefr6rr2)r$ryr:r)r;r7r8rrs    zPath._add_managed_fdcCs|jj|t|dS)z0Remove a file descriptor managed by this object.N)r-remover)r$ryrrr_sub_managed_fds zPath._sub_managed_fdcCs|jr|j|S)N)r, _raise_closed)r$rrr __enter__szPath.__enter__cCs4d|_|j}|dk r0d|_d|_d|_|j|dS)NT)r,r-rrr9)r$tvtbr7rrr__exit__sz Path.__exit__cCs tddS)NzI/O operation on closed path)r})r$rrrrCszPath._raise_closedcCs|jj|||S)N)r{r)r$rflagsrrrr_openersz Path._openercCs|tj|dS)zjReturn a new path pointing to the current working directory (as returned by os.getcwd()). )r/)r\r])rr/rrrcwdszPath.cwdccsL|jr|jx8|jj|D](}|dkr*q|j|V|jr|jqWdS)zyIterate over the files in this directory. Does not yield any result for the special paths '.' and '..'. r'..N>r'rM)r,rCr{rr)r$rrrr__iter__s z Path.__iter__cCs |jdrt|j|S|j|S)NZst_)rbgetattrr5__getattribute__)r$rrrr __getattr__s  zPath.__getattr__ccsZ|jj|}|jj|f\}}}|s(|r0tdtt|}x|j|D] }|VqHWdS)zIterate over this subtree and yield all existing files (of any kind, including directories) matching the given pattern. z%Non-relative patterns are unsupportedN)rrWr9rrrr)r$patternr5r6rselectorrXrrrglobs  z Path.globccs^|jj|}|jj|f\}}}|s(|r0tdtdt|}x|j|D] }|VqLWdS)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)rU)rrWr9rrrr)r$rRr5r6rrSrXrrrrglobs z Path.rglobcCsL|jr|j|jr|S|jtjg|jdd}|j||j|j d|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. F)r)rrry) r,rCr rr\r]rrrr)r$objrrrabsolutesz Path.absolutecCsj|jr|j|jj|}|dkr4|jt|j}|jjj|}|j |fdd}|j ||j |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). NF)r)rrry) r,rCrr`r5r[rXronormpathrrrr)r$rVZnormedrWrrrr`s  z Path.resolvecCs|jS)zh Return the result of the stat() system call on this path, like os.stat() does. )r5)r$rrrr sz Path.statc Cs$y|`Wntk rYnX|jS)zW Same as stat(), but resets the internal cache to force a fresh value. )rrr5)r$rrrrestats z Path.restatcCsddl}|j|jjjS)z: Return the login name of the file owner. rN)pwdgetpwuidr5st_uidZpw_name)r$r[rrrownersz Path.ownercCsddl}|j|jjjS)z8 Return the group name of the file gid. rN)grpZgetgrgidr5st_gidZgr_name)r$r_rrrgroup$sz Path.groupcCs|jr|j|jj|||S)zm Open the file pointed by this path and return a file descriptor, as os.open() does. )r,rCr{r)r$rJrrrrraw_open,sz Path.raw_openrrDc CsR|jr|jtjdkr6tjt|||||||jdStjt||||||SdS)z| Open the file pointed by this path and return a file object, as the built-in open() function does. r)openerN)rr)r,rCrriorr[rK)r$r bufferingencodingerrorsnewlinerrrr5s   z Path.openTc Csx|jr|j|rJtj}y|jj|||fWntk rDYnXdStj}|s^|tjO}|j ||}tj |dS)zS Create this file with the given access mode, if it doesn't exist. N) r,rCtimer{rrr\O_CREATO_EXCLrcrx)r$rexist_okrErJryrrrtouchCs  z Path.touchcCs|jr|j|s"|jj||nty|jj||Wn`tk r}zD|jtkrd|jtkrb|rbdS|jj|d|d|jj||WYdd}~XnXdS)NT)rn) r,rCr{rrrrrr")r$rr$rnrrrrr[s z Path.mkdircCs |jr|j|jj||dS)zF Change the permissions of the path, like os.chmod(). N)r,rCr{r)r$rrrrrksz 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)r,rCr{r)r$rrrrrssz Path.lchmodcCs|jr|j|jj|dS)zd Remove this file or link. If the path is a directory, use rmdir() instead. N)r,rCr{r)r$rrrr|sz Path.unlinkcCs|jr|j|jj|dS)zF Remove this directory. The directory must be empty. N)r,rCr{r)r$rrrrsz 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. )r,rCr{r)r$rrrrsz Path.lstatcCs |jr|j|jj||dS)z5 Rename this path to the given path. N)r,rCr{r)r$rrrrrsz Path.renamecCs2tjdkrtd|jr |j|jj||dS)zo Rename this path to the given path, clobbering the existing destination if it exists. rz5replace() is only available with Python 3.3 and laterN)rr)rrrr,rCr{r-)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)r,rCr{r)r$rrrrr symlink_toszPath.symlink_tocCs>y |jWn,tk r8}z|jtkr*dSd}~XnXdS)z+ Whether this path exists. FNT)rZrrr)r$rrrrrs  z Path.existscCs>y t|jjStk r8}z|jtkr*dSd}~XnXdS)z3 Whether this path is a directory. FN)r r5rrrr)r$rrrrrs   z Path.is_dircCs>y t|jjStk r8}z|jtkr*dSd}~XnXdS)zq Whether this path is a regular file (also True for symlinks pointing to regular files). FN)r r5rrrr)r$rrrris_files   z Path.is_filecCsDy |j}Wn,tk r8}z|jtkr*dSd}~XnXt|jS)z7 Whether this path is a symbolic link. FN)rrrrr r)r$rrrrr is_symlinks  zPath.is_symlink)r{rr,rrr-r.)FNNN)N)rI)F)rbrK)rdrKNNN)rIT)rbFF)F)0r:r;r<rr6r r>rrrrr)r5r'r9rrBrDrHrCrKrLrNrQrTrVrXr`rrZr^rarcrrorrrrrrrr-rprrrqrrrrrrr4sh                    c@seZdZfZdS)rN)r:r;r<rrrrrrsc@seZdZfZdS)rN)r:r;r<rrrrrrs)rr)rr)rr)Zrrrfrnr\rrrrkr? threading ImportErrordummy_threading collectionsrr contextlibrrrrr itertoolsrr operatorr rr r r ZurllibrZurlquoteriZ urllib.parserrrpZgetwindowsversionrr__all__r rr!r>rwrur+r*intrLockZ_fds_refs_lockrrrr supports_fdsupports_dir_fdrrrr~rrrr1rrr2rr3rrrrrrrrrrrrrrrrrrrrs     " #zX    F   !M9