o w[e@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/usr/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,partsparsedr)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:drv2root2parts2rrr join_parsed_parts^s z_Flavour.join_parsed_partsN)__name__ __module__ __qualname____doc__r-rBrHrrrr r'1s  &r'c@seZdZdZdZdZeZej dkZ e dZ dZ hddd d DBd d d DBZefd d ZddZddZddZe fddZddZddZdS)_WindowsFlavour\/Tnt4abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZz\\?\>CONIN$CONOUT$AUXCONNULPRNcCh|]}d|qS)zCOM%sr.0crrr z_WindowsFlavour.u123456789¹²³cCrX)zLPT%srrYrrr r\r]c 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)NrrCr/:)_split_extended_pathfindlen drive_letterslstrip) r,r?r)firstsecondprefixthirdindexindex2r<r=rrr r4s6      "   z_WindowsFlavour.splitrootcCs|Sr(lowerr,srrr rDz_WindowsFlavour.casefoldcCsdd|DS)NcSsg|]}|qSrrm)rZprrr r]z2_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\r_rN) startswith)r,rp ext_prefixrirrr rbs    z$_WindowsFlavour._split_extended_pathcCsJ|sdS|ddr dS|dddddd}||jvS)NFrz\\r`r0ra )r partitionrstripupperreserved_names)r,r:namerrr is_reserveds "z_WindowsFlavour.is_reservedcCs`|j}t|dkr%|ddkr%|ddd}d|t|dfSdt|dS)Nr^rCrarOz file:///%s/%szutf-8zfile:)driverdas_posixrfurlquote_from_bytesencode)r,pathrrestrrr make_urisz_WindowsFlavour.make_uriN)rIrJrKr)r1has_drvntpathpathmodosr is_supportedsetreext_namespace_prefixrr4rDrur~rbrrrrrr rMps*    '  rMc@sZeZdZdZdZdZeZej dkZ efddZ ddZ d d Z d d Zd dZddZdS) _PosixFlavourrOr/FrPcCsP|r#|d|kr#||}t|t|dkrd|d|fSd||fSdd|fS)Nrr^r/)rfrd)r,r?r) stripped_partrrr r4s    z_PosixFlavour.splitrootcC|Sr(rrorrr rDz_PosixFlavour.casefoldcCrr(rrtrrr rurz_PosixFlavour.casefold_partscCstt|jSr()rvrwrxryr{r|rrr r~z_PosixFlavour.compile_patterncCsdSNFrrtrrr rrz_PosixFlavour.is_reservedcCst|}dt|S)Nzfile://)bytesr)r,rbpathrrr r s z_PosixFlavour.make_uriN)rIrJrKr)r1r posixpathrrrrr4rDrur~rrrrrr rs   rc@seZdZdZdS) _AccessorzjAn accessor implements a particular (system-specific or not) way of accessing paths on the filesystem.N)rIrJrKrLrrrr 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-rqz_NormalAccessor.linksymlinkFcCr)Nz)os.symlink() not available on this systemr)r,rrtarget_is_directoryrrr r9rqz_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 rQrqz_NormalAccessor.readlinkcC6zddl}|||jjWStytdw)Nrz*Path.owner() is unsupported on this system)pwdgetpwuidstatst_uidpw_name ImportErrorr)r,rrrrr ownerT  z_NormalAccessor.ownercCr)Nrz*Path.group() is unsupported on this system)grpgetgrgidrst_gidgr_namerr)r,rrrrr group[rz_NormalAccessor.groupNFrT)rIrJrKrriorlistdirscandirchmodmkdirunlinkhasattrrrmdirrenamer3rrrrrgetcwd staticmethodr expanduserrealpathrrrr rs4      rcCsP|d}|dd}|dkrt}nd|vrtdt|r t}nt}||||S)NrrC**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_pathpath_clsrrrrrr select_fromsz_Selector.select_fromN)rIrJrKrLr-rrrrr rs rc@seZdZddZdS)rccs |VdSr(r)r,rrrrrrr rs z!_TerminatingSelector._select_fromN)rIrJrKrrrrr rs rc@eZdZddZddZdS)rcCs||_t|||dSr()rrr-)r,rrrrrr r-sz_PreciseSelector.__init__ccs`z$||j}|jr |n||r |j||||D]}|VqWdSWdSty/YdSwr()_make_child_relpathrrrrPermissionError)r,rrrrrrrrrr rs  z_PreciseSelector._select_fromNrIrJrKr-rrrrr r rc@r)rcCs|||_t|||dSr()r~matchrr-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!rrrrrr) r,rrrr scandir_itentriesentryerrrrrrr 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_symlinkrr_iterate_directoriesr) r,rrrrrr entry_is_dirrrrrrrr rs2       z/_RecursiveWildcardSelector._iterate_directoriesc csz5t}z,|jj}||||D]}|||||D]}||vr(|V||qqW|WdS|wty@YdSwr()rrrraddclearr) r,rrrryieldedsuccessor_selectstarting_pointrrrrr rs"  z'_RecursiveWildcardSelector._select_fromN)rIrJrKr-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|jSNrC)rrrdrr+rrr __len__s  z_PathParents.__len__cst|trtfddt|tDS|tks$|t kr(t||dkr2|t7}jj j j d| dS)Nc3s|]}|VqdSr(r)rZir+rr sz+_PathParents.__getitem__..rrC) isinstanceslicetuplerangeindicesrd IndexErrorr_from_parsed_partsrrr)r,idxrr+r __getitem__ s $ z_PathParents.__getitem__cCsd|jjS)Nz <{}.parents>)formatrrIr+rrr __repr__r.z_PathParents.__repr__N) rIrJrKrL __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. rP)rrrrr _from_parts)rargsrrr __new__*s zPurePath.__new__cCs|jt|jfSr() __class__r rr+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) r rrrfspathstrr6 TypeErrorr_flavourrB)rrr:arrr _parse_args9s     zPurePath._parse_argscCs0t|}||\}}}||_||_||_|Sr()objectrr%rrr)rrr,r<r=r:rrr rMs zPurePath._from_partscCs t|}||_||_||_|Sr()r&rrrr)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#rHrrrr)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)rAttributeErrorr'rrrr+rrr __str__ms   zPurePath.__str__cCt|Sr()r!r+rrr __fspath__wrqzPurePath.__fspath__cCs|j}t||jdS)zNReturn the string representation of the path with forward (/) slashes.rO)r#r!r3r)r,frrr rzszPurePath.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}))rrrIrr+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()rr)r#rurr+rrr _cpartss   zPurePath._cpartscCs&t|tstS|j|jko|j|juSr()r rNotImplementedr3r#r,otherrrr __eq__s zPurePath.__eq__cCs2z|jWStytt|j|_|jYSwr()rr)hashr r3r+rrr __hash__s   zPurePath.__hash__cCs&t|tr |j|jur tS|j|jkSr(r rr#r4r3r5rrr __lt__ zPurePath.__lt__cCs&t|tr |j|jur tS|j|jkSr(r:r5rrr __le__r<zPurePath.__le__cCs&t|tr |j|jur tS|j|jkSr(r:r5rrr __gt__r<zPurePath.__gt__cCs&t|tr |j|jur tS|j|jkSr(r:r5rrr __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 rCs zPurePath.anchorcCs.|j}t||js |jrdndkrdS|dS)z!The final path component, if any.rCrr/r`)rrdrrrtrrr rsz 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' r0rrCNr/rrfindrdr,rr rrr 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)rZrGrrr rsr]z%PurePath.suffixes..rCN)rendswithrfr5r,rrrr suffixess   zPurePath.suffixescCsB|j}|d}d|krt|dkrn|S|d|S|S)z0The final path component, minus its last suffix.r0rrCNrDrFrrr 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 namer`rCzInvalid name %rN) rrr#rBr)r1rdrrrr)r,rr<r=r:rrr with_names   zPurePath.with_namecCs|||jS)z(Return a new path with the stem changed.)rMrG)r,rKrrr 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 %rr0rLNr`) r#r)r1rrrrGrdrrrr)r,rGr.r 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 argumentrCNrzU{!r} is not in the subpath of {!r} OR one path is relative and the other is absolute.r/) r"rrrr%rdr#rur'rrr!r) r,r6r:r<r= abs_partsto_drvto_rootto_parts 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)rYrr5rrr is_relative_to8s   zPurePath.is_relative_tocCs.z|jWStyt|j|_|jYSw)zZAn object providing sequence-like access to the components in the filesystem path.)rr)r rr+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()r(r"r4r,keyrrr __truediv__Us  zPurePath.__truediv__cCs,z ||g|jWStytYSwr()rrr"r4r\rrr __rtruediv__[s  zPurePath.__rtruediv__cCs@|j}|j}|j}t|dkr|s|r|S||||ddS)zThe logical parent of the path.rCNr`)rrrrdr)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 r1pszPurePath.is_absolutecCs|j|jS)zaReturn True if the path contains one of the special names reserved by the system, if any.)r#rrr+rrr rwszPurePath.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 patternFrCNT) r#rDrBrrrr3rdzipr2rx fnmatchcase) r, path_patternrWr<r= pat_partsr:r?r%rrr r|s* zPurePath.matchN)2rIrJrKrLrrr classmethodr%rrr'r(r*r,rr0rr2propertyr3r7r9r;r=r>r?rArrr=rCrrGrJrKrMrNrPrYrZr:r[r^r_r`rar1rrrrrr 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)rIrJrKrL_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)rIrJrKrL_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)NrPz$cannot instantiate %r on your system) rrrrrrr#rrrI)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()). )rr)rrrsamestat)r, other_pathstother_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 '..'. >..r0N)rrrrIrrr 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#rBrrr rr,r}r<r=rselectorrrrrr 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)r7rr#rBrrr rrrrr 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. )r1rrrrr+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,rrrprrrrrr resolve(s&  z Path.resolveTfollow_symlinkscCs|jj||dS)zh Return the result of the stat() system call on this path, like os.stat() does. r)rr)r,rrrr rDsz Path.statcC |j|S)z: Return the login name of the file owner. )rrr+rrr rK z Path.ownercCr)z8 Return the group name of the file gid. )rrr+rrr rQrz Path.grouprr`NcCs(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)rreadr-rrr read_bytesbs$zPath.read_bytescCsFt|}|jd||d }|WdS1swYdS)zJ Open the file in text mode, read it, and close the file. r)rrrN)rrrr)r,rrr.rrr read_textis $zPath.read_textcCsBt|}|jdd }||WdS1swYdS)zO Open the file in bytes mode, write to it, and close the file. wbrN) memoryviewrwrite)r,dataviewr.rrr 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)rrrrN) r r!r"rrIrrrr)r,rrrrr.rrr 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)rarFN)rrFileNotFoundErrorr`rr)r,rrarrrr rs   z Path.mkdircCs|jj|||ddS)zF Change the permissions of the path, like os.chmod(). rN)rr)r,rrrrr 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. FrN)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, 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. Fr)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.r^) 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)rrr`rst_devrst_ino)r, parent_devdevino 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) rNrCruz#Could not determine home directory.)rrrrrrr)r,homedirrrr rs zPath.expanduserr)rr`NNN)NN)NNNr)rFF)3rIrJrKrL_normal_accessorrrrrrnrrrgrtrvr|r~rrrrrrrrrrrrrrrrrrrrrr3rrrrrrrrrrrrrrrrr rsf               rc@seZdZdZdZdS)rzsPath subclass for non-Windows systems. On a POSIX system, instantiating a Path should return this object. rN)rIrJrKrLrrrrr 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 rrqzWindowsPath.is_mountN)rIrJrKrLrrrrrr rs r)@rx functoolsrrrrrvr7r_collections_abcrrrrrrroperatorrrr r r r r rr urllib.parserr__all___WINERROR_NOT_READY_WINERROR_INVALID_NAMErrrr!r&r&r'rMrrlrjrrrrrrrrrrrrrPathLikeregisterrrrrrrrrr sl  $   ?w*O ,! }  x