3 �L�j���@s$ddlZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z mZmZmZddlmZddlmZmZmZmZmZmZmZddlmZdZd d d d d dgZdZ dZ!dZ"dd�Z#Gdd�de$�Z%Gdd�de%�Z&Gdd�de%�Z'e&�Z(e'�Z)Gdd�d�Z*Gdd�de*�Z+e+�Z,dd�Z-e.ed ��rTej/�e-�Z-Gd!d"�d"�Z0Gd#d$�d$�Z1Gd%d&�d&e0�Z2Gd'd(�d(e0�Z3Gd)d*�d*e0�Z4Gd+d,�d,e �Z5Gd-d �d e$�Z6ej7j8e6�Gd.d �d e6�Z9Gd/d �d e6�Z:Gd0d �d e6�Z;Gd1d �d e;e9�Zssz_WindowsFlavour.�a�zr7ccs|]}t|�VqdS)N)rB)rCr5rrrrDts�A�Zz\\?\ZCONZPRNZAUXZNULcCsh|] }d|�qS)zCOM%dr)rC�irrr� zsz_WindowsFlavour.� cCsh|] }d|�qS)zLPT%dr)rCrIrrrrJ{sc Csb|dd�}|dd�}||krP||krP|j|�\}}|dd�}|dd�}nd}|dd�}||kov||kov||k�r|j|d�}|dk�r|j||d�}||dk�r|dkr�t|�}|r�||d|�|||dd�fS|d|�|||dd�fSd} } |dk�r<||jk�r<|dd�} |dd�}|}||k�rT|} |j|�}|| | |fS) Nrr7�r%��:�����rO)�_split_extended_path�find�len� drive_letters�lstrip) r#r4r!�first�second�prefixZthird�indexZindex2r1r2rrrr*�s6      "    z_WindowsFlavour.splitrootcCs|j�S)N)�lower)r#�srrrr8�sz_WindowsFlavour.casefoldcCsdd�|D�S)NcSsg|] }|j��qSr)rY)rC�prrr� �sz2_WindowsFlavour.casefold_parts..r)r#r0rrr�casefold_parts�sz_WindowsFlavour.casefold_partscCsXd}|j|�rP|dd�}|dd�}|jd�rP||dd�7}d|dd�}||fS)Nr%�zUNC\rMr?)� startswith)r#rZZ ext_prefixrWrrrrP�s    z$_WindowsFlavour._split_extended_pathcCs6|sdS|djd�rdS|djd�dj�|jkS)NFrz\\r7r&rO)r_� partition�upper�reserved_names)r#r0rrr� is_reserved�s z_WindowsFlavour.is_reservedcCsd|j}t|�dkrJ|ddkrJ|j�dd�jd�}d|t|jd��fSdt|j�jd��SdS)NrLr7rNr@z file:///%s/%szutf-8zfile:)�driverR�as_posixrT�urlquote_from_bytes�encode)r#�pathrd�restrrr�make_uri�s z_WindowsFlavour.make_uric Cs�dtjkrtjd}n`dtjkr,tjd}nJdtjkrnytjd}Wntk r\d}YnX|tjd}ntd��|r�tjd|kr�|j|f�\}}}|d tjdkr�td |��||d <|s�|r�|||j|dd��}n |j|�}|S) N�HOMEZ USERPROFILEZHOMEPATHZ HOMEDRIVEr%zCan't determine home directoryZUSERNAMEr7z%Can't determine home directory for %rrOrO)�os�environ�KeyError� RuntimeErrorr6r")r#�username�userhomer1r2r0rrr� gethomedir�s,       z_WindowsFlavour.gethomedirN)r:r;r<r!r'�has_drv�ntpath�pathmodrl�name� is_supported�set�range�ordrSZext_namespace_prefixrbr*r8r]rPrcrjrrrrrrr>gs" "& '   r>c@sZeZdZdZdZdZeZej dkZ efdd�Z dd�Z d d �Z d d �Zd d�Zdd�ZdS)� _PosixFlavourr@r%FrAcCsV|rH|d|krH|j|�}t|�t|�dkr.wrapped)� functools�wraps� staticmethod)r�r�r)r�r� _wrap_strfunc3sz_NormalAccessor._wrap_strfunccstj���fdd��}t|�S)Ncs�t|�t|�f|��S)N)r�)ZpathobjAZpathobjBr�)r�rrr�:sz5_NormalAccessor._wrap_binary_strfunc..wrapped)r�r�r�)r�r�r)r�r�_wrap_binary_strfunc9sz$_NormalAccessor._wrap_binary_strfunc�lchmodcCs td��dS)Nz%lchmod() not available on this system)�NotImplementedError)r#r��moderrrr�Nsz_NormalAccessor.lchmod�symlinkFcCs td��dS)Nz)os.symlink() not available on this system)r�)r#�src�dst�target_is_directoryrrrr�^sz_NormalAccessor.symlinkcCs tj|�S)N)rl�readlink)r#rhrrrr�esz_NormalAccessor.readlinkN)F)r:r;r<r�r�rl�stat�lstat�open�listdir�scandir�chmod�hasattrr��mkdir�unlink�rmdir�renamer)r��utimer��getcwdr�rh� expanduser�realpathrrrrr�1s0                 r�cCsP|d}|dd�}|dkr"t}n$d|kr4td��nt|�rBt}nt}|||�S)Nrr7z**z:Invalid pattern: '**' can only be an entire path component)�_RecursiveWildcardSelector� ValueErrorr�_WildcardSelector�_PreciseSelector)� pattern_partsr� child_parts�clsrrr�_make_selectorvs  r�� lru_cachec@s eZdZdZdd�Zdd�ZdS)� _SelectorzYA selector matches a specific glob pattern part against the children of a given path.cCs.||_|rt|�|_d|_nt�|_d|_dS)NTF)r�r�� successor�dironly�_TerminatingSelector)r#r�rrrr$�s  z_Selector.__init__cCs<t|�}|j}|j}|jj}||�s,tg�S|j||||�S)zuIterate over all child paths of `parent_path` matched by this selector. This can contain parent_path itself.)�type�is_dir�exists� _accessorr��iter� _select_from)r#� parent_pathZpath_clsr�r�r�rrr� select_from�sz_Selector.select_fromN)r:r;r<r=r$r�rrrrr��s r�c@seZdZdd�ZdS)r�ccs |VdS)Nr)r#r�r�r�r�rrrr��sz!_TerminatingSelector._select_fromN)r:r;r<r�rrrrr��sr�c@seZdZdd�Zdd�ZdS)r�cCs||_tj||�dS)N)rvr�r$)r#rvr�rrrr$�sz_PreciseSelector.__init__c cs^yD|j|j�}|jr|n||�rBx |jj||||�D] }|Vq4WWntk rXdSXdS)N)�_make_child_relpathrvr�r�r��PermissionError)r#r�r�r�r�rhr[rrrr��s z_PreciseSelector._select_fromN)r:r;r<r$r�rrrrr��sr�c@seZdZdd�Zdd�ZdS)r�cCs"tjtj|��|_tj||�dS)N)�re�compile�fnmatch� translaterr�r$)r#rr�rrrr$�sz_WildcardSelector.__init__c cs�y||jj}t||��}xb|D]Z}|j s0|j�r|j}||�} |jj| �r|j|�} x |j j | |||�D] } | VqhWqWWnt k r�dSXdS)N) �_flavourr8�listr�r�rvr�matchr�r�r�r�) r#r�r�r�r��cf�entries�entryrvZ casefoldedrhr[rrrr��s    z_WildcardSelector._select_fromN)r:r;r<r$r�rrrrr��sr�c@s$eZdZdd�Zdd�Zdd�ZdS)r�cCstj||�dS)N)r�r$)r#rr�rrrr$�sz#_RecursiveWildcardSelector.__init__c csz|VyZt||��}xH|D]@}|j�r|j� r|j|j�}x|j|||�D] }|VqLWqWWntk rtdSXdS)N)r�r�� is_symlinkr�rv�_iterate_directoriesr�)r#r�r�r�r�r�rhr[rrrr��s   z/_RecursiveWildcardSelector._iterate_directoriesc cs�yjt�}zT|jj}xF|j|||�D]4}x.|||||�D]}||kr6|V|j|�q6Wq"WWd|j�XWntk r~dSXdS)N)rxr�r�r��add�clearr�) r#r�r�r�r�ZyieldedZsuccessor_selectZstarting_pointr[rrrr��sz'_RecursiveWildcardSelector._select_fromN)r:r;r<r$r�r�rrrrr��s r�c@s4eZdZdZdZdd�Zdd �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)r�r�r�r�r�)r#rhrrrr$�s z_PathParents.__init__cCs(|js |jrt|j�dSt|j�SdS)Nr7)r�r�rRr�)r#rrr�__len__�s z_PathParents.__len__cCs@|dks|t|�krt|��|jj|j|j|jd| d��S)Nrr7)rR� IndexErrorr��_from_parsed_partsr�r�r�)r#�idxrrr� __getitem__sz_PathParents.__getitem__cCsdj|jj�S)Nz <{}.parents>)�formatr�r:)r#rrr�__repr__ sz_PathParents.__repr__N)r�r�r�r�) r:r;r<r=� __slots__r$r�r�r�rrrrr��s r�c@s�eZdZdZdZZd d �Zd d �Zed d��Zed[dd��Z ed\dd��Z edd��Z dd�Z dd�Z dd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zed&d'��Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zeed�d4d5�Zeed�d6d5�Zed7d8��Zed9d:��Z ed;d<��Z!ed=d>��Z"ed?d@��Z#dAdB�Z$dCdD�Z%dEdF�Z&edGdH��Z'dIdJ�Z(dKdL�Z)dMdN�Z*edOdP��Z+edQdR��Z,dSdT�Z-dUdV�Z.dWdX�Z/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. r�r�r��_str�_hash�_pparts�_cached_cpartscGs$|tkrtjdkrtnt}|j|�S)z�Construct 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. rA)rrlrvrr� _from_parts)r�r�rrr�__new__szPurePath.__new__cCs|jt|j�fS)N)� __class__�tupler�)r#rrr� __reduce__&szPurePath.__reduce__cCshg}xV|D]N}t|t�r$||j7}q tj|�}t|t�rH|jt|��q tdt|���q W|j j |�S)NzNargument should be a str object or an os.PathLike object returning str, not %r) � isinstancerr�rl�fspathr�r,� TypeErrorr�r�r6)r�r�r0rErrr� _parse_args+s     zPurePath._parse_argsTcCs<tj|�}|j|�\}}}||_||_||_|r8|j�|S)N)�objectr�r�r�r�r��_init)r�r��initr#r1r2r0rrrr�?s zPurePath._from_partscCs,tj|�}||_||_||_|r(|j�|S)N)r�r�r�r�r�r�)r�r1r2r0r�r#rrrr�Ls zPurePath._from_parsed_partscCs4|s|r$|||jj|dd��S|jj|�SdS)Nr7)r�r")r�r1r2r0rrr�_format_parsed_partsVszPurePath._format_parsed_partscCsdS)Nr)r#rrrr�]szPurePath._initcCs@|j|�\}}}|jj|j|j|j|||�\}}}|j|||�S)N)r�r�r9r�r�r�r�)r#r�r1r2r0rrr� _make_childaszPurePath._make_childc Cs<y|jStk r6|j|j|j|j�p,d|_|jSXdS)z[Return the string representation of the path, suitable for passing to system calls.r&N)r��AttributeErrorr�r�r�r�)r#rrr�__str__gs  zPurePath.__str__cCst|�S)N)r�)r#rrr� __fspath__qszPurePath.__fspath__cCs|j}t|�j|jd�S)zNReturn the string representation of the path with forward (/) slashes.r@)r�r�r)r!)r#�frrrretszPurePath.as_posixcCstjt|��S)zaReturn the bytes representation of the path. This is only recommended to use under Unix.)rl�fsencoder�)r#rrr� __bytes__zszPurePath.__bytes__cCsdj|jj|j��S)Nz{}({!r}))r�r�r:re)r#rrrr�szPurePath.__repr__cCs|j�std��|jj|�S)z Return the path as a 'file' URI.z.relative path can't be expressed as a file URI)� is_absoluter�r�rj)r#rrr�as_uri�szPurePath.as_uric Cs2y|jStk r,|jj|j�|_|jSXdS)N)r�r�r�r]r�)r#rrr�_cparts�s zPurePath._cpartscCs&t|t�stS|j|jko$|j|jkS)N)r�r�NotImplementedr�r�)r#�otherrrr�__eq__�s zPurePath.__eq__c Cs2y|jStk r,tt|j��|_|jSXdS)N)r�r��hashr�r�)r#rrr�__hash__�s zPurePath.__hash__cCs(t|t� s|j|jk rtS|j|jkS)N)r�rr�r�r�)r#r�rrr�__lt__�szPurePath.__lt__cCs(t|t� s|j|jk rtS|j|jkS)N)r�rr�r�r�)r#r�rrr�__le__�szPurePath.__le__cCs(t|t� s|j|jk rtS|j|jkS)N)r�rr�r�r�)r#r�rrr�__gt__�szPurePath.__gt__cCs(t|t� s|j|jk rtS|j|jkS)N)r�rr�r�r�)r#r�rrr�__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 ''.)r�r�)r#�anchorrrrr��s zPurePath.anchorcCs.|j}t|�|js|jrdndkr&dS|dS)z!The final path component, if any.r7rr%rO)r�rRr�r�)r#r0rrrrv�sz PurePath.namecCsD|j}|jd�}d|ko*t|�dknr<||d�SdSdS)z*The final component's last suffix, if any.r&rr7Nr%)rv�rfindrR)r#rvrIrrr�suffix�s    zPurePath.suffixcCs:|j}|jd�rgS|jd�}dd�|jd�dd�D�S)z1A list of the final component's suffixes, if any.r&cSsg|] }d|�qS)r&r)rCr�rrrr\�sz%PurePath.suffixes..r7N)rv�endswithrTr+)r#rvrrr�suffixes�s   zPurePath.suffixescCsD|j}|jd�}d|ko*t|�dknr<|d|�S|SdS)z0The final path component, minus its last suffix.r&rr7N)rvr�rR)r#rvrIrrr�stem�s    z PurePath.stemcCs�|jstd|f��|jj|f�\}}}| sZ|d|jj|jjgksZ|sZ|sZt|�dkrftd|��|j|j|j |j dd�|g�S)z-Return a new path with the file name changed.z%r has an empty namer7zInvalid name %rNrOrO) rvr�r�r6r!r'rRr�r�r�r�)r#rvr1r2r0rrr� 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�|g�S)z�Return 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 nameNr7rO) r�r!r'r�r_rvr�rRr�r�r�r�)r#r�r�rvZ old_suffixrrr� with_suffix�s    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|| d��S)z�Return 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 argumentr7Nrz{!r} does not start with {!r}r%) r�r�r�r�r�rRr�r]r�r�r�r�r�) r#r�r0r1r2Z abs_partsZto_drvZto_rootZto_partsZ to_abs_parts�nr�Z formattedrrr� relative_tos( (zPurePath.relative_toc Cs.y|jStk r(t|j�|_|jSXdS)zZAn object providing sequence-like access to the components in the filesystem path.N)r�r�r�r�)r#rrrr0"s  zPurePath.partscGs |j|�S)z�Combine 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#r�rrr�joinpath.szPurePath.joinpathcCs |j|f�S)N)r�)r#�keyrrr� __truediv__6szPurePath.__truediv__cCs|j|g|j�S)N)r�r�)r#rrrr� __rtruediv__9szPurePath.__rtruediv__cCs@|j}|j}|j}t|�dkr*|s&|r*|S|j|||dd��S)zThe logical parent of the path.r7NrO)r�r�r�rRr�)r#r1r2r0rrr�parent<s zPurePath.parentcCst|�S)z*A sequence of this path's logical parents.)r�)r#rrr�parentsFszPurePath.parentscCs|js dS|jj pt|j�S)zSTrue if the path is absolute (has both a root and, if applicable, a drive).F)r�r�rs�boolr�)r#rrrr�KszPurePath.is_absolutecCs|jj|j�S)zaReturn True if the path contains one of the special names reserved by the system, if any.)r�rcr�)r#rrrrcRszPurePath.is_reservedc Cs�|jj}||�}|jj|f�\}}}|s0td��|rF|||j�krFdS|r\|||j�kr\dS|j}|sj|r�t|�t|�kr~dS|dd�}nt|�t|�kr�dSx.tt |�t |��D]\}}t j ||�s�dSq�WdS)zE Return True if this path matches the given pattern. z empty patternFr7NT) r�r8r6r�r�r�r�rR�zipr(r�Z fnmatchcase) r#Z path_patternr�r1r2Z pat_partsr0r4rrrrr�Ws( zPurePath.matchN)r�r�r�r�r�r�r�)T)T)0r:r;r<r=r�r�r�� classmethodr�r�r�r�r�r�r�r�rer�r�r��propertyr�r�r�r�r�r�r�rrdr2r�rvr�rrrrrr0rr r r r r�rcr�rrrrrs^            c@seZdZdZeZfZdS)rz�PurePath 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_flavourr�r�rrrrrusc@seZdZdZeZfZdS)rz�PurePath 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_flavourr�r�rrrrrsc@s�eZdZdZdaZdd�Zdbdd�Zd d �Zd d �Zd d�Z dd�Z dcdd�Z dddd�Z e dd��Ze dd��Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zded&d'�Zd(d)�Zd*d+�Zd,d-�Zdgd0d1�Zd2d3�Zdhd4d5�Zd6d7�Zdid8d9�Zdjd;d<�Zdkd=d>�Zd?d@�Z dAdB�Z!dCdD�Z"dEdF�Z#dGdH�Z$dIdJ�Z%dKdL�Z&dldMdN�Z'dOdP�Z(dQdR�Z)dSdT�Z*dUdV�Z+dWdX�Z,dYdZ�Z-d[d\�Z.d]d^�Z/d_d`�Z0dS)mra�PurePath 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)NrAF)r�z$cannot instantiate %r on your system) rrlrvrrr�r�rwr�r:r�)r�r��kwargsr#rrrr��s z Path.__new__NcCs"d|_|dk r|j|_nt|_dS)NF)rr��_normal_accessor)r#�templaterrrr��s z Path._initcCs|j|g}|j|j|j|�S)N)r�r�r�r�)r#r4r0rrrr��s zPath._make_child_relpathcCs|jr|j�|S)N)r� _raise_closed)r#rrr� __enter__�szPath.__enter__cCs d|_dS)NT)r)r#�t�v�tbrrr�__exit__�sz Path.__exit__cCs td��dS)NzI/O operation on closed path)r�)r#rrrr�szPath._raise_closed�cCs|jj|||�S)N)r�r�)r#rv�flagsr�rrr�_opener�sz Path._opener��cCs|jr|j�|jj|||�S)zm Open the file pointed by this path and return a file descriptor, as os.open() does. )rrr�r�)r#rr�rrr� _raw_open�szPath._raw_opencCs |tj��S)zjReturn a new path pointing to the current working directory (as returned by os.getcwd()). )rlr�)r�rrr�cwd�szPath.cwdcCs||�jjd��S)zrReturn a new path pointing to the user's home directory (as returned by os.path.expanduser('~')). N)r�rr)r�rrr�home�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()). )r�r�rlrh�samestat)r#Z other_path�stZother_strrr�samefile�s  z Path.samefileccsL|jr|j�x8|jj|�D](}|dkr*q|j|�V|jr|j�qWdS)zyIterate over the files in this directory. Does not yield any result for the special paths '.' and '..'. r&�..N>r&r')rrr�r�r�)r#rvrrr�iterdir�s z Path.iterdirccsl|stdj|���|jj|�}|jj|f�\}}}|s:|rBtd��tt|��}x|j|�D] }|VqZWdS)z�Iterate 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) r�r�r�r8r6r�r�r�r�)r#�patternr1r2r��selectorr[rrr�glob�s  z Path.globccs^|jj|�}|jj|f�\}}}|s(|r0td��tdt|��}x|j|�D] }|VqLWdS)z�Recursively yield all existing files (of any kind, including directories) matching the given pattern, anywhere in this subtree. z%Non-relative patterns are unsupported�**N)r,)r�r8r6r�r�r�r�)r#r)r1r2r�r*r[rrr�rglobs z Path.rglobcCsD|jr|j�|j�r|S|jtj�g|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)rrr�r�rlr�r�r�)r#�objrrr�absolutes z Path.absoluteFcCs�|jr|j�dd�}y|jj||d�}Wn,tk rV}z||��WYdd}~XnX|j|f�}|s�y |j�Wn*tk r�}z||�WYdd}~XnX|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|tkr,td|j��dS)N�winerrorrzSymlink loop from %r)�getattr�errnor�_WINERROR_CANT_RESOLVE_FILENAMEro�filename)�er0rrr� check_eloop*s z!Path.resolve..check_eloop)�strictN)rrr�r��OSErrorr�r�)r#r7r6rZr5r[rrr�resolve!s  z Path.resolvecCs |jj|�S)zh Return the result of the stat() system call on this path, like os.stat() does. )r�r�)r#rrrr�?sz Path.statcCsddl}|j|j�j�jS)z: Return the login name of the file owner. rN)r}r~r��st_uidZpw_name)r#r}rrr�ownerFsz Path.ownercCsddl}|j|j�j�jS)z8 Return the group name of the file gid. rN)�grpZgetgrgidr��st_gidZgr_name)r#r<rrr�groupMsz Path.group�rr7c Cs,|jr|j�tjt|�||||||jd�S)z| Open the file pointed by this path and return a file object, as the built-in open() function does. )�opener)rr�ior�r�r)r#r�� buffering�encoding�errors�newlinerrrr�Tsz Path.openc Cs |jdd�� }|j�SQRXdS)zK Open the file in bytes mode, read it, and close the file. �rb)r�N)r��read)r#r�rrr� read_bytes_szPath.read_bytesc Cs$|jd||d�� }|j�SQRXdS)zJ Open the file in text mode, read it, and close the file. r?)r�rCrDN)r�rG)r#rCrDr�rrr� read_textfszPath.read_textc Cs*t|�}|jdd�� }|j|�SQRXdS)zO Open the file in bytes mode, write to it, and close the file. �wb)r�N)� memoryviewr��write)r#�dataZviewr�rrr� write_bytesmszPath.write_bytesc Cs@t|t�std|jj��|jd||d�� }|j|�SQRXdS)zN Open the file in text mode, write to it, and close the file. zdata must be str, not %s�w)r�rCrDN)r�r�r�r�r:r�rL)r#rMrCrDr�rrr� write_textvs   zPath.write_textTc Csr|jr|j�|r>y|jj|d�Wntk r8YnXdStjtjB}|sX|tjO}|j ||�}tj |�dS)zS Create this file with the given access mode, if it doesn't exist. N) rrr�r�r8rl�O_CREAT�O_WRONLY�O_EXCLr!�close)r#r��exist_okr�fdrrr�touch�s   z Path.touchc Cs�|jr|j�y|jj||�Wnjtk rf| s@|j|krB�|jjddd�|j|d|d�Yn&tk r�| s�|j� r��YnXdS)z< Create a new directory at this given path. T)r rUFN)rrr�r��FileNotFoundErrorr r8r�)r#r�r rUrrrr��sz Path.mkdircCs |jr|j�|jj||�dS)zF Change the permissions of the path, like os.chmod(). N)rrr�r�)r#r�rrrr��sz 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)rrr�r�)r#r�rrrr��sz Path.lchmodcCs|jr|j�|jj|�dS)zd Remove this file or link. If the path is a directory, use rmdir() instead. N)rrr�r�)r#rrrr��sz Path.unlinkcCs|jr|j�|jj|�dS)zF Remove this directory. The directory must be empty. N)rrr�r�)r#rrrr��sz 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. )rrr�r�)r#rrrr��sz Path.lstatcCs |jr|j�|jj||�dS)z5 Rename this path to the given path. N)rrr�r�)r#�targetrrrr��sz Path.renamecCs |jr|j�|jj||�dS)zo Rename this path to the given path, clobbering the existing destination if it exists. N)rrr�r))r#rYrrrr)�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)rrr�r�)r#rYr�rrr� symlink_to�szPath.symlink_tocCsBy |j�Wn0tk r<}z|jttfkr.�dSd}~XnXdS)z+ Whether this path exists. FNT)r�r8r2rr)r#r5rrrr��s z Path.existscCsDyt|j�j�Stk r>}z|jttfkr0�dSd}~XnXdS)z3 Whether this path is a directory. FN)r r��st_moder8r2rr)r#r5rrrr��s z Path.is_dircCsDyt|j�j�Stk r>}z|jttfkr0�dSd}~XnXdS)zq Whether this path is a regular file (also True for symlinks pointing to regular files). FN)r r�r[r8r2rr)r#r5rrr�is_file s z Path.is_filecCsDyt|j�j�Stk r>}z|jttfkr0�dSd}~XnXdS)z7 Whether this path is a symbolic link. FN)r r�r[r8r2rr)r#r5rrrr�s zPath.is_symlinkcCsDyt|j�j�Stk r>}z|jttfkr0�dSd}~XnXdS)z6 Whether this path is a block device. FN)r r�r[r8r2rr)r#r5rrr�is_block_device$s zPath.is_block_devicecCsDyt|j�j�Stk r>}z|jttfkr0�dSd}~XnXdS)z: Whether this path is a character device. FN)rr�r[r8r2rr)r#r5rrr�is_char_device1s zPath.is_char_devicecCsDyt|j�j�Stk r>}z|jttfkr0�dSd}~XnXdS)z. Whether this path is a FIFO. FN)rr�r[r8r2rr)r#r5rrr�is_fifo>s z Path.is_fifocCsDyt|j�j�Stk r>}z|jttfkr0�dSd}~XnXdS)z0 Whether this path is a socket. FN)r r�r[r8r2rr)r#r5rrr� is_socketKs zPath.is_socketcCsb|jp |j r^|jr^|jddd�dkr^|jj|jddd��}|j|g|jdd��S|S)zl Return a new path with expanded ~ and ~user constructs (as returned by os.path.expanduser) rNr7�~)r�r�r�r�rrr�)r#Zhomedirrrrr�Xs zPath.expanduser)r�r)N)r)r )FrO)r?rONNN)NN)NN)rT)r FF)F)1r:r;r<r=r�r�r�r�rrrrr!rr"r#r&r(r+r-r/r9r�r;r>r�rHrIrNrPrWr�r�r�r�r�r�r�r)rZr�r�r\r�r]r^r_r`r�rrrrr�s^                      c@seZdZdZfZdS)rzsPath subclass for non-Windows systems. On a POSIX system, instantiating a Path should return this object. N)r:r;r<r=r�rrrrrdsc@s$eZdZdZfZdd�Zdd�ZdS)rzqPath subclass for Windows systems. On a Windows system, instantiating a Path should return this object. cCs td��dS)Nz*Path.owner() is unsupported on this system)r�)r#rrrr;rszWindowsPath.ownercCs td��dS)Nz*Path.group() is unsupported on this system)r�)r#rrrr>uszWindowsPath.groupN)r:r;r<r=r�r;r>rrrrrks)>r�r�rArtrlr�r�r-� collectionsr� contextlibrr2rrrr�operatorrr�r r r r r rrZ urllib.parserrfZsupports_symlinks�__all__Z_WINERROR_NOT_READYZ_WINERROR_INVALID_NAMEr3rr�r r>r{rrr�r�rr�r�r�r�r�r�r�r�r�r�PathLike�registerrrrrrrrrr�sd   $  ? 6>  %f   [