U
    g"                     @  s  d dl mZ d dlZd dlZd dlZd dl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mZ d dlmZ d dlmZ erd d	lmZmZmZ d d
lmZmZm Z m!Z!m"Z" d dl#m$Z$m%Z%m&Z&m'Z'm(Z( d dl)m*Z*m+Z+m,Z,m-Z- e,dZ.edddZ/edZ0dddddZ1dddddZ2dddddZ3d d!dd"d#Z4G d$d dej5Z6eG d%d& d&e6ej7Z8eG d'd( d(e6ej9Z:dS ))    )annotationsN)partialupdate_wrapper)cleandoc)IOTYPE_CHECKINGAnyBinaryIOClassVarTypeVaroverload)AsyncIOWrapper	wrap_file)final)run_sync)	AwaitableCallableIterable)BufferedRandomBufferedReaderBufferedWriterFileIOTextIOWrapper)OpenBinaryModeOpenBinaryModeReadingOpenBinaryModeUpdatingOpenBinaryModeWritingOpenTextMode)ConcatenateLiteral	ParamSpecSelfPPathTPath)boundTzCallable[..., Any]z5Callable[[Callable[P, T]], Callable[P, Awaitable[T]]])wrappedreturnc                   s   ddd fdd}|S )NzCallable[P, T]zCallable[P, Awaitable[T]]fnr(   c                   sN   dddd fdd}t | jrJdj dj d	tj d
|_|S )NP.argsP.kwargsr&   argskwargsr(   c                    s   t t f| |I d H S N)r   r   )r.   r/   r*    ./tmp/pip-unpacked-wheel-ks04xdmi/trio/_path.pywrapper%   s    z0_wraps_async.<locals>.decorator.<locals>.wrapperzLike :meth:`~.z`, but async.


)r   __doc__
__module____qualname__r   r*   r4   r'   r1   r3   	decorator$   s    
 z_wraps_async.<locals>.decoratorr2   )r'   r<   r2   r;   r3   _wraps_async!   s    r=   z)Callable[Concatenate[pathlib.Path, P], T]z,Callable[Concatenate[Path, P], Awaitable[T]]r)   c                   s$   t  ddddd fdd}|S )Nr$   r+   r,   r&   selfr.   r/   r(   c                  s    |  | f||S r0   )_wrapped_clsr?   r.   r/   r1   r2   r3   r4   7   s    z_wrap_method.<locals>.wrapperr=   r:   r2   r1   r3   _wrap_method4   s    rC   z4Callable[Concatenate[pathlib.Path, P], pathlib.Path]z1Callable[Concatenate[PathT, P], Awaitable[PathT]]c                   s$   t  ddddd fdd}|S )Nr#   r+   r,   r>   c                  s   |   | | f||S r0   )	__class__r@   rA   r1   r2   r3   r4   A   s    z"_wrap_method_path.<locals>.wrapperrB   r:   r2   r1   r3   _wrap_method_path>   s    rE   z>Callable[Concatenate[pathlib.Path, P], Iterable[pathlib.Path]]z;Callable[Concatenate[PathT, P], Awaitable[Iterable[PathT]]]c                   sB   t  ddddd fdd}|jr>| jd j d	7  _|S )
Nr#   r+   r,   zIterable[PathT]r>   c                  s    t | j | | f||S r0   )maprD   r@   rA   r1   r2   r3   r4   K   s    z+_wrap_method_path_iterable.<locals>.wrapperz
This is an async method that returns a synchronous iterator, so you
use it like:

.. code:: python

    for subpath in await mypath.z():
        ...

.. note::

    The iterator is loaded into memory immediately during the initial
    call (see `issue #501
    <https://github.com/python-trio/trio/issues/501>`__ for discussion).
)r=   r7   __name__r:   r2   r1   r3   _wrap_method_path_iterableH   s    rH   c                	      s  e Zd ZU dZdZded< ddd fdd	Zeee	j
jdd
ddZeee	j
jdd
ddZed7dddddddddZed8dddddddddZed9dddddd dd!dZed:d"ddddd#dd$dZed;d%ddddd&dd'dZed<dddddd(dd)dZed=d*ddddd+dd,dZee	j
jd-d-d+d.d/dZd*d
d0d1Zee	j
jZee	j
jZee	j
jZee	j
jZee	j
jZee	j
jZee	j
jZee	j
jZee	j
jZee	j
jZee	j
jZee	j
jZejd2kree	j
j Z ee	j
j!Z!ee	j
j"Z"ee	j
j#Z#ee	j
j$Z$ej%d3krdee	j
j&Z&ee	j
j'Z'ej%d3ks|ejd2kree	j
j(Z(ejd4kre)e	j
j*Z*e)e	j
j+Z+e)e	j
j,Z,e)e	j
j-Z-ee	j
j.Z.ee	j
j/Z/ejd5kree	j
j0Z0ee	j
j1Z1ee	j
j2Z2e)e	j
j3Z3e)e	j
j4Z4ee	j
j5Z5ee	j
j6Z6ee	j
j7Z7ee	j
j8Z8ee	j
j9Z9ejd2k rxee	j
j:Z:ejd6kree	j
j;Z;  Z<S )>r$   zAn async :class:`pathlib.Path` that executes blocking methods in :meth:`trio.to_thread.run_sync`.

    Instantiating :class:`Path` returns a concrete platform-specific subclass, one of :class:`PosixPath` or
    :class:`WindowsPath`.
    r2   ClassVar[type[pathlib.Path]]r@   zstr | os.PathLike[str]r!   )r.   r(   c                   s,   | t krtjdkrtnt} t j| f| S )Nnt)r$   osnameWindowsPath	PosixPathsuper__new__)clsr.   rD   r2   r3   rP   n   s    zPath.__new__)r(   c                 C  s   | t j S r0   )pathlibr$   cwdrQ   r2   r2   r3   rT   s   s    zPath.cwdc                 C  s   | t j S r0   )rS   r$   homerU   r2   r2   r3   rV   x   s    z	Path.homerNr   intz
str | NonezAsyncIOWrapper[TextIOWrapper])mode	bufferingencodingerrorsnewliner(   c                   s   d S r0   r2   r?   rZ   r[   r\   r]   r^   r2   r2   r3   open}   s    z	Path.openr   z
Literal[0]NonezAsyncIOWrapper[FileIO]c                   s   d S r0   r2   r_   r2   r2   r3   r`      s    r   zLiteral[(-1, 1)]zAsyncIOWrapper[BufferedRandom]c                   s   d S r0   r2   r_   r2   r2   r3   r`      s    r   zAsyncIOWrapper[BufferedWriter]c                   s   d S r0   r2   r_   r2   r2   r3   r`      s    r   zAsyncIOWrapper[BufferedReader]c                   s   d S r0   r2   r_   r2   r2   r3   r`      s    zAsyncIOWrapper[BinaryIO]c                   s   d S r0   r2   r_   r2   r2   r3   r`      s    strzAsyncIOWrapper[IO[Any]]c                   s   d S r0   r2   r_   r2   r2   r3   r`      s    r   r-   c                 O  s   t | | j||S r0   )r   r@   r`   rA   r2   r2   r3   r`      s    c                 C  s   dt | dS )Nz
trio.Path())rb   )r?   r2   r2   r3   __repr__   s    zPath.__repr__)      win32)re   	   )re   
   )re      )rW   rX   NNN)NNN)rX   NNN)rX   NNN)rX   NNN)rX   NNN)rX   NNN)=rG   r8   r9   r7   	__slots____annotations__rP   classmethodr=   rS   r$   rT   rV   r   r`   rd   rC   statchmodexistsrH   globrglobis_diris_file
is_symlink	is_socketis_fifois_block_deviceis_char_devicesysversion_infoZis_junctioniterdirlchmodlstatmkdirplatformownergroupis_mountrE   readlinkrenamereplaceresolvermdir
symlink_toZhardlink_totouchunlinkabsolute
expanduser
read_bytes	read_textsamefilewrite_bytes
write_textlink_toZ
full_match__classcell__r2   r2   rR   r3   r$   c   s   


     	   	    	    	    	    	    	
c                   @  s$   e Zd ZU dZdZejZded< dS )rN   zfAn async :class:`pathlib.PosixPath` that executes blocking methods in :meth:`trio.to_thread.run_sync`.r2   rI   r@   N)	rG   r8   r9   r7   rk   rS   rN   r@   rl   r2   r2   r2   r3   rN      s   
rN   c                   @  s$   e Zd ZU dZdZejZded< dS )rM   zhAn async :class:`pathlib.WindowsPath` that executes blocking methods in :meth:`trio.to_thread.run_sync`.r2   rI   r@   N)	rG   r8   r9   r7   rk   rS   rM   r@   rl   r2   r2   r2   r3   rM     s   
rM   );
__future__r   rK   rS   rz   	functoolsr   r   inspectr   typingr   r   r   r	   r
   r   r   Ztrio._file_ior   r   Z
trio._utilr   Ztrio.to_threadr   collections.abcr   r   r   ior   r   r   r   r   Z	_typeshedr   r   r   r   r   Ztyping_extensionsr   r   r    r!   r"   r#   r&   r=   rC   rE   rH   PurePathr$   PurePosixPathrN   PureWindowsPathrM   r2   r2   r2   r3   <module>   s6   $

 