o Ƌ|c@s4ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z m Z mZmZmZddlmZddlmZmZmZmZmZmZmZddlmZgdZdZd Z d Z!e eeefZ"ee e!fZ#d d Z$d dZ%Gddde&Z'Gddde'Z(Gddde'Z)e(Z*e)Z+GdddZ,Gddde,Z-e-Z.ddZ/e0edre1e/Z/GdddZ2GdddZ3Gd d!d!e2Z4Gd"d#d#e2Z5Gd$d%d%e2Z6Gd&d'd'e Z7Gd(d)d)e&Z8ej9:e8Gd*d+d+e8Z;Gd,d-d-e8ZGd2d3d3e=e<Z?dS)4N)Sequence)EINVALENOENTENOTDIREBADFELOOP) attrgetter)S_ISDIRS_ISLNKS_ISREGS_ISSOCKS_ISBLKS_ISCHRS_ISFIFO)quote_from_bytes)PurePath PurePosixPathPureWindowsPathPath PosixPath WindowsPath{icCs t|ddtvpt|ddtvS)Nerrnowinerror)getattr_IGNORED_ERROS_IGNORED_WINERRORS) exceptionr$/opt/conda/lib/python3.10/pathlib.py _ignore_error&sr!cCsd|vp d|vp d|vS)N*?[r)patrrr _is_wildcard_pattern+sr&c@s(eZdZdZddZddZddZdS) _FlavourzPA flavour implements a particular (platform-specific) set of path semantics.cCs|jj|_dSN)sepjoinselfrrr __init__5z_Flavour.__init__c Csg}|j}|j}d}}t|}|D]c}|sq|r|||}||\}}} || vrDt| |D]} | rB| dkrB|t| q2n| rR| dkrR|t| |sV|ru|ss|D]}|s_qZ|rg|||}||d}|rrnqZnq|sz|r|||| |||fS)N.r) r)altsepreversedreplace splitrootsplitappendsysinternreverse) r,partsZparsedr)r1drvrootitpartrelxrrr parse_parts8sH     z_Flavour.parse_partscCsz|r|s|r||||g|ddfSn#|r1||ks%||||kr0||||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,r;r<r:Zdrv2Zroot2Zparts2rrr join_parsed_parts^s z_Flavour.join_parsed_partsN)__name__ __module__ __qualname____doc__r-rArDrrrr r'1s  &r'c@seZdZdZdZdZeZej dkZ e dZ dZ hddd d DBd d d DBZefd d ZddZddZddZe fddZddZddZdS)_WindowsFlavour\/TntZ4abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZz\\?\>ZAUXZCONZPRNZNULzCONOUT$zCONIN$cCh|]}d|qS)zCOM%sr.0crrr z_WindowsFlavour.u123456789¹²³cCrM)zLPT%srrNrrr rQrRc CsV|dd}|dd}||kr(||kr(||\}}|dd}|dd}nd}|dd}||kr~||kr~||kr~||d}|dkr~|||d}||dkr~|dkr\t|}|ro||d||||ddfS|d||||ddfSd} } |dkr||jvr|dd} |dd}|}||kr|} ||}|| | |fS)NrrBr/:)_split_extended_pathfindlen drive_letterslstrip) r,r>r)firstsecondprefixZthirdindexZindex2r;r<rrr r4s6      "   z_WindowsFlavour.splitrootcCs|Sr(lowerr,srrr rCz_WindowsFlavour.casefoldcCsdd|DS)NcSsg|]}|qSrr`)rOprrr rRz2_WindowsFlavour.casefold_parts..rr,r:rrr casefold_partsr.z_WindowsFlavour.casefold_partscCstt|tjjSr()recompilefnmatch translate IGNORECASE fullmatchr,patternrrr compile_patternsz_WindowsFlavour.compile_patterncCsXd}||r(|dd}|dd}|dr(||dd7}d|dd}||fS)Nr/zUNC\rTrJ) startswith)r,rcZ ext_prefixr^rrr rWs    z$_WindowsFlavour._split_extended_pathcCsJ|sdS|ddr dS|dddddd}||jvS)NFrz\\rUr0rV )rs partitionrstripupperreserved_names)r,r:namerrr is_reserveds "z_WindowsFlavour.is_reservedcCs`|j}t|dkr%|ddkr%|ddd}d|t|dfSdt|dS)NrSrBrVrKz file:///%s/%szutf-8zfile:)driverYas_posixr[urlquote_from_bytesencode)r,pathr{restrrr make_urisz_WindowsFlavour.make_uriN)rErFrGr)r1has_drvntpathpathmodosry is_supportedsetrZZext_namespace_prefixrxr4rCrhrqrWrzrrrrr rIps*    '  rIc@sZeZdZdZdZdZeZej dkZ efddZ ddZ d d Z d d Zd dZddZdS) _PosixFlavourrKr/FrLcCsP|r#|d|kr#||}t|t|dkrd|d|fSd||fSdd|fS)NrrSr/)r[rY)r,r>r)Z stripped_partrrr r4s    z_PosixFlavour.splitrootcC|Sr(rrbrrr rCz_PosixFlavour.casefoldcCrr(rrgrrr rhrz_PosixFlavour.casefold_partscCstt|jSr()rirjrkrlrnrorrr rqz_PosixFlavour.compile_patterncCsdSNFrrgrrr rzrz_PosixFlavour.is_reservedcCst|}dt|S)Nzfile://)bytesr})r,rbpathrrr r s z_PosixFlavour.make_uriN)rErFrGr)r1r posixpathrrryrr4rCrhrqrzrrrrr rs   rc@seZdZdZdS) _AccessorzjAn accessor implements a particular (system-specific or not) way of accessing paths on the filesystem.N)rErFrGrHrrrr rsrc@seZdZejZejZejZejZej Z ej Z ej Z e edr"ej Z nddZ ejZejZejZe edr8ejZndddZdd d Ze ed rKejZnd dZddZddZejZeejjZeejjZdS)_NormalAccessorlinkcCtd)Nz&os.link() not available on this systemNotImplementedError)r,srcdstrrr r-rdz_NormalAccessor.linksymlinkFcCr)Nz)os.symlink() not available on this systemr)r,rrtarget_is_directoryrrr r9rdz_NormalAccessor.symlinkTcCs`|rz t|dWdStyYnwtjtjB}|s"|tjO}t|||}t|dSr()rutimeOSErrorO_CREATO_WRONLYO_EXCLopenclose)r,rmodeexist_okflagsfdrrr touch<s   z_NormalAccessor.touchreadlinkcCr)Nz*os.readlink() not available on this systemrr,rrrr rQrdz_NormalAccessor.readlinkcC6zddl}|||jjWStytdw)Nrz*Path.owner() is unsupported on this system)pwdgetpwuidstatst_uidZpw_name ImportErrorr)r,rrrrr ownerT  z_NormalAccessor.ownercCr)Nrz*Path.group() is unsupported on this system)grpZgetgrgidrst_gidZgr_namerr)r,rrrrr group[rz_NormalAccessor.groupNFrT)rErFrGrriorlistdirscandirchmodmkdirunlinkhasattrrrmdirrenamer3rrrrrgetcwd staticmethodr expanduserrealpathrrrr rs4      rcCsP|d}|dd}|dkrt}nd|vrtdt|r t}nt}||||S)NrrB**z:Invalid pattern: '**' can only be an entire path component)_RecursiveWildcardSelector ValueErrorr&_WildcardSelector_PreciseSelector) pattern_partsflavourr% child_partsclsrrr _make_selectorps  r lru_cachec@s eZdZdZddZddZdS) _SelectorzYA selector matches a specific glob pattern part against the children of a given path.cCs2||_|rt|||_d|_dSt|_d|_dS)NTF)rr successordironly_TerminatingSelector)r,rrrrr r-s    z_Selector.__init__cCs<t|}|j}|j}|jj}||stgS|||||S)zuIterate over all child paths of `parent_path` matched by this selector. This can contain parent_path itself.)typeis_direxists _accessorriter _select_from)r, parent_pathZpath_clsrrrrrr select_fromsz_Selector.select_fromN)rErFrGrHr-rrrrr rs rc@seZdZddZdS)rccs |VdSr(r)r,rrrrrrr rs z!_TerminatingSelector._select_fromN)rErFrGrrrrr rs rc@eZdZddZddZdS)rcCs||_t|||dSr()ryrr-)r,ryrrrrr r-sz_PreciseSelector.__init__ccs`z$||j}|jr |n||r |j||||D]}|VqWdSWdSty/YdSwr()_make_child_relpathryrrrPermissionError)r,rrrrrrerrr rs  z_PreciseSelector._select_fromNrErFrGr-rrrrr r rc@r)rcCs|||_t|||dSr()rqmatchrr-r,r%rrrrr r-s z_WildcardSelector.__init__c csz_|| }t|}Wdn1swY|D]A}|jrAz|s(WqWnty@}z t|s6WYd}~qd}~ww|j} || r]|| } |j | |||D]} | VqWqWdSt yjYdSwr() listrrrr!ryrrrrr) r,rrrr scandir_itentriesentryeryrrerrr rs6      z_WildcardSelector._select_fromNrrrrr rrrc@s$eZdZddZddZddZdS)rcCst|||dSr()rr-rrrr r-rz#_RecursiveWildcardSelector.__init__c cs|VzY|| }t|}Wdn1swY|D];}d}z|}Wnty@}z t|s6WYd}~nd}~ww|rZ|sZ||j} || ||D]} | VqTqWdStygYdSwr) rrrr! is_symlinkrry_iterate_directoriesr) r,rrrrrrZ entry_is_dirrrrerrr rs2       z/_RecursiveWildcardSelector._iterate_directoriesc csz5t}z,|jj}||||D]}|||||D]}||vr(|V||qqW|WdS|wty@YdSwr()rrrraddclearr) r,rrrrZyieldedZsuccessor_selectZstarting_pointrerrr rs"  z'_RecursiveWildcardSelector._select_fromN)rErFrGr-rrrrrr rs rc@s4eZdZdZdZddZddZddZd d Zd S) _PathParentszvThis object provides sequence-like access to the logical ancestors of a path. Don't try to construct it yourself.)_pathcls_drv_root_partscCs&t||_|j|_|j|_|j|_dSr()rrrrrrrrr r-s  z_PathParents.__init__cCs$|js|jr t|jdSt|jSNrB)rrrYrr+rrr __len__s  z_PathParents.__len__cst|trtfddt|tDS|tks$|t kr(t||dkr2|t7}jj j j d| dS)Nc3s|]}|VqdSr(r)rOir+rr sz+_PathParents.__getitem__..rrB) isinstanceslicetuplerangeindicesrY IndexErrorr_from_parsed_partsrrr)r,idxrr+r __getitem__ s $ z_PathParents.__getitem__cCsd|jjS)Nz <{}.parents>)formatrrEr+rrr __repr__r.z_PathParents.__repr__N) rErFrGrH __slots__r-rrrrrrr rs rc@seZdZdZdZddZddZeddZed d Z ed d Z ed dZ ddZ ddZ ddZddZddZddZddZeddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zeed-d.d/Zeed0d1d/Zed2d3Zed4d5Z ed6d7Z!ed8d9Z"ed:d;Z#dd?Z%d@dAZ&dBdCZ'dDdEZ(edFdGZ)dHdIZ*dJdKZ+dLdMZ,edNdOZ-edPdQZ.dRdSZ/dTdUZ0dVdWZ1dXS)Yra|Base class for manipulating paths without I/O. PurePath 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_cpartscGs$|tur tjdkr tnt}||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. rL)rrryrr _from_parts)rargsrrr __new__*s zPurePath.__new__cCs|jt|jfSr() __class__rrr+rrr __reduce__4szPurePath.__reduce__cCsbg}|D]&}t|tr||j7}qt|}t|tr#|t|qtdt||j |S)NzNargument should be a str object or an os.PathLike object returning str, not %r) rrrrfspathstrr6 TypeErrorr_flavourrA)rrr:arrr _parse_args9s     zPurePath._parse_argscCs0t|}||\}}}||_||_||_|Sr()objectrr rrr)rrr,r;r<r:rrr rMs zPurePath._from_partscCs t|}||_||_||_|Sr()rrrrr)rr;r<r:r,rrr rXs zPurePath._from_parsed_partscCs0|s|r|||j|ddS|j|Sr)r r*)rr;r<r:rrr _format_parsed_parts`s zPurePath._format_parsed_partscCs@||\}}}|j|j|j|j|||\}}}||||Sr()r r rDrrrr)r,rr;r<r:rrr _make_childgs  zPurePath._make_childcCs<z|jWSty||j|j|jpd|_|jYSw)z[Return the string representation of the path, suitable for passing to system calls.r0)rAttributeErrorrrrrr+rrr __str__ms   zPurePath.__str__cCt|Sr()r r+rrr __fspath__wrdzPurePath.__fspath__cCs|j}t||jdS)zNReturn the string representation of the path with forward (/) slashes.rK)r r r3r)r,frrr r|zszPurePath.as_posixcCs t|S)zaReturn the bytes representation of the path. This is only recommended to use under Unix.)rfsencoder+rrr __bytes__s zPurePath.__bytes__cCsd|jj|S)Nz{}({!r}))rrrEr|r+rrr rszPurePath.__repr__cCs|std|j|S)z Return the path as a 'file' URI.z.relative path can't be expressed as a file URI) is_absoluterr rr+rrr as_uris zPurePath.as_uricCs2z|jWSty|j|j|_|jYSwr()rrr rhrr+rrr _cpartss   zPurePath._cpartscCs&t|tstS|j|jko|j|juSr()rrNotImplementedrr r,otherrrr __eq__s zPurePath.__eq__cCs2z|jWStytt|j|_|jYSwr()rrhashrrr+rrr __hash__s   zPurePath.__hash__cCs&t|tr |j|jur tS|j|jkSr(rrr rrrrrr __lt__ zPurePath.__lt__cCs&t|tr |j|jur tS|j|jkSr(r"rrrr __le__r$zPurePath.__le__cCs&t|tr |j|jur tS|j|jkSr(r"rrrr __gt__r$zPurePath.__gt__cCs&t|tr |j|jur tS|j|jkSr(r"rrrr __ge__r$zPurePath.__ge__cC|Sr(r)rrrrr __class_getitem__rzPurePath.__class_getitem__rz.The drive prefix (letter or UNC path), if any.)docrzThe root of the path, if any.cCs|j|j}|S)z/The concatenation of the drive and root, or ''.)rr)r,anchorrrr r+s zPurePath.anchorcCs.|j}t||js |jrdndkrdS|dS)z!The final path component, if any.rBrr/rU)rrYrrrgrrr rysz PurePath.namecCsB|j}|d}d|krt|dkrndS||dSdS)z{ The final component's last suffix, if any. This includes the leading period. For example: '.txt' r0rrBNr/ryrfindrYr,ryrrrr suffixs   zPurePath.suffixcCs:|j}|dr gS|d}dd|dddDS)z A list of the final component's suffixes, if any. These include the leading periods. For example: ['.tar', '.gz'] r0cSsg|]}d|qS)r0r)rOr/rrr rfrRz%PurePath.suffixes..rBN)ryendswithr[r5r,ryrrr suffixess   zPurePath.suffixescCsB|j}|d}d|krt|dkrn|S|d|S|S)z0The final path component, minus its last suffix.r0rrBNr,r.rrr stems   z PurePath.stemcCs|js td|f|j|f\}}}|r,|d|jj|jjfvs,|s,|s,t|dkr2td|||j|j |j dd|gS)z-Return a new path with the file name changed.%r has an empty namerUrBzInvalid name %rN) ryrr rAr)r1rYrrrr)r,ryr;r<r:rrr with_names   zPurePath.with_namecCs|||jS)z(Return a new path with the stem changed.)r5r/)r,r3rrr with_stemszPurePath.with_stemcCs|j}|j|vs|jr|j|vrtd|f|r|dr"|dkr(td||j}|s4td|f|j}|s>||}n |dt| |}||j |j |j dd|gS)zReturn a new path with the file suffix changed. If the path has no suffix, add given suffix. If the given suffix is an empty string, remove the suffix from the path. zInvalid suffix %rr0r4NrU) r r)r1rrsryr/rYrrrr)r,r/rryZ old_suffixrrr with_suffixs   zPurePath.with_suffixc Gs|std|j}|j}|j}|r||g|dd}n|}||\}}}|r3||g|dd} n|} t| } |jj} | dkrF|sE|ren | |d| | | kre||||} t d t |t | | d| dkrn|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 argumentrBNrzU{!r} is not in the subpath of {!r} OR one path is relative and the other is absolute.r/) r rrrr rYr rhrrrr r) r,rr:r;r<Z abs_partsZto_drvZto_rootZto_partsZ to_abs_partsncf formattedrrr relative_tos0  zPurePath.relative_tocGs&z|j|WdStyYdSw)zFReturn True if the path is relative to another path or False. TF)r;rrrrr is_relative_to8s   zPurePath.is_relative_tocCs.z|jWStyt|j|_|jYSw)zZAn object providing sequence-like access to the components in the filesystem path.)rrrrr+rrr r:As    zPurePath.partscGs ||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,rrrr joinpathMs zPurePath.joinpathcCs&z||fWStytYSwr()rr rr,keyrrr __truediv__Us  zPurePath.__truediv__cCs,z ||g|jWStytYSwr()rrr rr>rrr __rtruediv__[s  zPurePath.__rtruediv__cCs@|j}|j}|j}t|dkr|s|r|S||||ddS)zThe logical parent of the path.rBNrU)rrrrYr)r,r;r<r:rrr parentas zPurePath.parentcCr)z*A sequence of this path's logical parents.)rr+rrr parentskszPurePath.parentscCs|jsdS|jj pt|jS)zSTrue if the path is absolute (has both a root and, if applicable, a drive).F)rr rboolrr+rrr rpszPurePath.is_absolutecCs|j|jS)zaReturn True if the path contains one of the special names reserved by the system, if any.)r rzrr+rrr rzwszPurePath.is_reservedc Cs|jj}||}|j|f\}}}|std|r#|||jkr#dS|r.|||jkr.dS|j}|s5|rFt|t|kr?dS|dd}n t|t|krPdStt |t |D] \}}t ||sfdSqYdS)zE Return True if this path matches the given pattern. z empty patternFrBNT) r rCrArrrrrYzipr2rk fnmatchcase) r,Z path_patternr9r;r<Z pat_partsr:r>r%rrr r|s* zPurePath.matchN)2rErFrGrHrrr classmethodr rrrrrrr|rrrpropertyrrr!r#r%r&r'r)rr{r<r+ryr/r2r3r5r6r7r;r<r:r=r@rArBrCrrzrrrrr rs|              !     rc@eZdZdZeZdZdS)rzPurePath subclass for non-Windows systems. On a POSIX system, instantiating a PurePath should return this object. However, you can also instantiate it directly on any system. rN)rErFrGrH_posix_flavourr rrrrr rrc@rI)rzPurePath subclass for Windows systems. On a Windows system, instantiating a PurePath should return this object. However, you can also instantiate it directly on any system. rN)rErFrGrH_windows_flavourr rrrrr rrKrc@seZdZdZeZdZddZddZddZ d d Z e d d Z e d dZ ddZddZddZddZddZdaddZddddZd d!Zd"d#Z & &dbd'd(Zd)d*Zdcd+d,Zd-d.Zddd/d0Zd1d2Zded4d5Zdfd7d8Zddd9d:Zd;d<Z dad=d>Z!d?d@Z"dAdBZ#dCdDZ$dEdFZ%dadGdHZ&dIdJZ'dKdLZ(dMdNZ)dOdPZ*dQdRZ+dSdTZ,dUdVZ-dWdXZ.dYdZZ/d[d\Z0d]d^Z1d_d`Z2d&S)graPurePath subclass that can make system calls. Path represents a filesystem path but unlike PurePath, also offers methods to do system calls on path objects. Depending on your system, instantiating a Path will return either a PosixPath or a WindowsPath object. You can also instantiate a PosixPath or WindowsPath directly, but cannot instantiate a WindowsPath on a POSIX system or vice versa. rcOs@|tur tjdkr tnt}||}|jjstd|j f|S)NrLz$cannot instantiate %r on your system) rrryrrrr rrrE)rrkwargsr,rrr rs z Path.__new__cCs|j|g}||j|j|Sr()rrrr)r,r>r:rrr rs zPath._make_child_relpathcCr(r(rr+rrr __enter__rzPath.__enter__cCsdSr(r)r,tvtbrrr __exit__s z Path.__exit__cCs||jS)zjReturn a new path pointing to the current working directory (as returned by os.getcwd()). )rrrrrr cwdszPath.cwdcCs |dS)zrReturn a new path pointing to the user's home directory (as returned by os.path.expanduser('~')). ~)rrSrrr home z Path.homecCsB|}z|}Wnty|j|}Ynwtj||S)zoReturn whether other_path is the same or not as this file (as returned by os.path.samefile()). )rrrrrsamestat)r,Z other_pathstZother_strrr samefiles  z Path.samefileccs.|j|D] }|dvrq||VqdS)zyIterate over the files in this directory. Does not yield any result for the special paths '.' and '..'. >z..r0N)rrrr1rrr iterdirs z Path.iterdirccsptd|||std||j|f\}}}|s|r#tdtt||j}| |D]}|Vq0dS)zIterate over this subtree and yield all existing files (of any kind, including directories) matching the given relative pattern. zpathlib.Path.globzUnacceptable pattern: {!r}%Non-relative patterns are unsupportedN) r7auditrrr rArrrrr,rpr;r<rselectorrerrr globsz Path.globccsbtd|||j|f\}}}|s|rtdtdt||j}||D]}|Vq)dS)zRecursively yield all existing files (of any kind, including directories) matching the given relative pattern, anywhere in this subtree. zpathlib.Path.rglobr\)rN)r7r]r rArrrrr^rrr rglob sz Path.rglobcCs$|r|S||jg|jS)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. )rrrrrr+rrr absolutesz Path.absoluteFc Csdd}z |jj||d}Wnty}z||d}~ww||f}|sGz|W|StyF}z ||WYd}~|Sd}~ww|S)z Make the path absolute, resolving all symlinks on the way and also normalizing it (for example turning slashes into backslashes under Windows). cSs0t|dd}|jtks|tkrtd|jdS)NrrzSymlink loop from %r)rrr_WINERROR_CANT_RESOLVE_FILENAME RuntimeErrorfilename)rrrrr check_eloop/s z!Path.resolve..check_eloop)strictN)rrrrr)r,rgrfrcrrerrr resolve(s&  z Path.resolveTfollow_symlinkscCs|jj||dS)zh Return the result of the stat() system call on this path, like os.stat() does. ri)rr)r,rjrrr rDsz Path.statcC |j|S)z: Return the login name of the file owner. )rrr+rrr rK z Path.ownercCrk)z8 Return the group name of the file gid. )rrr+rrr rQrlz Path.grouprrUNcCs(d|vr t|}|j||||||S)z| Open the file pointed by this path and return a file object, as the built-in open() function does. b)r text_encodingrr)r,r bufferingencodingerrorsnewlinerrr rWs  z Path.opencCs8|jdd }|WdS1swYdS)zK Open the file in bytes mode, read it, and close the file. rbrN)rreadrrrr read_bytesbs$zPath.read_bytescCsFt|}|jd||d }|WdS1swYdS)zJ Open the file in text mode, read it, and close the file. rm)rrqrrN)rrorrv)r,rqrrrrrr read_textis $zPath.read_textcCsBt|}|jdd }||WdS1swYdS)zO Open the file in bytes mode, write to it, and close the file. wbruN) memoryviewrwrite)r,dataviewrrrr write_bytesqs$zPath.write_bytescCsdt|ts td|jjt|}|jd|||d }||WdS1s+wYdS)zN Open the file in text mode, write to it, and close the file. zdata must be str, not %sw)rrqrrrsN) rr r rrErrorr{)r,r|rqrrrsrrrr write_textzs  $zPath.write_textcCs|j|}||fS)zD Return the path to which the symbolic link points. )rrrrrrr rs  z Path.readlinkrcCs|j|||dS)zS Create this file with the given access mode, if it doesn't exist. N)rr)r,rrrrr rsz Path.touchcCszz |j||WdSty,|r|j|kr|jjddd|j|d|dYdSty<|r8|s9YdSw)z< Create a new directory at this given path. T)rCrFN)rrFileNotFoundErrorrBrr)r,rrCrrrr rs   z Path.mkdircCs|jj|||ddS)zF Change the permissions of the path, like os.chmod(). riN)rr)r,rrjrrr rsz Path.chmodcCs|j|dddS)z Like chmod(), except if the path points to a symlink, the symlink's permissions are changed, rather than its target's. FriN)r)r,rrrr lchmodsz Path.lchmodcCs.z |j|WdSty|sYdSw)zd Remove this file or link. If the path is a directory, use rmdir() instead. N)rrr)r,Z missing_okrrr rs z Path.unlinkcCs|j|dS)zF Remove this directory. The directory must be empty. N)rrr+rrr rsz Path.rmdircCs |jddS)z Like stat(), except if the path points to a symlink, the symlink's status information is returned, rather than its target's. Fri)rr+rrr lstatrWz Path.lstatcC|j||||S)a2 Rename this path to the target path. The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, *not* the directory of the Path object. Returns the new Path instance pointing to the target path. )rrrr,targetrrr r z Path.renamecCr)aS Rename this path to the target path, overwriting if that path exists. The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, *not* the directory of the Path object. Returns the new Path instance pointing to the target path. )rr3rrrrr r3rz Path.replacecCs|j|||dS)z Make this path a symlink pointing to the target path. Note the order of arguments (link, target) is the reverse of os.symlink. N)rr)r,rrrrr symlink_toszPath.symlink_tocCs|j||dS)z Make this path a hard link pointing to the same file as *target*. Note the order of arguments (self, target) is the reverse of os.link's. N)rrrrrr hardlink_toszPath.hardlink_tocCs"tjdtdd|j||dS)a Make the target path a hard link pointing to this path. Note this function does not make this path a hard link to *target*, despite the implication of the function and argument names. The order of arguments (target, link) is the reverse of Path.symlink_to, but matches that of os.link. Deprecated since Python 3.10 and scheduled for removal in Python 3.12. Use `hardlink_to()` instead. zypathlib.Path.link_to() is deprecated and is scheduled for removal in Python 3.12. Use pathlib.Path.hardlink_to() instead.rS) stacklevelN)warningswarnDeprecationWarningrrrrrr link_tos z Path.link_toc CsRz|WdSty}z t|sWYd}~dSd}~wty(YdSw)z+ Whether this path exists. NFT)rrr!rr,rrrr rs  z Path.existsc CTzt|jWSty }z t|sWYd}~dSd}~wty)YdSw)z3 Whether this path is a directory. NF)r rst_moderr!rrrrr r z Path.is_dirc Cr)zq Whether this path is a regular file (also True for symlinks pointing to regular files). NF)r rrrr!rrrrr is_file$s z Path.is_filecCsn|r|s dSz|jj}Wn tyYdSw|j}||kr(dS|j}|jj}||kS)z; Check if this path is a POSIX mount point FT)rrrBrst_devrst_ino)r,Z parent_devdevZinoZ parent_inorrr is_mount5s    z Path.is_mountc Cr)z7 Whether this path is a symbolic link. NF)r rrrr!rrrrr rIs zPath.is_symlinkc Cr)z6 Whether this path is a block device. NF)r rrrr!rrrrr is_block_deviceXrzPath.is_block_devicec Cr)z: Whether this path is a character device. NF)rrrrr!rrrrr is_char_devicehrzPath.is_char_devicec Cr)z. Whether this path is a FIFO. NF)rrrrr!rrrrr is_fifoxrz Path.is_fifoc Cr)z0 Whether this path is a socket. NF)r rrrr!rrrrr is_socketrzPath.is_socketcCsp|js6|js6|jr6|jddddkr6|j|jd}|dddkr)td||g|jddS|S)zl Return a new path with expanded ~ and ~user constructs (as returned by os.path.expanduser) rNrBrUz#Could not determine home directory.)rrrrrrdr)r,Zhomedirrrr rs zPath.expanduserr)rmrUNNN)NN)NNNr)rFF)3rErFrGrH_normal_accessorrrrrrNrRrGrTrVrZr[r`rarbrhrrrrrwrxr~rrrrrrrrrrr3rrrrrrrrrrrrrrrrr rsf               rc@seZdZdZdZdS)rzsPath subclass for non-Windows systems. On a POSIX system, instantiating a Path should return this object. rN)rErFrGrHrrrrr rsrc@seZdZdZdZddZdS)rzqPath subclass for Windows systems. On a Windows system, instantiating a Path should return this object. rcCr)Nz-Path.is_mount() is unsupported on this systemrr+rrr rrdzWindowsPath.is_mountN)rErFrGrHrrrrrr rs r)@rk functoolsrrrrrir7r_collections_abcrrrrrrroperatorrrr r r r r rr urllib.parserr}__all__Z_WINERROR_NOT_READYZ_WINERROR_INVALID_NAMErcrrr!r&rr'rIrrLrJrrrrrrrrrrrrrPathLikeregisterrrrrrrrrr sl  $   ?w*O ,! }  x