a
    ze9                     @   sb  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	 d dl
mZmZmZmZmZ d dlmZ d dlmZmZmZmZmZmZmZ d dlmZ dZejdkrd dlZe  dd	 d
krd dlm!Z! qdZdZ!ndZg dZ"eeeefZ#dZ$dd Z%dd Z&G dd de'Z(G dd de(Z)G dd de(Z*e) Z+e* Z,G dd dZ-G dd de-Z.e. Z/dd Z0e1edre2 e0Z0G d d! d!Z3G d"d# d#Z4G d$d% d%e3Z5G d&d' d'e3Z6G d(d) d)e3Z7G d*d+ d+e	Z8G d,d- d-e'Z9ej:;e9 G d.d/ d/e9Z<G d0d1 d1e9Z=G d2d3 d3e9Z>G d4d5 d5e>e<Z?G d6d7 d7e>e=Z@dS )8    N)Sequence)EINVALENOENTENOTDIREBADFELOOP)
attrgetter)S_ISDIRS_ISLNKS_ISREGS_ISSOCKS_ISBLKS_ISCHRS_ISFIFO)quote_from_bytesTnt   )   r   )_getfinalpathnameF)PurePathPurePosixPathPureWindowsPathPath	PosixPathWindowsPath)   {   i  c                 C   s    t | dd tv pt | dd tv S )Nerrnowinerror)getattr_IGNORED_ERROS_IGNORED_WINERRORS)	exception r#   /usr/lib/python3.9/pathlib.py_ignore_error.   s    r%   c                 C   s   d| v pd| v pd| v S )N*?[r#   )patr#   r#   r$   _is_wildcard_pattern3   s    r*   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )_Flavourc                 C   s   | j j| _d S N)sepjoinselfr#   r#   r$   __init__=   s    z_Flavour.__init__c                 C   s  g }| j }| j}d }}t|}|D ]}|s.q$|r>|||}| |\}}}	||	v rt|	|D ] }
|
rd|
dkrd|t|
 qdn|	r|	dkr|t|	 |s|r$|s|D ]0}|sq|r|||}| |d }|r qq qq$|s|r|||  |	  |||fS )N .r   )
r-   altsepreversedreplace	splitrootsplitappendsysinternreverse)r0   partsparsedr-   r4   drvrootitpartrelxr#   r#   r$   parse_parts@   s@    
z_Flavour.parse_partsc                 C   sz   |r*|sp|rp|||| g|dd   fS nF|rb||ksJ|  ||  |krp||||dd   fS n|||| fS |||fS N   )casefold)r0   r?   r@   r=   drv2root2parts2r#   r#   r$   join_parsed_partsf   s    z_Flavour.join_parsed_partsN)__name__
__module____qualname__r1   rE   rL   r#   r#   r#   r$   r+   9   s   &r+   c                   @   s   e Zd ZdZdZdZeZej	dkZ
edZdZh ddd	 d
D B dd	 d
D B ZefddZdd Zdd Zdd Zd"ddZefddZdd Zdd Zdd Zdd  Zd!S )#_WindowsFlavour\/Tr   Z4abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZz\\?\>   PRNAUXzCONIN$zCONOUT$CONNULc                 C   s   h | ]}d | qS )zCOM%sr#   .0cr#   r#   r$   	<setcomp>       z_WindowsFlavour.<setcomp>u   123456789¹²³c                 C   s   h | ]}d | qS )zLPT%sr#   rW   r#   r#   r$   rZ      r[   c                 C   s\  |dd }|dd }||krP||krP|  |\}}|dd }|dd }nd}|dd }||kr||kr||kr||d}|dkr|||d }||d kr|dkrt|}|r||d|  |||d d  fS |d | |||d d  fS d }	}
|dkr6|| jv r6|d d }	|dd  }|}||krN|}
||}||	 |
|fS )Nr   rG   r   r2      :)_split_extended_pathfindlendrive_letterslstrip)r0   rB   r-   firstsecondprefixthirdindexindex2r?   r@   r#   r#   r$   r7      s6    "

z_WindowsFlavour.splitrootc                 C   s   |  S r,   lowerr0   sr#   r#   r$   rH      s    z_WindowsFlavour.casefoldc                 C   s   dd |D S )Nc                 S   s   g | ]}|  qS r#   rj   )rX   pr#   r#   r$   
<listcomp>   r[   z2_WindowsFlavour.casefold_parts.<locals>.<listcomp>r#   r0   r=   r#   r#   r$   casefold_parts   s    z_WindowsFlavour.casefold_partsc                 C   s   t t|t jjS r,   )recompilefnmatch	translate
IGNORECASE	fullmatchr0   patternr#   r#   r$   compile_pattern   s    z_WindowsFlavour.compile_patternFc                 C   s   t |}|st S d }td ur|r2| t|S g }z| t|}W n@ ty   |}tj|\}}|| ||kr| Y S Y q60 tjj	|gt
|R  S q6d S r,   )strosgetcwdr   _ext_to_normalFileNotFoundErrorpathr8   r9   r.   r5   )r0   r   strictrm   
previous_s
tail_partstailr#   r#   r$   resolve   s$    
z_WindowsFlavour.resolvec                 C   sX   d}| |rP|d d }|dd  }| drP||d d 7 }d|dd   }||fS )Nr2      zUNC\r\   rQ   )
startswith)r0   rm   
ext_prefixrf   r#   r#   r$   r_      s    

z$_WindowsFlavour._split_extended_pathc                 C   s   |  |d S rF   )r_   rl   r#   r#   r$   r~      s    z_WindowsFlavour._ext_to_normalc                 C   sJ   |sdS |d  drdS |d dd dd d}| | jv S )NFr   z\\r]   r3   r^    )r   	partitionrstripupperreserved_names)r0   r=   namer#   r#   r$   is_reserved   s    "z_WindowsFlavour.is_reservedc                 C   sd   |j }t|dkrJ|d dkrJ| dd  d}d|t|df S dt| d S d S )Nr   rG   r^   rR   zfile:///%s/%szutf-8zfile:)drivera   as_posixrc   urlquote_from_bytesencode)r0   r   r   restr#   r#   r$   make_uri   s    z_WindowsFlavour.make_uric                 C   s   dt jv rt jd }nHdt jv rVzt jd }W n tyD   d}Y n0 |t jd  }ntd|rt jd |kr| |f\}}}|d t jd krtd| ||d< |s|r|| | |d	d   }n
| |}|S )
NUSERPROFILEHOMEPATH	HOMEDRIVEr2   zCan't determine home directoryUSERNAMEr]   %Can't determine home directory for %rrG   )r|   environKeyErrorRuntimeErrorrE   r.   )r0   usernameuserhomer?   r@   r=   r#   r#   r$   
gethomedir
  s*    



z_WindowsFlavour.gethomedirN)F)rM   rN   rO   r-   r4   has_drvntpathpathmodr|   r   is_supportedsetrb   ext_namespace_prefixr   r7   rH   rq   rz   r   r_   r~   r   r   r   r#   r#   r#   r$   rP   x   s.   
'

rP   c                   @   sl   e Zd ZdZdZdZeZej	dkZ
efddZdd Zd	d
 Zdd ZdddZdd Zdd Zdd ZdS )_PosixFlavourrR   r2   Fr   c                 C   sV   |rH|d |krH| |}t|t| dkr<d|d |fS d||fS n
dd|fS d S )Nr   r   r2   )rc   ra   )r0   rB   r-   stripped_partr#   r#   r$   r7   /  s    
z_PosixFlavour.splitrootc                 C   s   |S r,   r#   rl   r#   r#   r$   rH   >  s    z_PosixFlavour.casefoldc                 C   s   |S r,   r#   rp   r#   r#   r$   rq   A  s    z_PosixFlavour.casefold_partsc                 C   s   t t|jS r,   )rr   rs   rt   ru   rw   rx   r#   r#   r$   rz   D  s    z_PosixFlavour.compile_patternc                    sJ   | j |ji  fdd | r0dnt } |t|pHS )Nc                    s   | rd} |D ]}|r|dkr*q|dkrD| \} }}q| rX| | }n|  | }|v r| } | d ur~qtd| z|}W n8 ty } z |jtkrr |} W Y d }~qd }~0 0 d |<  | |} | |< q| S )Nr2   r3   ..zSymlink loop from %r)	r   r8   
rpartitionendswithr   readlinkOSErrorr   r   )r   r   r   _newpathtargete_resolveaccessorseenr-   r   r#   r$   r   K  s4    




z'_PosixFlavour.resolve.<locals>._resolver2   )r-   	_accessoris_absoluter|   r}   r{   )r0   r   r   baser#   r   r$   r   G  s    )z_PosixFlavour.resolvec                 C   s   dS NFr#   rp   r#   r#   r$   r   w  s    z_PosixFlavour.is_reservedc                 C   s   t |}dt| S )Nzfile://)bytesr   )r0   r   bpathr#   r#   r$   r   z  s    z_PosixFlavour.make_uric                 C   sx   |s>zt jd W S  ty:   dd l}|t  j Y S 0 n6dd l}z||jW S  tyr   td| Y n0 d S )NHOMEr   r   )	r|   r   r   pwdgetpwuidgetuidpw_dirgetpwnamr   )r0   r   r   r#   r#   r$   r     s    z_PosixFlavour.gethomedirN)F)rM   rN   rO   r-   r4   r   	posixpathr   r|   r   r   r7   rH   rq   rz   r   r   r   r   r#   r#   r#   r$   r   '  s   

0r   c                   @   s   e Zd ZdS )	_AccessorN)rM   rN   rO   r#   r#   r#   r$   r     s   r   c                   @   s   e Zd ZejZejZejZejZejZej	Z	e
edr>ejZndd ZejZejZe
edrdejZnedd ZejZejZejZererejZqdd Zned	d ZejZd
d Zdd Zdd ZdS )_NormalAccessorlchmodc                 C   s   t dd S )Nz%lchmod() not available on this systemNotImplementedError)r0   pathobjmoder#   r#   r$   r     s    z_NormalAccessor.lchmodlinkc                 C   s   t dd S )Nz&os.link() not available on this systemr   r0   r   r#   r#   r$   link_to  s    z_NormalAccessor.link_toc                 C   s   t dd S )Nz&symlink() not available on this systemr   abtarget_is_directoryr#   r#   r$   symlink  s    z_NormalAccessor.symlinkc                 C   s   t | |S r,   )r|   r   r   r#   r#   r$   r     s    c                 C   s
   t |S r,   )r|   r   r0   r   r#   r#   r$   r     s    z_NormalAccessor.readlinkc                 C   s>   zdd l }|| |jjW S  ty8   tdY n0 d S )Nr   z*Path.owner() is unsupported on this system)r   r   statst_uidpw_nameImportErrorr   )r0   r   r   r#   r#   r$   owner  s
    z_NormalAccessor.ownerc                 C   s>   zdd l }|| |jjW S  ty8   tdY n0 d S )Nr   z*Path.group() is unsupported on this system)grpgetgrgidr   st_gidgr_namer   r   )r0   r   r   r#   r#   r$   group  s
    z_NormalAccessor.groupN)rM   rN   rO   r|   r   lstatopenlistdirscandirchmodhasattrr   mkdirunlinkr   r   staticmethodrmdirrenamer6   r   supports_symlinksr   utimer   r   r   r#   r#   r#   r$   r     s8   




r   c                 C   sR   | d }| dd  }|dkr"t }n$d|v r4tdnt|rBt}nt}||||S )Nr   rG   **z:Invalid pattern: '**' can only be an entire path component)_RecursiveWildcardSelector
ValueErrorr*   _WildcardSelector_PreciseSelector)pattern_partsflavourr)   child_partsclsr#   r#   r$   _make_selector  s    
r   	lru_cachec                   @   s   e Zd Zdd Zdd ZdS )	_Selectorc                 C   s0   || _ |rt||| _d| _nt | _d| _d S NTF)r   r   	successordironly_TerminatingSelector)r0   r   r   r#   r#   r$   r1     s    z_Selector.__init__c                 C   s<   t |}|j}|j}|jj}||s,tg S | ||||S r,   )typeis_direxistsr   r   iter_select_from)r0   parent_pathpath_clsr   r   r   r#   r#   r$   select_from  s    z_Selector.select_fromN)rM   rN   rO   r1   r  r#   r#   r#   r$   r     s   	r   c                   @   s   e Zd Zdd ZdS )r   c                 c   s
   |V  d S r,   r#   )r0   r   r   r   r   r#   r#   r$   r     s    z!_TerminatingSelector._select_fromN)rM   rN   rO   r   r#   r#   r#   r$   r     s   r   c                   @   s   e Zd Zdd Zdd ZdS )r   c                 C   s   || _ t| || d S r,   )r   r   r1   )r0   r   r   r   r#   r#   r$   r1     s    z_PreciseSelector.__init__c                 c   sZ   z@| | j}| jr|n||r>| j||||D ]
}|V  q2W n tyT   Y d S 0 d S r,   )_make_child_relpathr   r   r   r   PermissionError)r0   r   r   r   r   r   rn   r#   r#   r$   r     s    z_PreciseSelector._select_fromNrM   rN   rO   r1   r   r#   r#   r#   r$   r     s   r   c                   @   s   e Zd Zdd Zdd ZdS )r   c                 C   s   | || _t| || d S r,   )rz   matchr   r1   r0   r)   r   r   r#   r#   r$   r1   (  s    z_WildcardSelector.__init__c                 c   s   z||}t |}W d    n1 s(0    Y  |D ]}| jrz| sNW q6W n: ty } z"t|sj W Y d }~q6W Y d }~n
d }~0 0 |j}	| |	r6||	}
| j	|
|||D ]
}|V  qq6W n t
y   Y d S 0 d S r,   )listr   r   r   r%   r   r  r  r   r   r  )r0   r   r   r   r   
scandir_itentriesentryr   r   r   rn   r#   r#   r$   r   ,  s&    
&"

z_WildcardSelector._select_fromNr  r#   r#   r#   r$   r   &  s   r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )r   c                 C   s   t | || d S r,   )r   r1   r  r#   r#   r$   r1   G  s    z#_RecursiveWildcardSelector.__init__c                 c   s   |V  z||}t |}W d    n1 s.0    Y  |D ]v}d}z| }W n. ty~ } zt|sj W Y d }~n
d }~0 0 |r<| s<||j}	| |	||D ]
}
|
V  qq<W n ty   Y d S 0 d S r   )	r  r   r   r%   
is_symlinkr  r   _iterate_directoriesr  )r0   r   r   r   r  r	  r
  entry_is_dirr   r   rn   r#   r#   r$   r  J  s"    
&z/_RecursiveWildcardSelector._iterate_directoriesc           	      c   s   zjt  }zT| jj}| |||D ]0}|||||D ]}||vr2|V  || q2q W |  n
|  0 W n ty~   Y d S 0 d S r,   )r   r   r   r  addclearr  )	r0   r   r   r   r   yieldedsuccessor_selectstarting_pointrn   r#   r#   r$   r   ]  s    z'_RecursiveWildcardSelector._select_fromN)rM   rN   rO   r1   r  r   r#   r#   r#   r$   r   E  s   r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )_PathParents)_pathcls_drv_root_partsc                 C   s&   t || _|j| _|j| _|j| _d S r,   )r   r  r  r  r  r   r#   r#   r$   r1   v  s    
z_PathParents.__init__c                 C   s(   | j s| jrt| jd S t| jS d S rF   )r  r  ra   r  r/   r#   r#   r$   __len__}  s    z_PathParents.__len__c                 C   s@   |dk s|t | krt|| j| j| j| jd | d  S )Nr   rG   )ra   
IndexErrorr  _from_parsed_partsr  r  r  )r0   idxr#   r#   r$   __getitem__  s
    z_PathParents.__getitem__c                 C   s   d | jjS )Nz<{}.parents>)formatr  rM   r/   r#   r#   r$   __repr__  s    z_PathParents.__repr__N)rM   rN   rO   	__slots__r1   r  r  r  r#   r#   r#   r$   r  q  s
   r  c                   @   s  e Zd ZdZdd Zdd Zedd Zed[d	d
Zed\ddZ	edd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zedd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zeed/d0d1Zeed2d3d1Zed4d5 Zed6d7 Z ed8d9 Z!ed:d; Z"ed<d= Z#d>d? Z$d@dA Z%dBdC Z&dDdE Z'dFdG Z(edHdI Z)dJdK Z*dLdM Z+dNdO Z,edPdQ Z-edRdS Z.dTdU Z/dVdW Z0dXdY Z1dZS )]r   )r  r  r  _str_hash_pparts_cached_cpartsc                 G   s$   | t u rtjdkrtnt} | |S )Nr   )r   r|   r   r   r   _from_parts)r   argsr#   r#   r$   __new__  s    zPurePath.__new__c                 C   s   | j t| jfS r,   )	__class__tupler  r/   r#   r#   r$   
__reduce__  s    zPurePath.__reduce__c                 C   sd   g }|D ]N}t |tr"||j7 }qt|}t |trF|t| qtdt| q| j	
|S )NzNargument should be a str object or an os.PathLike object returning str, not %r)
isinstancer   r  r|   fspathr{   r9   	TypeErrorr   _flavourrE   )r   r%  r=   r   r#   r#   r$   _parse_args  s    


zPurePath._parse_argsTc                 C   s<   t | }||\}}}||_||_||_|r8|  |S r,   )objectr&  r.  r  r  r  _init)r   r%  initr0   r?   r@   r=   r#   r#   r$   r$    s    
zPurePath._from_partsc                 C   s,   t | }||_||_||_|r(|  |S r,   )r/  r&  r  r  r  r0  )r   r?   r@   r=   r1  r0   r#   r#   r$   r    s    
zPurePath._from_parsed_partsc                 C   s4   |s|r$|| | j |dd   S | j |S d S rF   )r-  r.   )r   r?   r@   r=   r#   r#   r$   _format_parsed_parts  s    zPurePath._format_parsed_partsc                 C   s   d S r,   r#   r/   r#   r#   r$   r0    s    zPurePath._initc                 C   s@   |  |\}}}| j| j| j| j|||\}}}| |||S r,   )r.  r-  rL   r  r  r  r  )r0   r%  r?   r@   r=   r#   r#   r$   _make_child  s
    
zPurePath._make_childc                 C   s@   z| j W S  ty:   | | j| j| jp,d| _ | j  Y S 0 d S )Nr3   )r   AttributeErrorr2  r  r  r  r/   r#   r#   r$   __str__  s    zPurePath.__str__c                 C   s   t | S r,   )r{   r/   r#   r#   r$   
__fspath__  s    zPurePath.__fspath__c                 C   s   | j }t| |jdS )NrR   )r-  r{   r6   r-   r0   fr#   r#   r$   r     s    zPurePath.as_posixc                 C   s
   t | S r,   )r|   fsencoder/   r#   r#   r$   	__bytes__  s    zPurePath.__bytes__c                 C   s   d | jj|  S )Nz{}({!r}))r  r'  rM   r   r/   r#   r#   r$   r    s    zPurePath.__repr__c                 C   s   |   std| j| S )Nz.relative path can't be expressed as a file URI)r   r   r-  r   r/   r#   r#   r$   as_uri  s    zPurePath.as_uric                 C   s6   z| j W S  ty0   | j| j| _ | j  Y S 0 d S r,   )r#  r4  r-  rq   r  r/   r#   r#   r$   _cparts  s
    zPurePath._cpartsc                 C   s&   t |tstS | j|jko$| j|ju S r,   )r*  r   NotImplementedr<  r-  r0   otherr#   r#   r$   __eq__  s    
zPurePath.__eq__c                 C   s6   z| j W S  ty0   tt| j| _ | j  Y S 0 d S r,   )r!  r4  hashr(  r<  r/   r#   r#   r$   __hash__  s
    zPurePath.__hash__c                 C   s&   t |tr| j|jurtS | j|jk S r,   r*  r   r-  r=  r<  r>  r#   r#   r$   __lt__  s    zPurePath.__lt__c                 C   s&   t |tr| j|jurtS | j|jkS r,   rC  r>  r#   r#   r$   __le__!  s    zPurePath.__le__c                 C   s&   t |tr| j|jurtS | j|jkS r,   rC  r>  r#   r#   r$   __gt__&  s    zPurePath.__gt__c                 C   s&   t |tr| j|jurtS | j|jkS r,   rC  r>  r#   r#   r$   __ge__+  s    zPurePath.__ge__c                 C   s   | S r,   r#   )r   r   r#   r#   r$   __class_getitem__0  s    zPurePath.__class_getitem__r  z.The drive prefix (letter or UNC path), if any.)docr  zThe root of the path, if any.c                 C   s   | j | j }|S r,   )r  r  )r0   anchorr#   r#   r$   rJ  9  s    zPurePath.anchorc                 C   s.   | j }t|| js| jrdndkr&dS |d S )NrG   r   r2   r]   )r  ra   r  r  rp   r#   r#   r$   r   ?  s    zPurePath.namec                 C   sD   | j }|d}d|  k r,t|d k r<n n||d  S dS d S )Nr3   r   rG   r2   r   rfindra   r0   r   ir#   r#   r$   suffixG  s
    
 zPurePath.suffixc                 C   s:   | j }|drg S |d}dd |ddd  D S )Nr3   c                 S   s   g | ]}d | qS )r3   r#   )rX   rO  r#   r#   r$   ro   `  r[   z%PurePath.suffixes.<locals>.<listcomp>rG   )r   r   rc   r8   r0   r   r#   r#   r$   suffixesU  s
    

zPurePath.suffixesc                 C   sD   | j }|d}d|  k r,t|d k r<n n|d | S |S d S )Nr3   r   rG   rK  rM  r#   r#   r$   stemb  s
    
 zPurePath.stemc                 C   s   | j std| f | j|f\}}}|rX|d | jj| jjfv sX|sX|sXt|dkrdtd| | | j| j	| j
d d |g S )N%r has an empty namer]   rG   zInvalid name %r)r   r   r-  rE   r-   r4   ra   r  r  r  r  )r0   r   r?   r@   r=   r#   r#   r$   	with_namel  s    
zPurePath.with_namec                 C   s   |  || j S r,   )rT  rO  )r0   rR  r#   r#   r$   	with_stemw  s    zPurePath.with_stemc                 C   s   | j }|j|v s |jr.|j|v r.td|f |r<|drD|dkrPtd| | j}|shtd| f | j}|s||| }n|d t|  | }| | j	| j
| jd d |g S )NzInvalid suffix %rr3   rS  r]   )r-  r-   r4   r   r   r   rO  ra   r  r  r  r  )r0   rO  r8  r   
old_suffixr#   r#   r$   with_suffix{  s    
zPurePath.with_suffixc                 G   s   |st d| j}| j}| j}|r8||g|dd   }n|}| |\}}}|rf||g|dd   }	n|}	t|	}
| jj}|
dkr|s|rn||d |
 ||	kr| |||}t	d
t| t|| d|
dkr|nd||
d  S )Nzneed at least one argumentrG   r   zU{!r} is not in the subpath of {!r} OR one path is relative and the other is absolute.r2   )r,  r  r  r  r.  ra   r-  rq   r2  r   r  r{   r  )r0   r?  r=   r?   r@   	abs_partsto_drvto_rootto_partsto_abs_partsncf	formattedr#   r#   r$   relative_to  s,    	*
zPurePath.relative_toc                 G   s*   z| j |  W dS  ty$   Y dS 0 d S r   )r`  r   r>  r#   r#   r$   is_relative_to  s
    
zPurePath.is_relative_toc                 C   s2   z| j W S  ty,   t| j| _ | j  Y S 0 d S r,   )r"  r4  r(  r  r/   r#   r#   r$   r=     s
    zPurePath.partsc                 G   s
   |  |S r,   )r3  )r0   r%  r#   r#   r$   joinpath  s    zPurePath.joinpathc                 C   s*   z|  |fW S  ty$   t Y S 0 d S r,   )r3  r,  r=  r0   keyr#   r#   r$   __truediv__  s    zPurePath.__truediv__c                 C   s0   z|  |g| j W S  ty*   t Y S 0 d S r,   )r$  r  r,  r=  rc  r#   r#   r$   __rtruediv__  s    zPurePath.__rtruediv__c                 C   s@   | j }| j}| j}t|dkr*|s&|r*| S | |||d d S )NrG   r]   )r  r  r  ra   r  )r0   r?   r@   r=   r#   r#   r$   parent  s    zPurePath.parentc                 C   s   t | S r,   )r  r/   r#   r#   r$   parents  s    zPurePath.parentsc                 C   s   | j s
dS | jj pt| jS r   )r  r-  r   boolr  r/   r#   r#   r$   r     s    zPurePath.is_absolutec                 C   s   | j | jS r,   )r-  r   r  r/   r#   r#   r$   r     s    zPurePath.is_reservedc           	      C   s   | j j}||}| j |f\}}}|s0td|rF||| jkrFdS |r\||| jkr\dS | j}|sj|rt|t|kr~dS |dd  }nt|t|krdS tt	|t	|D ]\}}t
||s dS qdS )Nzempty patternFrG   T)r-  rH   rE   r   r  r  r<  ra   zipr5   rt   fnmatchcase)	r0   path_patternr^  r?   r@   	pat_partsr=   rB   r)   r#   r#   r$   r    s(    zPurePath.matchN)T)T)2rM   rN   rO   r  r&  r)  classmethodr.  r$  r  r2  r0  r3  r5  r6  r   r:  r  r;  propertyr<  r@  rB  rD  rE  rF  rG  rH  r   r   r@   rJ  r   rO  rQ  rR  rT  rU  rW  r`  ra  r=   rb  re  rf  rg  rh  r   r   r  r#   r#   r#   r$   r     sz   	

	







	!	

	
r   c                   @   s   e Zd ZeZdZdS )r   r#   N)rM   rN   rO   _posix_flavourr-  r  r#   r#   r#   r$   r     s   r   c                   @   s   e Zd ZeZdZdS )r   r#   N)rM   rN   rO   _windows_flavourr-  r  r#   r#   r#   r$   r     s   r   c                   @   s  e Zd ZdZdd ZdcddZdd Zd	d
 Zdd ZddddZ	deddZ
edd Zedd Zdd Zdd Zdd Zdd Zdd  Zdfd"d#Zd$d% Zd&d' Zd(d) Zdgd,d-Zd.d/ Zdhd0d1Zd2d3 Zdid4d5Zd6d7 Zdjd9d:Zdkd;d<Zd=d> Zd?d@ Z dldAdBZ!dCdD Z"dEdF Z#dGdH Z$dIdJ Z%dmdKdLZ&dMdN Z'dOdP Z(dQdR Z)dSdT Z*dUdV Z+dWdX Z,dYdZ Z-d[d\ Z.d]d^ Z/d_d` Z0dadb Z1dS )nr   )r   c                 O   sL   | t u rtjdkrtnt} | j|dd}|jjs@td| j	f |
  |S )Nr   Fr1  z$cannot instantiate %r on your system)r   r|   r   r   r   r$  r-  r   r   rM   r0  )r   r%  kwargsr0   r#   r#   r$   r&  7  s    zPath.__new__Nc                 C   s   |d ur|j | _ nt| _ d S r,   )r   _normal_accessor)r0   templater#   r#   r$   r0  A  s    
z
Path._initc                 C   s   | j |g }| | j| j|S r,   )r  r  r  r  )r0   rB   r=   r#   r#   r$   r  J  s    zPath._make_child_relpathc                 C   s   | S r,   r#   r/   r#   r#   r$   	__enter__P  s    zPath.__enter__c                 C   s   d S r,   r#   )r0   tvtbr#   r#   r$   __exit__S  s    	zPath.__exit__  c                 C   s   | j | ||S r,   r   r   )r0   r   flagsr   r#   r#   r$   _opener^  s    zPath._opener  c                 C   s   | j | ||S r,   r|  )r0   r}  r   r#   r#   r$   	_raw_openb  s    zPath._raw_openc                 C   s   | t  S r,   )r|   r}   r   r#   r#   r$   cwdk  s    zPath.cwdc                 C   s   | |  j d S r,   )r-  r   r  r#   r#   r$   homer  s    z	Path.homec                 C   sB   |   }z|  }W n ty2   | j |}Y n0 tj||S r,   )r   r4  r   r|   r   samestat)r0   
other_pathstother_str#   r#   r$   samefiley  s    zPath.samefilec                 c   s,   | j | D ]}|dv rq| |V  qd S )N>   r   r3   )r   r   r  rP  r#   r#   r$   iterdir  s    zPath.iterdirc                 c   sn   t d| | |s td|| j|f\}}}|s<|rDtdtt|| j}|	| D ]
}|V  q^d S )Nzpathlib.Path.globzUnacceptable pattern: {!r}%Non-relative patterns are unsupported)
r:   auditr   r  r-  rE   r   r   r(  r  r0   ry   r?   r@   r   selectorrn   r#   r#   r$   glob  s    z	Path.globc                 c   s`   t d| | | j|f\}}}|s*|r2tdtdt| | j}|| D ]
}|V  qPd S )Nzpathlib.Path.rglobr  )r   )r:   r  r-  rE   r   r   r(  r  r  r#   r#   r$   rglob  s    z
Path.rglobc                 C   s6   |   r| S | jt g| j dd}|j| d |S NFrr  ru  )r   r$  r|   r}   r  r0  )r0   objr#   r#   r$   absolute  s
    zPath.absoluteFc                 C   sZ   | j j| |d}|d u r,|   t|  }| j j|}| j|fdd}|j| d |S )N)r   Frr  r  )	r-  r   r   r{   r  r   normpathr$  r0  )r0   r   rm   normedr  r#   r#   r$   r     s    zPath.resolvec                 C   s   | j | S r,   )r   r   r/   r#   r#   r$   r     s    z	Path.statc                 C   s   | j | S r,   )r   r   r/   r#   r#   r$   r     s    z
Path.ownerc                 C   s   | j | S r,   )r   r   r/   r#   r#   r$   r     s    z
Path.grouprr]   c              	   C   s   t j| |||||| jdS )N)opener)ior   r~  )r0   r   	bufferingencodingerrorsnewliner#   r#   r$   r     s    z	Path.openc                 C   s8   | j dd}| W  d    S 1 s*0    Y  d S )Nrbr   r   readr7  r#   r#   r$   
read_bytes  s    zPath.read_bytesc                 C   s<   | j d||d}| W  d    S 1 s.0    Y  d S )Nr  r   r  r  r  )r0   r  r  r8  r#   r#   r$   	read_text  s    zPath.read_textc                 C   sB   t |}| jdd}||W  d    S 1 s40    Y  d S )Nwbr  )
memoryviewr   write)r0   dataviewr8  r#   r#   r$   write_bytes  s    zPath.write_bytesc                 C   sX   t |tstd|jj | jd||d}||W  d    S 1 sJ0    Y  d S )Nzdata must be str, not %swr  )r*  r{   r,  r'  rM   r   r  )r0   r  r  r  r8  r#   r#   r$   
write_text  s    
zPath.write_textc                 C   s,   | j | }| j|fdd}|j| d |S r  )r   r   r$  r0  )r0   r   r  r#   r#   r$   r     s    zPath.readlinkTc                 C   sb   |r.z| j | d  W n ty(   Y n0 d S tjtjB }|sH|tjO }| ||}t| d S r,   )	r   r   r   r|   O_CREATO_WRONLYO_EXCLr  close)r0   r   exist_okr}  fdr#   r#   r$   touch  s    
z
Path.touchc                 C   sx   z| j | | W n` tyT   |r.| j| kr0 | jjddd | j|d|d Y n  tyr   |rl|  sn Y n0 d S )NT)rh  r  F)r   r   r   rg  r   r   )r0   r   rh  r  r#   r#   r$   r   &  s    z
Path.mkdirc                 C   s   | j | | d S r,   )r   r   r0   r   r#   r#   r$   r   7  s    z
Path.chmodc                 C   s   | j | | d S r,   )r   r   r  r#   r#   r$   r   =  s    zPath.lchmodc                 C   s.   z| j |  W n ty(   |s$ Y n0 d S r,   )r   r   r   )r0   
missing_okr#   r#   r$   r   D  s
    zPath.unlinkc                 C   s   | j |  d S r,   )r   r   r/   r#   r#   r$   r   O  s    z
Path.rmdirc                 C   s   | j | S r,   )r   r   r/   r#   r#   r$   r   U  s    z
Path.lstatc                 C   s   | j | | | |S r,   )r   r   r'  r   r#   r#   r$   r   \  s    
zPath.renamec                 C   s   | j | | | |S r,   )r   r6   r'  r   r#   r#   r$   r6   i  s    
zPath.replacec                 C   s   | j || | d S r,   )r   r   )r0   r   r   r#   r#   r$   
symlink_tov  s    zPath.symlink_toc                 C   s   | j | | d S r,   )r   r   r   r#   r#   r$   r   }  s    
zPath.link_toc              
   C   sT   z|    W nB ty< } zt|s& W Y d }~dS d }~0  tyN   Y dS 0 dS NFT)r   r   r%   r   r0   r   r#   r#   r$   r     s    zPath.existsc              
   C   sX   zt |  jW S  ty@ } zt|s* W Y d }~dS d }~0  tyR   Y dS 0 d S r   )r	   r   st_moder   r%   r   r  r#   r#   r$   r     s    zPath.is_dirc              
   C   sX   zt |  jW S  ty@ } zt|s* W Y d }~dS d }~0  tyR   Y dS 0 d S r   )r   r   r  r   r%   r   r  r#   r#   r$   is_file  s    zPath.is_filec                 C   sn   |   r|  sdS z| j j}W n ty8   Y dS 0 |  j}||krPdS |  j}| j j}||kS r  )r   r   rg  r   st_devr   st_ino)r0   
parent_devdevino
parent_inor#   r#   r$   is_mount  s    

zPath.is_mountc              
   C   sX   zt |  jW S  ty@ } zt|s* W Y d }~dS d }~0  tyR   Y dS 0 d S r   )r
   r   r  r   r%   r   r  r#   r#   r$   r    s    zPath.is_symlinkc              
   C   sX   zt |  jW S  ty@ } zt|s* W Y d }~dS d }~0  tyR   Y dS 0 d S r   )r   r   r  r   r%   r   r  r#   r#   r$   is_block_device  s    zPath.is_block_devicec              
   C   sX   zt |  jW S  ty@ } zt|s* W Y d }~dS d }~0  tyR   Y dS 0 d S r   )r   r   r  r   r%   r   r  r#   r#   r$   is_char_device  s    zPath.is_char_devicec              
   C   sX   zt |  jW S  ty@ } zt|s* W Y d }~dS d }~0  tyR   Y dS 0 d S r   )r   r   r  r   r%   r   r  r#   r#   r$   is_fifo  s    zPath.is_fifoc              
   C   sX   zt |  jW S  ty@ } zt|s* W Y d }~dS d }~0  tyR   Y dS 0 d S r   )r   r   r  r   r%   r   r  r#   r#   r$   	is_socket  s    zPath.is_socketc                 C   s`   | j s\| js\| jr\| jd d d dkr\| j| jd dd  }| |g| jdd   S | S )Nr   rG   ~)r  r  r  r-  r   r$  )r0   homedirr#   r#   r$   
expanduser  s    zPath.expanduser)N)r{  )r  )F)r  r]   NNN)NN)NN)r{  T)r  FF)F)F)2rM   rN   rO   r  r&  r0  r  rv  rz  r~  r  rn  r  r  r  r  r  r  r  r   r   r   r   r   r  r  r  r  r   r  r   r   r   r   r   r   r   r6   r  r   r   r   r  r  r  r  r  r  r  r  r#   r#   r#   r$   r   *  sf   	 
	

	



  
	
	

	



r   c                   @   s   e Zd ZdZdS )r   r#   N)rM   rN   rO   r  r#   r#   r#   r$   r   *  s   r   c                   @   s   e Zd ZdZdd ZdS )r   r#   c                 C   s   t dd S )Nz-Path.is_mount() is unsupported on this systemr   r/   r#   r#   r$   r  8  s    zWindowsPath.is_mountN)rM   rN   rO   r  r  r#   r#   r#   r$   r   1  s   r   )Art   	functoolsr  r   r|   r   rr   r:   _collections_abcr   r   r   r   r   r   r   operatorr   r   r	   r
   r   r   r   r   r   urllib.parser   r   r   r   r   getwindowsversionr   __all__r    r!   r%   r*   r/  r+   rP   r   rq  rp  r   r   rt  r   r   r   r   r   r   r   r   r  r   PathLikeregisterr   r   r   r   r   r#   r#   r#   r$   <module>   sr   $

? 0iF,   
    