U
    pd                     @   sj  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ddddddg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/d0 d0e	Z8G d1d de'Z9ej:;e9 G d2d de9Z<G d3d de9Z=G d4d de9Z>G d5d de>e<Z?G d6d de>e=Z@dS )7    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kpt | dd tkS )NerrnoZwinerror)getattr_IGNORED_ERROS_IGNORED_WINERRORS)Z	exception r!   /usr/lib/python3.8/pathlib.py_ignore_error.   s    r#   c                 C   s   d| kpd| kpd| kS )N*?[r!   )patr!   r!   r"   _is_wildcard_pattern3   s    r(   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	_FlavourzPA flavour implements a particular (platform-specific) set of path
    semantics.c                 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>|||}| |\}}}	||	k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)r.   partsZparsedr+   r2   drvrootitpartZ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 )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;   Zdrv2Zroot2Zparts2r!   r!   r"   join_parsed_partsf   s    z_Flavour.join_parsed_partsN)__name__
__module____qualname____doc__r/   rA   rD   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ddd	d
hdd eddD B dd e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\\?\ZCONZPRNZAUXZNULc                 C   s   h | ]}d | qS )zCOM%dr!   .0ir!   r!   r"   	<setcomp>   s     z_WindowsFlavour.<setcomp>rB   
   c                 C   s   h | ]}d | qS )zLPT%dr!   rL   r!   r!   r"   rO      s     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kr6|d d }	|dd  }|}||krN|}
||}||	 |
|fS )Nr   rB   r   r0      :)_split_extended_pathfindlendrive_letterslstrip)r.   r?   r+   firstsecondprefixZthirdindexZindex2r<   r=   r!   r!   r"   r5      s6    "

z_WindowsFlavour.splitrootc                 C   s   |  S r*   lowerr.   sr!   r!   r"   rC      s    z_WindowsFlavour.casefoldc                 C   s   dd |D S )Nc                 S   s   g | ]}|  qS r!   r]   )rM   pr!   r!   r"   
<listcomp>   s     z2_WindowsFlavour.casefold_parts.<locals>.<listcomp>r!   r.   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r.   patternr!   r!   r"   compile_pattern   s    z_WindowsFlavour.compile_patternFc                 C   s   t |}|st S d }td k	r|r2| t|S g }z| t|}W nB tk
r   |}tj|\}}|| ||kr| Y S Y q6X tjj	|ft
| S q6d S r*   )strosgetcwdr   _ext_to_normalFileNotFoundErrorpathr6   r7   r,   r3   )r.   rs   strictr`   Z
previous_sZ
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 )Nr0      zUNC\rQ   rJ   )
startswith)r.   r`   Z
ext_prefixr[   r!   r!   r"   rT      s    

z$_WindowsFlavour._split_extended_pathc                 C   s   |  |d S NrB   )rT   r_   r!   r!   r"   rq      s    z_WindowsFlavour._ext_to_normalc                 C   s6   |sdS |d  drdS |d dd  | jkS )NFr   z\\rR   r1   )rx   	partitionupperreserved_namesrc   r!   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   rB   rS   rK   zfile:///%s/%szutf-8zfile:)driverV   as_posixrX   urlquote_from_bytesencode)r.   rs   r~   restr!   r!   r"   make_uri   s     z_WindowsFlavour.make_uric                 C   s   dt jkrt jd }nJdt jkrXzt jd }W n tk
rF   d}Y nX |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 )
NZUSERPROFILEZHOMEPATHZ	HOMEDRIVEr0   zCan't determine home directoryZUSERNAMErR   %Can't determine home directory for %rrB   )ro   environKeyErrorRuntimeErrorrA   r,   )r.   usernameuserhomer<   r=   r;   r!   r!   r"   
gethomedir   s*    



z_WindowsFlavour.gethomedirN)F)rE   rF   rG   r+   r2   has_drvntpathpathmodro   nameis_supportedsetrW   Zext_namespace_prefixranger|   r5   rC   rd   rm   rv   rT   rq   r}   r   r   r!   r!   r!   r"   rI   x   s.   

'

rI   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 )_PosixFlavourrK   r0   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   r0   )rX   rV   )r.   r?   r+   Zstripped_partr!   r!   r"   r5   %  s    
z_PosixFlavour.splitrootc                 C   s   |S r*   r!   r_   r!   r!   r"   rC   4  s    z_PosixFlavour.casefoldc                 C   s   |S r*   r!   rc   r!   r!   r"   rd   7  s    z_PosixFlavour.casefold_partsc                 C   s   t t|jS r*   )re   rf   rg   rh   rj   rk   r!   r!   r"   rm   :  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|  | }|kr| } | d k	r~qtd| z|}W n6 tk
r } z|jtkrr |} W 5 d }~X Y qX d |<  | |} | |< q| S )Nr0   r1   ..zSymlink loop from %r)	rx   r6   
rpartitionendswithr   readlinkOSErrorr   r   )rs   r   r   _newpathtargete_resolveZaccessorseenr+   rt   r!   r"   r   A  s4    




z'_PosixFlavour.resolve.<locals>._resolver0   )r+   	_accessoris_absolutero   rp   rn   )r.   rs   rt   baser!   r   r"   rv   =  s    )z_PosixFlavour.resolvec                 C   s   dS NFr!   rc   r!   r!   r"   r}   m  s    z_PosixFlavour.is_reservedc                 C   s   t |}dt| S )Nzfile://)bytesr   )r.   rs   Zbpathr!   r!   r"   r   p  s    z_PosixFlavour.make_uric                 C   s|   |s@zt jd W S  tk
r<   dd l}|t  j Y S X n8dd l}z||jW S  tk
rv   td| Y nX d S )NHOMEr   r   )	ro   r   r   pwdgetpwuidgetuidpw_dirgetpwnamr   )r.   r   r   r!   r!   r"   r   v  s    z_PosixFlavour.gethomedirN)F)rE   rF   rG   r+   r2   r   	posixpathr   ro   r   r   r5   rC   rd   rm   rv   r}   r   r   r!   r!   r!   r"   r     s   

0r   c                   @   s   e Zd ZdZdS )	_AccessorzjAn accessor implements a particular (system-specific or not) way of
    accessing paths on the filesystem.N)rE   rF   rG   rH   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S )_NormalAccessorlchmodc                 C   s   t dd S )Nz%lchmod() not available on this systemNotImplementedError)r.   Zpathobjmoder!   r!   r"   r     s    z_NormalAccessor.lchmodlinkc                 C   s   t dd S )Nz&os.link() not available on this systemr   r.   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*   )ro   r   r   r!   r!   r"   r     s    c                 C   s
   t |S r*   )ro   r   r.   rs   r!   r!   r"   r     s    z_NormalAccessor.readlinkN)rE   rF   rG   ro   statlstatopenlistdirscandirchmodhasattrr   mkdirunlinkr   r   staticmethodrmdirrenamer4   r   supports_symlinksr   utimer   r!   r!   r!   r"   r     s4   




r   c                 C   sR   | d }| dd  }|dkr"t }n$d|kr4tdnt|rBt}nt}||||S )Nr   rB   **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Zdd Zdd ZdS )	_SelectorzYA selector matches a specific glob pattern part against the children
    of a given path.c                 C   s0   || _ |rt||| _d| _nt | _d| _d S )NTF)r   r   	successordironly_TerminatingSelector)r.   r   r   r!   r!   r"   r/     s    z_Selector.__init__c                 C   s<   t |}|j}|j}|jj}||s,tg S | ||||S )zuIterate over all child paths of `parent_path` matched by this
        selector.  This can contain parent_path itself.)typeis_direxistsr   r   iter_select_from)r.   parent_pathZpath_clsr   r   r   r!   r!   r"   select_from  s    z_Selector.select_fromN)rE   rF   rG   rH   r/   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!   )r.   r   r   r   r   r!   r!   r"   r     s    z!_TerminatingSelector._select_fromN)rE   rF   rG   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   r/   )r.   r   r   r   r!   r!   r"   r/      s    z_PreciseSelector.__init__c                 c   s\   z@| | j}| jr|n||r>| j||||D ]
}|V  q2W n tk
rV   Y d S X d S r*   )_make_child_relpathr   r   r   r   PermissionError)r.   r   r   r   r   rs   ra   r!   r!   r"   r     s    z_PreciseSelector._select_fromNrE   rF   rG   r/   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*   )rm   matchr   r/   r.   r'   r   r   r!   r!   r"   r/     s    z_WildcardSelector.__init__c                 c   s   z||}t |}W 5 Q R X |D ]}| jrrz| s:W q"W n4 tk
rp } zt|sX W Y q"W 5 d }~X Y nX |j}	| |	r"||	}
| j	|
|||D ]
}|V  qq"W n t
k
r   Y d S X d S r*   )listr   r   r   r#   r   r   r   r   r   r   )r.   r   r   r   r   
scandir_itentriesentryr   r   rs   ra   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   r/   r   r!   r!   r"   r/   /  s    z#_RecursiveWildcardSelector.__init__c                 c   s   |V  z||}t |}W 5 Q R X |D ]t}d}z| }W n, tk
rh } zt|sX W 5 d }~X Y nX |r(| s(||j}	| |	||D ]
}
|
V  qq(W n tk
r   Y d S X d S r   )	r   r   r   r#   
is_symlinkr   r   _iterate_directoriesr   )r.   r   r   r   r   r   r   Zentry_is_dirr   rs   ra   r!   r!   r"   r   2  s"    
z/_RecursiveWildcardSelector._iterate_directoriesc           	      c   s~   zbt  }zL| jj}| |||D ]0}|||||D ]}||kr2|V  || q2q W 5 |  X W n tk
rx   Y d S X d S r*   )r   clearr   r   r   addr   )	r.   r   r   r   r   ZyieldedZsuccessor_selectZstarting_pointra   r!   r!   r"   r   E  s    z'_RecursiveWildcardSelector._select_fromN)rE   rF   rG   r/   r   r   r!   r!   r!   r"   r   -  s   r   c                   @   s4   e Zd ZdZdZdd Zdd Zdd Zd	d
 ZdS )_PathParentszvThis object provides sequence-like access to the logical ancestors
    of a path.  Don't try to construct it yourself.)_pathcls_drv_root_partsc                 C   s&   t || _|j| _|j| _|j| _d S r*   )r   r   r   r   r   r   r!   r!   r"   r/   ^  s    
z_PathParents.__init__c                 C   s(   | j s| jrt| jd S t| jS d S ry   )r   r   rV   r   r-   r!   r!   r"   __len__e  s    z_PathParents.__len__c                 C   s@   |dk s|t | krt|| j| j| j| jd | d  S )Nr   rB   )rV   
IndexErrorr   _from_parsed_partsr   r   r   )r.   idxr!   r!   r"   __getitem__k  s
    z_PathParents.__getitem__c                 C   s   d | jjS )Nz<{}.parents>)formatr   rE   r-   r!   r!   r"   __repr__q  s    z_PathParents.__repr__N)	rE   rF   rG   rH   	__slots__r/   r   r   r   r!   r!   r!   r"   r   Y  s   r   c                   @   s  e Zd ZdZdZdd Zdd Zedd ZedVd
dZ	edWd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eed.d/d0Zeed1d2d0Zed3d4 Zed5d6 Z ed7d8 Z!ed9d: Z"ed;d< Z#d=d> Z$d?d@ Z%dAdB Z&edCdD Z'dEdF Z(dGdH Z)dIdJ Z*edKdL Z+edMdN Z,dOdP Z-dQdR Z.dSdT Z/dUS )Xr   a|  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_cpartsc                 G   s$   | t krtjdkrtnt} | |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   )r   ro   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   ro   fspathrn   r7   	TypeErrorr   _flavourrA   )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   initr.   r<   r=   r;   r!   r!   r"   r     s    
zPurePath._from_partsc                 C   s,   t | }||_||_||_|r(|  |S r*   )r  r   r   r   r   r  )r   r<   r=   r;   r	  r.   r!   r!   r"   r     s    
zPurePath._from_parsed_partsc                 C   s4   |s|r$|| | j |dd   S | j |S d S ry   )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"   r    s    zPurePath._initc                 C   s@   |  |\}}}| j| j| j| j|||\}}}| |||S r*   )r  r  rD   r   r   r   r   )r.   r   r<   r=   r;   r!   r!   r"   _make_child  s         
zPurePath._make_childc                 C   sB   z| j W S  tk
r<   | | j| j| jp.d| _ | j  Y S X dS )z[Return the string representation of the path, suitable for
        passing to system calls.r1   N)r   AttributeErrorr
  r   r   r   r-   r!   r!   r"   __str__  s    zPurePath.__str__c                 C   s   t | S r*   )rn   r-   r!   r!   r"   
__fspath__  s    zPurePath.__fspath__c                 C   s   | j }t| |jdS )zNReturn the string representation of the path with forward (/)
        slashes.rK   )r  rn   r4   r+   r.   fr!   r!   r"   r     s    zPurePath.as_posixc                 C   s
   t | S )zaReturn the bytes representation of the path.  This is only
        recommended to use under Unix.)ro   fsencoder-   r!   r!   r"   	__bytes__  s    zPurePath.__bytes__c                 C   s   d | jj|  S )Nz{}({!r}))r   r   rE   r   r-   r!   r!   r"   r     s    zPurePath.__repr__c                 C   s   |   std| j| S )z Return the path as a 'file' URI.z.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   s8   z| j W S  tk
r2   | j| j| _ | j  Y S X d S r*   )r   r  r  rd   r   r-   r!   r!   r"   _cparts  s
    zPurePath._cpartsc                 C   s&   t |tstS | j|jko$| j|jkS r*   )r  r   NotImplementedr  r  r.   otherr!   r!   r"   __eq__  s    
zPurePath.__eq__c                 C   s8   z| j W S  tk
r2   tt| j| _ | j  Y S X d S r*   )r   r  hashr   r  r-   r!   r!   r"   __hash__  s
    zPurePath.__hash__c                 C   s&   t |tr| j|jk	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k	rtS | j|jkS r*   r  r  r!   r!   r"   __le__	  s    zPurePath.__le__c                 C   s&   t |tr| j|jk	rtS | j|jkS r*   r  r  r!   r!   r"   __gt__  s    zPurePath.__gt__c                 C   s&   t |tr| j|jk	rtS | j|jkS r*   r  r  r!   r!   r"   __ge__  s    zPurePath.__ge__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 )z/The concatenation of the drive and root, or ''.)r   r   )r.   anchorr!   r!   r"   r!    s    zPurePath.anchorc                 C   s.   | j }t|| js| jrdndkr&dS |d S )z!The final path component, if any.rB   r   r0   rR   )r   rV   r   r   rc   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 )z{
        The final component's last suffix, if any.

        This includes the leading period. For example: '.txt'
        r1   r   rB   Nr0   r   rfindrV   r.   r   rN   r!   r!   r"   suffix,  s
    
 zPurePath.suffixc                 C   s:   | j }|drg S |d}dd |ddd D S )z
        A list of the final component's suffixes, if any.

        These include the leading periods. For example: ['.tar', '.gz']
        r1   c                 S   s   g | ]}d | qS )r1   r!   )rM   r%  r!   r!   r"   rb   E  s     z%PurePath.suffixes.<locals>.<listcomp>rB   N)r   r   rX   r6   r.   r   r!   r!   r"   suffixes:  s
    

zPurePath.suffixesc                 C   sD   | j }|d}d|  k r,t|d k r<n n|d| S |S dS )z0The final path component, minus its last suffix.r1   r   rB   Nr"  r$  r!   r!   r"   stemG  s
    
 zPurePath.stemc                 C   s   | j std| f | j|f\}}}|rX|d | jj| jjfksX|sX|sXt|dkrdtd| | | j| j	| j
dd |g S )z-Return a new path with the file name changed.%r has an empty namerR   rB   zInvalid name %rN)r   r   r  rA   r+   r2   rV   r   r   r   r   )r.   r   r<   r=   r;   r!   r!   r"   	with_nameQ  s    
zPurePath.with_namec                 C   s   | j }|j|ks |jr.|j|k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 )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.
        zInvalid suffix %rr1   r)  NrR   )r  r+   r2   r   rx   r   r%  rV   r   r   r   r   )r.   r%  r  r   Z
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 )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.
        zneed at least one argumentrB   Nr   z{!r} does not start with {!r}r0   )r  r   r   r   r  rV   r  rd   r
  r   r   rn   r   )r.   r  r;   r<   r=   Z	abs_partsZto_drvZto_rootZto_partsZto_abs_partsncfZ	formattedr!   r!   r"   relative_toq  s.    	* 
zPurePath.relative_toc                 C   s4   z| j W S  tk
r.   t| j| _ | j  Y S X dS )zZAn object providing sequence-like access to the
        components in the filesystem path.N)r   r  r   r   r-   r!   r!   r"   r;     s
    zPurePath.partsc                 G   s
   |  |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.   r   r!   r!   r"   joinpath  s    zPurePath.joinpathc                 C   s,   z|  |fW S  tk
r&   t Y S X d S r*   )r  r  r  r.   keyr!   r!   r"   __truediv__  s    zPurePath.__truediv__c                 C   s2   z|  |g| j W S  tk
r,   t Y S X d S r*   )r   r   r  r  r0  r!   r!   r"   __rtruediv__  s    zPurePath.__rtruediv__c                 C   s@   | j }| j}| j}t|dkr*|s&|r*| S | |||dd S )zThe logical parent of the path.rB   NrR   )r   r   r   rV   r   )r.   r<   r=   r;   r!   r!   r"   parent  s    zPurePath.parentc                 C   s   t | S )z*A sequence of this path's logical parents.)r   r-   r!   r!   r"   parents  s    zPurePath.parentsc                 C   s   | j s
dS | jj pt| jS )zSTrue if the path is absolute (has both a root and, if applicable,
        a drive).F)r   r  r   boolr   r-   r!   r!   r"   r     s    zPurePath.is_absolutec                 C   s   | j | jS )zaReturn True if the path contains one of the special names reserved
        by the system, if any.)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 )zE
        Return True if this path matches the given pattern.
        zempty patternFrB   NT)r  rC   rA   r   r   r   r  rV   zipr3   rg   Zfnmatchcase)	r.   Zpath_patternr-  r<   r=   Z	pat_partsr;   r?   r'   r!   r!   r"   r     s(    zPurePath.matchN)T)T)0rE   rF   rG   rH   r   r   r  classmethodr  r   r   r
  r  r  r  r  r   r  r   r  propertyr  r  r  r  r  r  r  r   r~   r=   r!  r   r%  r'  r(  r*  r+  r.  r;   r/  r2  r3  r4  r5  r   r}   r   r!   r!   r!   r"   r   u  sv   

	







	 

	
c                   @   s   e Zd ZdZeZdZdS )r   zPurePath 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.
    r!   N)rE   rF   rG   rH   _posix_flavourr  r   r!   r!   r!   r"   r     s   c                   @   s   e Zd ZdZeZdZdS )r   zPurePath 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.
    r!   N)rE   rF   rG   rH   _windows_flavourr  r   r!   r!   r!   r"   r     s   c                   @   s  e Zd ZdZdZdd ZddddZdd	 Zd
d Zdd Z	dd Z
deddZdfd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dgd%d&Zd'd( Zd)d* Zd+d, Zdhd/d0Zd1d2 Zdid3d4Zd5d6 Zdjd7d8Zdkd:d;Zdld<d=Zd>d? Z d@dA Z!dmdBdCZ"dDdE Z#dFdG Z$dHdI Z%dJdK Z&dndLdMZ'dNdO Z(dPdQ Z)dRdS Z*dTdU Z+dVdW Z,dXdY Z-dZd[ Z.d\d] Z/d^d_ Z0d`da Z1dbdc Z2dS )or   a  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   _closedc                 O   sL   | t krtjdkrtnt} | j|dd}|jjs@td| j	f |
  |S )Nr   Fr	  z$cannot instantiate %r on your system)r   ro   r   r   r   r   r  r   r   rE   r  )r   r   kwargsr.   r!   r!   r"   r     s    zPath.__new__Nc                 C   s"   d| _ |d k	r|j| _nt| _d S r   )r<  r   _normal_accessor)r.   templater!   r!   r"   r    s    
z
Path._initc                 C   s   | j |g }| | j| j|S r*   )r   r   r   r   )r.   r?   r;   r!   r!   r"   r   #  s    zPath._make_child_relpathc                 C   s   | j r|   | S r*   )r<  _raise_closedr-   r!   r!   r"   	__enter__)  s    zPath.__enter__c                 C   s
   d| _ d S )NT)r<  )r.   tvtbr!   r!   r"   __exit__.  s    zPath.__exit__c                 C   s   t dd S )NzI/O operation on closed path)r   r-   r!   r!   r"   rA  1  s    zPath._raise_closed  c                 C   s   | j | ||S r*   )r   r   )r.   r   flagsr   r!   r!   r"   _opener4  s    zPath._opener  c                 C   s   | j r|   | j| ||S )zm
        Open the file pointed by this path and return a file descriptor,
        as os.open() does.
        )r<  rA  r   r   )r.   rH  r   r!   r!   r"   	_raw_open8  s    zPath._raw_openc                 C   s   | t  S )zjReturn a new path pointing to the current working directory
        (as returned by os.getcwd()).
        )ro   rp   r   r!   r!   r"   cwdC  s    zPath.cwdc                 C   s   | |  j dS )zrReturn a new path pointing to the user's home directory (as
        returned by os.path.expanduser('~')).
        N)r  r   rL  r!   r!   r"   homeJ  s    z	Path.homec                 C   sB   |   }z|  }W n tk
r2   t |}Y nX tj||S )zoReturn whether other_path is the same or not as this file
        (as returned by os.path.samefile()).
        )r   r  ro   rs   samestat)r.   Z
other_pathstZother_str!   r!   r"   samefileQ  s    zPath.samefilec                 c   sH   | j r|   | j| D ](}|dkr(q| |V  | j r|   qdS )zyIterate over the files in this directory.  Does not yield any
        result for the special paths '.' and '..'.
        >   r1   r   N)r<  rA  r   r   r   r&  r!   r!   r"   iterdir\  s    zPath.iterdirc                 c   s`   |st d|| j|f\}}}|s.|r6tdtt|| j}|| D ]
}|V  qPdS )zIterate over this subtree and yield all existing files (of any
        kind, including directories) matching the given relative pattern.
        zUnacceptable pattern: {!r}%Non-relative patterns are unsupportedN)r   r   r  rA   r   r   r   r   r.   rl   r<   r=   r   Zselectorra   r!   r!   r"   globj  s    z	Path.globc                 c   sR   | j |f\}}}|s|r$tdtdt| | j }|| D ]
}|V  qBdS )zRecursively yield all existing files (of any kind, including
        directories) matching the given relative pattern, anywhere in
        this subtree.
        rS  )r   N)r  rA   r   r   r   r   rT  r!   r!   r"   rglobw  s    z
Path.rglobc                 C   sD   | j r|   |  r| S | jt g| j dd}|j| d |S )a  Return 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.
        Fr=  r@  )r<  rA  r   r   ro   rp   r   r  )r.   objr!   r!   r"   absolute  s    zPath.absoluteFc                 C   sh   | j r|   | jj| |d}|dkr:|   t|  }| jj|}| j	|fdd}|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).
        )rt   NFr=  rW  )r<  rA  r  rv   r   rn   rY  r   normpathr   r  )r.   rt   r`   ZnormedrX  r!   r!   r"   rv     s    zPath.resolvec                 C   s   | j | S )zh
        Return the result of the stat() system call on this path, like
        os.stat() does.
        )r   r   r-   r!   r!   r"   r     s    z	Path.statc                 C   s   ddl }||  jjS )z:
        Return the login name of the file owner.
        r   N)r   r   r   st_uidZpw_name)r.   r   r!   r!   r"   owner  s    z
Path.ownerc                 C   s   ddl }||  jjS )z8
        Return the group name of the file gid.
        r   N)grpZgetgrgidr   st_gidZgr_name)r.   r]  r!   r!   r"   group  s    z
Path.grouprrR   c              	   C   s(   | j r|   tj| |||||| jdS )z|
        Open the file pointed by this path and return a file object, as
        the built-in open() function does.
        )Zopener)r<  rA  ior   rI  )r.   r   	bufferingencodingerrorsnewliner!   r!   r"   r     s
    z	Path.openc              
   C   s,   | j dd}| W  5 Q R  S Q R X dS )zK
        Open the file in bytes mode, read it, and close the file.
        rbr   Nr   readr  r!   r!   r"   
read_bytes  s    zPath.read_bytesc              
   C   s0   | j d||d}| W  5 Q R  S Q R X dS )zJ
        Open the file in text mode, read it, and close the file.
        r`  r   rc  rd  Nrh  )r.   rc  rd  r  r!   r!   r"   	read_text  s    zPath.read_textc              
   C   s6   t |}| jdd}||W  5 Q R  S Q R X dS )zO
        Open the file in bytes mode, write to it, and close the file.
        wbrg  N)
memoryviewr   write)r.   dataZviewr  r!   r!   r"   write_bytes  s    zPath.write_bytesc              
   C   sL   t |tstd|jj | jd||d}||W  5 Q R  S Q R X dS )zN
        Open the file in text mode, write to it, and close the file.
        zdata must be str, not %swrk  N)r  rn   r  r   rE   r   ro  )r.   rp  rc  rd  r  r!   r!   r"   
write_text  s    
zPath.write_textTc                 C   sr   | j r|   |r>z| j| d W n tk
r8   Y nX dS tjtjB }|sX|tjO }| 	||}t
| dS )zS
        Create this file with the given access mode, if it doesn't exist.
        N)r<  rA  r   r   r   ro   O_CREATO_WRONLYO_EXCLrK  close)r.   r   exist_okrH  fdr!   r!   r"   touch  s    
z
Path.touchc                 C   s   | j r|   z| j| | W nd tk
rd   |r>| j| kr@ | jjddd | j|d|d Y n" tk
r   |r~|  s Y nX dS )z<
        Create a new directory at this given path.
        T)r5  rx  FN)r<  rA  r   r   rr   r4  r   r   )r.   r   r5  rx  r!   r!   r"   r     s    z
Path.mkdirc                 C   s    | j r|   | j| | dS )zF
        Change the permissions of the path, like os.chmod().
        N)r<  rA  r   r   r.   r   r!   r!   r"   r     s    z
Path.chmodc                 C   s    | j r|   | j| | dS )z
        Like chmod(), except if the path points to a symlink, the symlink's
        permissions are changed, rather than its target's.
        N)r<  rA  r   r   r{  r!   r!   r"   r     s    zPath.lchmodc                 C   s>   | j r|   z| j|  W n tk
r8   |s4 Y nX dS )zd
        Remove this file or link.
        If the path is a directory, use rmdir() instead.
        N)r<  rA  r   r   rr   )r.   Z
missing_okr!   r!   r"   r   %  s    zPath.unlinkc                 C   s   | j r|   | j|  dS )zF
        Remove this directory.  The directory must be empty.
        N)r<  rA  r   r   r-   r!   r!   r"   r   2  s    z
Path.rmdirc                 C   s   | j r|   | j| 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<  rA  r   r   r-   r!   r!   r"   r   :  s    z
Path.lstatc                 C   s&   | j r|   | 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.
        )r<  rA  r   r   r   r   r!   r!   r"   r   C  s    
zPath.renamec                 C   s&   | j r|   | j| | | |S )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.
        )r<  rA  r   r4   r   r   r!   r!   r"   r4   R  s    
zPath.replacec                 C   s"   | j r|   | j|| | dS )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)r<  rA  r   r   )r.   r   r   r!   r!   r"   
symlink_toa  s    zPath.symlink_toc                 C   s    | j r|   | j| | dS )aQ  
        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.

        N)r<  rA  r   r   r   r!   r!   r"   r   j  s    
zPath.link_toc              
   C   sX   z|    W nF tk
r> } zt|s( W Y dS d}~X Y n tk
rR   Y dS X dS )z+
        Whether this path exists.
        FNT)r   r   r#   r   r.   r   r!   r!   r"   r   z  s    zPath.existsc              
   C   s\   zt |  jW S  tk
rB } zt|s, W Y dS d}~X Y n tk
rV   Y dS X dS )z3
        Whether this path is a directory.
        FN)r	   r   st_moder   r#   r   r}  r!   r!   r"   r     s    zPath.is_dirc              
   C   s\   zt |  jW S  tk
rB } zt|s, W Y dS d}~X Y n tk
rV   Y dS X dS )zq
        Whether this path is a regular file (also True for symlinks pointing
        to regular files).
        FN)r   r   r~  r   r#   r   r}  r!   r!   r"   is_file  s    zPath.is_filec                 C   sv   |   r|  sdS t| j}z| j}W n tk
rB   Y dS X |  j}||krZdS |  j}| j}||kS )z;
        Check if this path is a POSIX mount point
        FT)r   r   r   r4  r   st_devr   st_ino)r.   r4  Z
parent_devZdevZinoZ
parent_inor!   r!   r"   is_mount  s    



zPath.is_mountc              
   C   s\   zt |  jW S  tk
rB } zt|s, W Y dS d}~X Y n tk
rV   Y dS X dS )z7
        Whether this path is a symbolic link.
        FN)r
   r   r~  r   r#   r   r}  r!   r!   r"   r     s    zPath.is_symlinkc              
   C   s\   zt |  jW S  tk
rB } zt|s, W Y dS d}~X Y n tk
rV   Y dS X dS )z6
        Whether this path is a block device.
        FN)r   r   r~  r   r#   r   r}  r!   r!   r"   is_block_device  s    zPath.is_block_devicec              
   C   s\   zt |  jW S  tk
rB } zt|s, W Y dS d}~X Y n tk
rV   Y dS X dS )z:
        Whether this path is a character device.
        FN)r   r   r~  r   r#   r   r}  r!   r!   r"   is_char_device  s    zPath.is_char_devicec              
   C   s\   zt |  jW S  tk
rB } zt|s, W Y dS d}~X Y n tk
rV   Y dS X dS )z.
        Whether this path is a FIFO.
        FN)r   r   r~  r   r#   r   r}  r!   r!   r"   is_fifo  s    zPath.is_fifoc              
   C   s\   zt |  jW S  tk
rB } zt|s, W Y dS d}~X Y n tk
rV   Y dS X dS )z0
        Whether this path is a socket.
        FN)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 )zl Return a new path with expanded ~ and ~user constructs
        (as returned by os.path.expanduser)
        r   NrB   ~)r   r   r   r  r   r   )r.   Zhomedirr!   r!   r"   
expanduser  s    zPath.expanduser)N)rG  )rJ  )F)r`  rR   NNN)NN)NN)rG  T)rJ  FF)F)F)3rE   rF   rG   rH   r   r   r  r   rB  rF  rA  rI  rK  r8  rM  rN  rQ  rR  rU  rV  rY  rv   r   r\  r_  r   rj  rl  rq  rs  rz  r   r   r   r   r   r   r   r4   r|  r   r   r   r  r  r   r  r  r  r  r  r!   r!   r!   r"   r     sj    






    

	



	
	
	c                   @   s   e Zd ZdZdZdS )r   zsPath subclass for non-Windows systems.

    On a POSIX system, instantiating a Path should return this object.
    r!   N)rE   rF   rG   rH   r   r!   r!   r!   r"   r     s   c                   @   s,   e Zd ZdZdZdd Zdd Zdd Zd	S )
r   zqPath subclass for Windows systems.

    On a Windows system, instantiating a Path should return this object.
    r!   c                 C   s   t dd S )Nz*Path.owner() is unsupported on this systemr   r-   r!   r!   r"   r\  (  s    zWindowsPath.ownerc                 C   s   t dd S )Nz*Path.group() is unsupported on this systemr   r-   r!   r!   r"   r_  +  s    zWindowsPath.groupc                 C   s   t dd S )Nz-Path.is_mount() is unsupported on this systemr   r-   r!   r!   r"   r  .  s    zWindowsPath.is_mountN)rE   rF   rG   rH   r   r\  r_  r  r!   r!   r!   r"   r   !  s
   )Arg   	functoolsra  r   ro   r   re   r8   _collections_abcr   r   r   r   r   r   r   operatorr   r   r	   r
   r   r   r   r   r   Zurllib.parser   r   r   r   r   Zgetwindowsversionr   __all__r   r    r#   r(   r  r)   rI   r   r;  r:  r   r   r?  r   r   r   r   r   r   r   r   r   r   PathLikeregisterr   r   r   r   r   r!   r!   r!   r"   <module>   s|   $
    
? &i8,  t
    