3 \V@sVddlZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z mZmZddlmZddlmZmZmZmZmZmZmZddlmZdZejd krddlZej dd d5krdd lm!Z!qd ZdZ!ndZddddddgZ"ddZ#Gddde$Z%Gddde%Z&Gddde%Z'e&Z(e'Z)GdddZ*Gddde*Z+e+Z,d d!Z-e.ed"rej/e-Z-Gd#d$d$Z0Gd%d&d&Z1Gd'd(d(e0Z2Gd)d*d*e0Z3Gd+d,d,e0Z4Gd-d.d.e Z5Gd/dde$Z6ej7j8e6Gd0dde6Z9Gd1dde6Z:Gd2dde6Z;Gd3dde;e9Zwsz_WindowsFlavour.azr8ccs|]}t|VqdS)N)rB)rCr6rrrrDxsAZz\\?\ZCONZPRNZAUXZNULcCsh|] }d|qS)zCOM%dr)rCirrr ~sz_WindowsFlavour. cCsh|] }d|qS)zLPT%dr)rCrIrrrrJsc 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) 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 sz2_WindowsFlavour.casefold_parts..r)r$r1rrrcasefold_partssz_WindowsFlavour.casefold_partsFc Cst|}|stjSd}tdk r|r2|jt|Sg}xly|jt|}Wn>tk r|}tjj|\}}|j|||kr|SYq8Xtjj |ft |Sq8WdS)N) strosgetcwdr_ext_to_normalFileNotFoundErrorpathr,r-r#r))r$rbstrictrYZ previous_sZ tail_partstailrrrresolves&  z_WindowsFlavour.resolvecCsXd}|j|rP|dd}|dd}|jdrP||dd7}d|dd}||fS)Nr&zUNC\rLr@) startswith)r$rYZ ext_prefixrVrrrrOs    z$_WindowsFlavour._split_extended_pathcCs|j|dS)Nr8)rO)r$rYrrrr`sz_WindowsFlavour._ext_to_normalcCs6|sdS|djdrdS|djddj|jkS)NFrz\\r8r'rN)rg partitionupperreserved_names)r$r1rrr is_reserveds z_WindowsFlavour.is_reservedcCsd|j}t|dkrJ|ddkrJ|jddjd}d|t|jdfSdt|jjdSdS)Nrr8rMrAz file:///%s/%szutf-8zfile:)driverQas_posixrSurlquote_from_bytesencode)r$rbrlrestrrrmake_uris z_WindowsFlavour.make_uric Csdtjkrtjd}n`dtjkr,tjd}nJdtjkrnytjd}Wntk r\d}YnX|tjd}ntd|rtjd|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)F)r;r<r=r"r(has_drvntpathpathmodr^name is_supportedsetrangeordrRZext_namespace_prefixrjr+r9r\rerOr`rkrqrxrrrrr?ks& "& '    r?c@sdeZdZdZdZdZeZej dkZ efddZ ddZ d d Z dd d Zd dZddZddZdS) _PosixFlavourrAr&FrcCsV|rH|d|krH|j|}t|t|dkr._resolver&)r" _accessor is_absoluter^r_r])r$rbrcbaser)rrrr"rcrre/s &z_PosixFlavour.resolvecCsdS)NFr)r$r1rrrrk\sz_PosixFlavour.is_reservedcCst|}dt|S)Nzfile://)bytesrn)r$rbZbpathrrrrq_sz_PosixFlavour.make_uric Cst|s:y tjdStk r6ddl}|jtjjSXn6ddl}y |j|jStk rntd|YnXdS)Nrrrz%Can't determine home directory for %r) r^rsrtpwdgetpwuidgetuidpw_dirgetpwnamru)r$rvrrrrrxes  z_PosixFlavour.gethomedirN)F)r;r<r=r"r(ry posixpathr{r^r|r}r+r9r\rerkrqrxrrrrrs   -rc@seZdZdZdS) _AccessorzjAn accessor implements a particular (system-specific or not) way of accessing paths on the filesystem.N)r;r<r=r>rrrrrysrc@seZdZddZddZeejZeejZeejZeej Z eej Z eej Z e edrjeej Z nddZ eejZeejZeejZeejZeejZerereejZqdd Zn ed d ZeejZd d Zd S)_NormalAccessorcstjfdd}t|S)Ncst|f|S)N)r])pathobjargs)strfuncrrwrappedsz._NormalAccessor._wrap_strfunc..wrapped) functoolswraps staticmethod)rrr)rr _wrap_strfuncsz_NormalAccessor._wrap_strfunccstjfdd}t|S)Ncst|t|f|S)N)r])ZpathobjAZpathobjBr)rrrrsz5_NormalAccessor._wrap_binary_strfunc..wrapped)rrr)rrr)rr_wrap_binary_strfuncsz$_NormalAccessor._wrap_binary_strfunclchmodcCs tddS)Nz%lchmod() not available on this system)NotImplementedError)r$rmoderrrrsz_NormalAccessor.lchmodcCs tddS)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$rbrrrrsz_NormalAccessor.readlinkN)r;r<r=rrr^statlstatopenlistdirscandirchmodhasattrrmkdirunlinkrmdirrenamer*rsupports_symlinksrrutimerrrrrr~s.                 rcCsP|d}|dd}|dkr"t}n$d|kr4tdnt|rBt}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.cCs.||_|rt||_d|_nt|_d|_dS)NTF)rr successordironly_TerminatingSelector)r$rrrrr%s  z_Selector.__init__cCs<t|}|j}|j}|jj}||s,tgS|j||||S)zuIterate over all child paths of `parent_path` matched by this selector. This can contain parent_path itself.)typeis_direxistsrriter _select_from)r$ parent_pathZpath_clsrrrrrr select_fromsz_Selector.select_fromN)r;r<r=r>r%rrrrrrs rc@seZdZddZdS)rccs |VdS)Nr)r$rrrrrrrrsz!_TerminatingSelector._select_fromN)r;r<r=rrrrrrsrc@seZdZddZddZdS)rcCs||_tj||dS)N)r|rr%)r$r|rrrrr%sz_PreciseSelector.__init__c cs^yD|j|j}|jr|n||rBx |jj||||D] }|Vq4WWntk rXdSXdS)N)_make_child_relpathr|rrrPermissionError)r$rrrrrbrZrrrrs z_PreciseSelector._select_fromN)r;r<r=r%rrrrrrsrc@seZdZddZddZdS)rcCs"tjtj||_tj||dS)N)recompilefnmatch translaterrr%)r$rrrrrr%sz_WildcardSelector.__init__c csy||jj}t||}xb|D]Z}|j s0|jr|j}||} |jj| r|j|} x |j j | |||D] } | VqhWqWWnt k rdSXdS)N) _flavourr9listrrr|rmatchrrrr) r$rrrrcfentriesentryr|Z casefoldedrbrZrrrrs    z_WildcardSelector._select_fromN)r;r<r=r%rrrrrrsrc@s$eZdZddZddZddZdS)rcCstj||dS)N)rr%)r$rrrrrr%sz#_RecursiveWildcardSelector.__init__c csz|VyZt||}xH|D]@}|jr|j r|j|j}x|j|||D] }|VqLWqWWntk rtdSXdS)N)rr is_symlinkrr|_iterate_directoriesr)r$rrrrrrbrZrrrrs   z/_RecursiveWildcardSelector._iterate_directoriesc csyjt}zT|jj}xF|j|||D]4}x.|||||D]}||kr6|V|j|q6Wq"WWd|jXWntk r~dSXdS)N)r~rrraddclearr) r$rrrrZyieldedZsuccessor_selectZstarting_pointrZrrrr*sz'_RecursiveWildcardSelector._select_fromN)r;r<r=r%rrrrrrrs rc@s4eZdZdZdZddZdd 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_partscCs&t||_|j|_|j|_|j|_dS)N)rrrrr)r$rbrrrr%Cs z_PathParents.__init__cCs(|js |jrt|jdSt|jSdS)Nr8)rrrQr)r$rrr__len__Js z_PathParents.__len__cCs@|dks|t|krt||jj|j|j|jd| dS)Nrr8)rQ IndexErrorr_from_parsed_partsrrr)r$idxrrr __getitem__Psz_PathParents.__getitem__cCsdj|jjS)Nz <{}.parents>)formatrr;)r$rrr__repr__Vsz_PathParents.__repr__N)rrrr) r;r<r=r> __slots__r%rrrrrrrr>s rc@seZdZdZdZZd d Zd d Zed dZed[ddZ ed\ddZ eddZ ddZ ddZ ddZddZddZd d!Zd"d#Zd$d%Zed&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zeedd4d5Zeedd6d5Zed7d8Zed9d:Z ed;d<Z!ed=d>Z"ed?d@Z#dAdBZ$dCdDZ%dEdFZ&edGdHZ'dIdJZ(dKdLZ)dMdNZ*edOdPZ+edQdRZ,dSdTZ-dUdVZ.dWdXZ/dYS)]ra|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$|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. r)rr^r|rr _from_parts)rrrrr__new__hszPurePath.__new__cCs|jt|jfS)N) __class__tupler)r$rrr __reduce__rszPurePath.__reduce__cCshg}xV|D]N}t|tr$||j7}q tj|}t|trH|jt|q tdt|q W|j j |S)NzNargument should be a str object or an os.PathLike object returning str, not %r) isinstancerrr^fspathr]r- TypeErrorrrr7)rrr1rErrr _parse_argsws     zPurePath._parse_argsTcCs<tj|}|j|\}}}||_||_||_|r8|j|S)N)objectrrrrr_init)rrinitr$r2r3r1rrrrs zPurePath._from_partscCs,tj|}||_||_||_|r(|j|S)N)rrrrrr)rr2r3r1rr$rrrrs zPurePath._from_parsed_partscCs4|s|r$|||jj|ddS|jj|SdS)Nr8)rr#)rr2r3r1rrr_format_parsed_partsszPurePath._format_parsed_partscCsdS)Nr)r$rrrrszPurePath._initcCs@|j|\}}}|jj|j|j|j|||\}}}|j|||S)N)rrr:rrrr)r$rr2r3r1rrr _make_childszPurePath._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)rAttributeErrorrrrr)r$rrr__str__s  zPurePath.__str__cCst|S)N)r])r$rrr __fspath__szPurePath.__fspath__cCs|j}t|j|jdS)zNReturn the string representation of the path with forward (/) slashes.rA)rr]r*r")r$frrrrmszPurePath.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;rm)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)rrrrq)r$rrras_uriszPurePath.as_uric Cs2y|jStk r,|jj|j|_|jSXdS)N)rrrr\r)r$rrr_cpartss zPurePath._cpartscCs&t|tstS|j|jko$|j|jkS)N)rrNotImplementedrr)r$otherrrr__eq__s zPurePath.__eq__c Cs2y|jStk r,tt|j|_|jSXdS)N)rrhashrr)r$rrr__hash__s zPurePath.__hash__cCs(t|t s|j|jk rtS|j|jkS)N)rrrrr)r$rrrr__lt__szPurePath.__lt__cCs(t|t s|j|jk rtS|j|jkS)N)rrrrr)r$rrrr__le__szPurePath.__le__cCs(t|t s|j|jk rtS|j|jkS)N)rrrrr)r$rrrr__gt__szPurePath.__gt__cCs(t|t s|j|jk rtS|j|jkS)N)rrrrr)r$rrrr__ge__szPurePath.__ge__z.The drive prefix (letter or UNC path), if any.)doczThe root of the path, if any.cCs|j|j}|S)z/The concatenation of the drive and root, or ''.)rr)r$anchorrrrr s zPurePath.anchorcCs.|j}t||js|jrdndkr&dS|dS)z!The final path component, if any.r8rr&rN)rrQrr)r$r1rrrr| sz PurePath.namecCsD|j}|jd}d|ko*t|dknr<||dSdSdS)z*The final component's last suffix, if any.r'rr8Nr&)r|rfindrQ)r$r|rIrrrsuffixs    zPurePath.suffixcCs:|j}|jdrgS|jd}dd|jdddDS)z1A list of the final component's suffixes, if any.r'cSsg|] }d|qS)r'r)rCr rrrr["sz%PurePath.suffixes..r8N)r|endswithrSr,)r$r|rrrsuffixess   zPurePath.suffixescCsD|j}|jd}d|ko*t|dknr<|d|S|SdS)z0The final path component, minus its last suffix.r'rr8N)r|r rQ)r$r|rIrrrstem$s    z PurePath.stemcCs|jstd|f|jj|f\}}}| sZ|d|jj|jjgksZ|sZ|sZt|dkrftd||j|j|j |j dd|gS)z-Return a new path with the file name changed.z%r has an empty namer8zInvalid name %rNrNrN) r|rrr7r"r(rQrrrr)r$r|r2r3r1rrr with_name.s  zPurePath.with_namecCs|j}|j|ks |jr,|j|kr,td||r<|jd sD|dkrPtd||j}|shtd|f|j}|s|||}n|dt| |}|j|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 %rr'z%r has an empty nameNr8rN) rr"r(rrgr|r rQrrrr)r$r rr|Z old_suffixrrr with_suffix9s    zPurePath.with_suffixc Gs|s td|j}|j}|j}|r8||g|dd}n|}|j|\}}}|rf||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_toNs( (zPurePath.relative_toc Cs.y|jStk r(t|j|_|jSXdS)zZAn object providing sequence-like access to the components in the filesystem path.N)rrrr)r$rrrr1ns  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$rrrrjoinpathzszPurePath.joinpathcCs |j|fS)N)r)r$keyrrr __truediv__szPurePath.__truediv__cCs|j|g|jS)N)rr)r$rrrr __rtruediv__szPurePath.__rtruediv__cCs@|j}|j}|j}t|dkr*|s&|r*|S|j|||ddS)zThe logical parent of the path.r8NrN)rrrrQr)r$r2r3r1rrrparents zPurePath.parentcCst|S)z*A sequence of this path's logical parents.)r)r$rrrparentsszPurePath.parentscCs|js dS|jj pt|jS)zSTrue if the path is absolute (has both a root and, if applicable, a drive).F)rrryboolr)r$rrrrszPurePath.is_absolutecCs|jj|jS)zaReturn True if the path contains one of the special names reserved by the system, if any.)rrkr)r$rrrrkszPurePath.is_reservedc Cs|jj}||}|jj|f\}}}|s0td|rF|||jkrFdS|r\|||jkr\dS|j}|sj|rt|t|kr~dS|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)T)T)0r;r<r=r>rrr classmethodrrrrrrrrrmrrrpropertyrrrrrrrrrlr3r r|r rrrrrr1rrrrrrrkrrrrrrZs^            c@seZdZdZeZfZdS)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. N)r;r<r=r>_posix_flavourrrrrrrrsc@seZdZdZeZfZdS)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. N)r;r<r=r>_windows_flavourrrrrrrrsc@seZdZdZdaZddZdbddZd d Zd d Zd dZ ddZ dcddZ ddddZ e ddZe ddZddZddZdd Zd!d"Zd#d$Zded&d'Zd(d)Zd*d+Zd,d-Zdgd0d1Zd2d3Zdhd4d5Zd6d7Zdid8d9Zdjd;d<Zdkd=d>Zd?d@Z dAdBZ!dCdDZ"dEdFZ#dGdHZ$dIdJZ%dKdLZ&dldMdNZ'dOdPZ(dQdRZ)dSdTZ*dUdVZ+dWdXZ,dYdZZ-d[d\Z.d]d^Z/d_d`Z0dS)mraPurePath 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. r_closedcOsL|tkrtjdkrtnt}|j|dd}|jjs@td|j f|j |S)NrF)rz$cannot instantiate %r on your system) rr^r|rrrrr}rr;r)rrkwargsr$rrrrs z Path.__new__NcCs"d|_|dk r|j|_nt|_dS)NF)r r_normal_accessor)r$templaterrrrs z Path._initcCs|j|g}|j|j|j|S)N)rrrr)r$r5r1rrrrs zPath._make_child_relpathcCs|jr|j|S)N)r  _raise_closed)r$rrr __enter__szPath.__enter__cCs d|_dS)NT)r )r$tvtbrrr__exit__sz Path.__exit__cCs tddS)NzI/O operation on closed path)r)r$rrrr$szPath._raise_closedcCs|jj|||S)N)rr)r$r|flagsrrrr_opener sz Path._openercCs|jr|j|jj|||S)zm Open the file pointed by this path and return a file descriptor, as os.open() does. )r r$rr)r$r+rrrr _raw_openszPath._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)rrx)rrrrhome!sz Path.homec CsB|j}y |j}Wntk r2tj|}YnXtjj||S)zoReturn whether other_path is the same or not as this file (as returned by os.path.samefile()). )rrr^rbsamestat)r$Z other_pathstZother_strrrsamefile(s  z Path.samefileccsL|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'r4)r r$rrr)r$r|rrriterdir3s z Path.iterdirccsl|stdj||jj|}|jj|f\}}}|s:|rBtdtt|}x|j|D] }|VqZWdS)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$patternr2r3rselectorrZrrrglobAs  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)r9)rr9r7rrrr)r$r6r2r3rr7rZrrrrglobOs z Path.rglobcCsD|jr|j|jr|S|jtjg|jdd}|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)r#)r r$rrr^r_rr)r$objrrrabsolute[s z Path.absoluteFcCsh|jr|j|jj||d}|dkr:|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). )rcNF)r)r#) r r$rrerr]r<r{normpathrr)r$rcrYZnormedr;rrrrems  z Path.resolvecCs |jj|S)zh Return the result of the stat() system call on this path, like os.stat() does. )rr)r$rrrrsz Path.statcCsddl}|j|jjjS)z: Return the login name of the file owner. rN)rrrst_uidZpw_name)r$rrrrownersz Path.ownercCsddl}|j|jjjS)z8 Return the group name of the file gid. rN)grpZgetgrgidrst_gidZgr_name)r$r@rrrgroupsz Path.grouprr8c Cs,|jr|jtjt|||||||jdS)z| Open the file pointed by this path and return a file object, as the built-in open() function does. )opener)r r$iorr]r,)r$r bufferingencodingerrorsnewlinerrrrsz Path.openc Cs |jdd }|jSQRXdS)zK Open the file in bytes mode, read it, and close the file. rb)rN)rread)r$rrrr read_bytesszPath.read_bytesc Cs$|jd||d }|jSQRXdS)zJ Open the file in text mode, read it, and close the file. rC)rrGrHN)rrK)r$rGrHrrrr read_textszPath.read_textc Cs*t|}|jdd }|j|SQRXdS)zO Open the file in bytes mode, write to it, and close the file. wb)rN) memoryviewrwrite)r$dataZviewrrrr write_bytesszPath.write_bytesc Cs@t|tstd|jj|jd||d }|j|SQRXdS)zN Open the file in text mode, write to it, and close the file. zdata must be str, not %sw)rrGrHN)rr]rrr;rrP)r$rQrGrHrrrr write_texts   zPath.write_textTc Csr|jr|j|r>y|jj|dWntk r8YnXdStjtjB}|sX|tjO}|j ||}tj |dS)zS Create this file with the given access mode, if it doesn't exist. N) r r$rrrr^O_CREATO_WRONLYO_EXCLr.close)r$rexist_okr+fdrrrtouchs   z Path.touchc Cs|jr|jy|jj||Wnjtk rf| s@|j|krB|jjddd|j|d|dYn&tk r| s|j rYnXdS)z< Create a new directory at this given path. T)rrYFN)r r$rrrarrr)r$rrrYrrrrsz Path.mkdircCs |jr|j|jj||dS)zF Change the permissions of the path, like os.chmod(). N)r r$rr)r$rrrrrsz 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 r$rr)r$rrrrrsz Path.lchmodcCs|jr|j|jj|dS)zd Remove this file or link. If the path is a directory, use rmdir() instead. N)r r$rr)r$rrrrsz Path.unlinkcCs|jr|j|jj|dS)zF Remove this directory. The directory must be empty. N)r r$rr)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 r$rr)r$rrrrsz Path.lstatcCs |jr|j|jj||dS)z5 Rename this path to the given path. N)r r$rr)r$rrrrrsz Path.renamecCs |jr|j|jj||dS)zo Rename this path to the given path, clobbering the existing destination if it exists. N)r r$rr*)r$rrrrr*sz 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 r$rr)r$rrrrr symlink_to(szPath.symlink_tocCsBy |jWn0tk r<}z|jttfkr.dSd}~XnXdS)z+ Whether this path exists. FNT)rrrrr)r$rrrrr3s z Path.existscCsDyt|jjStk r>}z|jttfkr0dSd}~XnXdS)z3 Whether this path is a directory. FN)rrst_moderrrr)r$rrrrr?s z Path.is_dircCsDyt|jjStk r>}z|jttfkr0dSd}~XnXdS)zq Whether this path is a regular file (also True for symlinks pointing to regular files). FN)r rr]rrrr)r$rrrris_fileLs z Path.is_filecCsDyt|jjStk r>}z|jttfkr0dSd}~XnXdS)z7 Whether this path is a symbolic link. FN)r rr]rrrr)r$rrrrrZs zPath.is_symlinkcCsDyt|jjStk r>}z|jttfkr0dSd}~XnXdS)z6 Whether this path is a block device. FN)r rr]rrrr)r$rrrris_block_devicefs zPath.is_block_devicecCsDyt|jjStk r>}z|jttfkr0dSd}~XnXdS)z: Whether this path is a character device. FN)r rr]rrrr)r$rrrris_char_devicess zPath.is_char_devicecCsDyt|jjStk r>}z|jttfkr0dSd}~XnXdS)z. Whether this path is a FIFO. FN)rrr]rrrr)r$rrrris_fifos z Path.is_fifocCsDyt|jjStk r>}z|jttfkr0dSd}~XnXdS)z0 Whether this path is a socket. FN)r rr]rrrr)r$rrrr is_sockets zPath.is_socketcCsb|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~)rrrrrxr)r$Zhomedirrrr expandusers zPath.expanduser)rr )N)r*)r-)FrN)rCrNNNN)NN)NN)r*T)r-FF)F)1r;r<r=r>rrrrr%r)r$r,r.rr/r0r3r5r8r:r<rerr?rBrrLrMrRrTr[rrrrrrrr*r\rrr^rr_r`rarbrdrrrrrs^                      c@seZdZdZfZdS)rzsPath subclass for non-Windows systems. On a POSIX system, instantiating a Path should return this object. N)r;r<r=r>rrrrrrsc@s$eZdZdZfZddZddZdS)rzqPath subclass for Windows systems. On a Windows system, instantiating a Path should return this object. cCs tddS)Nz*Path.owner() is unsupported on this system)r)r$rrrr?szWindowsPath.ownercCs tddS)Nz*Path.group() is unsupported on this system)r)r$rrrrBszWindowsPath.groupN)r;r<r=r>rr?rBrrrrrs)rr)>rrrErzr^rrr. collectionsr contextlibrrrrroperatorrrrr r r r r rZ urllib.parserrnrr|rZgetwindowsversionr__all__r rr!r?rrrrrr"rrrrrrrrrrPathLikeregisterrrrrrrrrrsl   $   ?(c=  %f   Q