o
    ACekC                     @  s  U d dl m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m	Z	m
Z
mZ d dl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mZmZmZmZ d dlZd dlm Z! d dl"m#Z#m$Z$m%Z% erd d	l&m'Z'm(Z(m)Z)m*Z*m+Z+ d d
l,m-Z-m.Z.m/Z/m0Z0 e/dZ1edZ2ee3df Z4de5d< d3ddZ6d4ddZ7d5d d!Z8d6d$d%Z9d7d'd(Z:d8d*d+Z;G d,d de<Z=e$G d-d. d.e=d/Z>d0e>j?_@ejAd1k rd2e>jB_@e>jC`@ejDEe> dS )9    )annotationsN)	AwaitableCallableIterableSequence)partial)BufferedRandomBufferedReaderBufferedWriterFileIOTextIOWrapper)	IOTYPE_CHECKINGAnyBinaryIOClassVarTypeVarUnioncastoverload)AsyncIOWrapper)async_wrapsfinalwraps)OpenBinaryModeOpenBinaryModeReadingOpenBinaryModeUpdatingOpenBinaryModeWritingOpenTextMode)ConcatenateLiteral	ParamSpec	TypeAliasPTzos.PathLike[str]r"   StrPathvaluereturnT | Pathc                 C  s   t | tjr
t| S | S N)
isinstancepathlibPath)r&    r-   .usr/lib/python3.10/site-packages/trio/_path.pyrewrap_path,   s   r/   clsAsyncAutoWrapperType	attr_namestrattr)Callable[Concatenate[pathlib.Path, P], T](Callable[Concatenate[Path, P], T | Path]c                   s6   t |d fd	d
}t|tjsJ t||_|S )Nselfr,   argsP.argskwargsP.kwargsr'   r(   c                   s"   t | j }||i |}t|S r)   )getattr_wrappedr/   )r7   r8   r:   r4   r&   r2   r-   r.   wrapper8   s   z!_forward_factory.<locals>.wrapper)r7   r,   r8   r9   r:   r;   r'   r(   )r   r*   typesFunctionTypeinspect	signature__signature__)r0   r2   r4   r?   r-   r>   r.   _forward_factory3   s
   rE   Callable[..., T]Callable[..., Path | T]c                   sD   t  t fd	 fdd}t|tjsJ t |_|S )
Nr7   r,   otherobjectr'   Path | Tc                   s<   |u r	 | j S t|rtt|j } | j |}t|S r)   )r=   r*   r   r,   r/   )r7   rH   r&   r4   r0   sentinelr-   r.   r?   K   s   

z_forward_magic.<locals>.wrapper)r7   r,   rH   rI   r'   rJ   )rI   r   r*   r@   rA   rB   rC   rD   )r0   r4   r?   r-   rK   r.   _forward_magicF   s   rM   	meth_name9Callable[Concatenate[Path, P], Awaitable[Iterable[Path]]]c                   s    t | | j d fd	d
}|S )Nr7   r,   r8   r9   r:   r;   r'   Iterable[Path]c                   sL   t | j}t|g|R i | tj fddI d H }dd |D S )Nc                     s
   t   S r)   )listr-   funcr-   r.   <lambda>b   s   
 z7iter_wrapper_factory.<locals>.wrapper.<locals>.<lambda>c                 s  s    | ]}t |V  qd S r)   )r/   ).0itemr-   r-   r.   	<genexpr>c   s    z8iter_wrapper_factory.<locals>.wrapper.<locals>.<genexpr>)r<   r=   r   trio	to_threadrun_sync)r7   r8   r:   methitemsrN   rR   r.   r?   \   s
   z%iter_wrapper_factory.<locals>.wrapper)r7   r,   r8   r9   r:   r;   r'   rP   r   _wrapsr0   rN   r?   r-   r]   r.   iter_wrapper_factoryY   s   ra   /Callable[Concatenate[Path, P], Awaitable[Path]]c                   s    t | | j d
 fdd	}|S )Nr7   r,   r8   r9   r:   r;   r'   c                   >   t | j }t|g|R i |}tj|I d H }t|S r)   )r<   r=   r   rX   rY   rZ   r/   )r7   r8   r:   r[   rS   r&   r]   r-   r.   r?   k   
   z'thread_wrapper_factory.<locals>.wrapper)r7   r,   r8   r9   r:   r;   r'   r,   r^   r`   r-   r]   r.   thread_wrapper_factoryh   s   re   classmethodc                   sH   t | | j d
 fdd	}t|tjsJ tt| j |_t	|S )Nr0   
type[Path]r8   r   r:   r'   r,   c                   rc   r)   )r<   r_   r   rX   rY   rZ   r/   )r0   r8   r:   r[   rS   r&   r]   r-   r.   r?   x   rd   z,classmethod_wrapper_factory.<locals>.wrapper)r0   rg   r8   r   r:   r   r'   r,   )
r   r_   r*   r@   rA   rB   rC   r<   rD   rf   r`   r-   r]   r.   classmethod_wrapper_factoryu   s
   rh   c                      sp   e Zd ZU ded< ded< ded< ded< ded< d fddZdddZdddZdddZdddZ  Z	S )r1   type	_forwardsr_   	list[str]rM   
_wrap_iter_forwardnamer3   basestuple[type, ...]attrsdict[str, object]r'   Nonec                   sZ   t  ||| g | _t| | | t| | | t| | | t| | | d S r)   )super__init__rm   ri   generate_forwardsgenerate_wrapsgenerate_magicgenerate_iter)r0   rn   ro   rq   	__class__r-   r.   ru      s   zAsyncAutoWrapperType.__init__c                 C  sx   | j j D ]3\}}|ds||v rqt|tr | j| qt|tj	r3t
| ||}t| || qt|t|d S N_)rj   __dict__r\   
startswithr*   propertyrm   appendr@   rA   rE   setattr	TypeErrorri   r0   rq   r2   r4   r?   r-   r-   r.   rv      s   
z&AsyncAutoWrapperType.generate_forwardsc                 C  s   | j j D ]E\}}|ds||v rqt|tr%t| |}t| || qt|tj	rEt
| |}t|tj	s8J t||_t| || qt|t|d S r|   )r_   r~   r\   r   r*   rf   rh   r   r@   rA   re   rB   rC   rD   r   ri   r   r-   r-   r.   rw      s   


z#AsyncAutoWrapperType.generate_wrapsc                 C  s2   | j D ]}t| j|}t | |}t| || qd S r)   )rM   r<   rj   r   r   r-   r-   r.   rx      s
   

z#AsyncAutoWrapperType.generate_magicc                 C  sV   | j j D ]"\}}|| jv r(t| |}t|tjsJ t	||_
t| || qd S r)   )r_   r~   r\   rl   ra   r*   r@   rA   rB   rC   rD   r   r   r-   r-   r.   ry      s   

z"AsyncAutoWrapperType.generate_iter)rn   r3   ro   rp   rq   rr   r'   rs   )rq   rr   r'   rs   )
__name__
__module____qualname____annotations__ru   rv   rw   rx   ry   __classcell__r-   r-   rz   r.   r1      s   
 


c                      s\  e Zd ZU dZded< ejZded< ejZ	ded< g dZ
ded< g d	Zded
< dddZes4dd Zd fddZdddZdddZe					ddd'd(Ze			ddd,d(Ze				ddd0d(Ze				ddd3d(Ze				ddd6d(Ze				ddd8d(Ze				ddd:d(Zeejjdd=d(Zerdd?d@ZddBdCZddDdEZddHdIZddJdKZddLdMZddNdOZeddQdRZeddSdTZeddUdVZeddWdXZ eddYdZZ!edd[d\Z"edd]d^Z#edd_d`Z$eddbdcZ%ed dddeZ&ddfdgZ'ddhdiZ(ddjdkZ)ddldmZ*ddodpZ+ddqdrZ,ddtduZ-ddwdxZ.ddydzZ/e0j1d{krUdd|d}Z2dddZ3e4d ddZ5e0j1dkrvdddddZ6dddddZ7nd	ddZ6d
ddZ7dddZ8dddZ9dddZ:dddZ;dddZ<dddZ=dddZ>dddZ?dddZ@dddZAd
ddZBd	ddZCddddZDe0jEdkrdddZFdddZGdddZHe0j1d{krd ddZIdddZJdddZKddddZLdddZMdddZNddddńZOe0j1dkr(dddȄZPdddd˄ZQdddd΄ZRe4d ddЄZSd dd҄ZTd ddԄZUdddքZVdddd؄ZWddd܄ZXddd߄ZYe0j1dkrv			ddddZZn
		ddddZZe0j1dk rdddZ[e0j1dkrdddZ\d;ed< dddZ]  Z^S   Z^S   Z^S (   r,   zlA :class:`pathlib.Path` wrapper that executes blocking methods in
    :meth:`trio.to_thread.run_sync`.

    zClassVar[list[str]]rm   zClassVar[type]r_   rj   )
__str__	__bytes____truediv____rtruediv____eq____lt____le____gt____ge____hash__rM   )globrglobiterdirrl   r8   r%   r'   rs   c                 G  s   t j| | _d S r)   )r+   r,   r=   )r7   r8   r-   r-   r.   ru         zPath.__init__c                 C  s&   || j v rt| j|}t|S t|r)   )rm   r<   r=   r/   AttributeError)r7   rn   r&   r-   r-   r.   __getattr__   s   
zPath.__getattr__rk   c                   s   g t   | jS r)   )rt   __dir__rm   r7   rz   r-   r.   r      s   zPath.__dir__r3   c                 C  s   dt | dS )Nz
trio.Path())r3   r   r-   r-   r.   __repr__   r   zPath.__repr__c                 C  s   t | jS r)   )osfspathr=   r   r-   r-   r.   
__fspath__   s   zPath.__fspath__rNmoder   	bufferingintencoding
str | Noneerrorsnewline_AsyncIOWrapper[TextIOWrapper]c                      d S r)   r-   r7   r   r   r   r   r   r-   r-   r.   open      	z	Path.openr   
Literal[0]_AsyncIOWrapper[FileIO]c                   r   r)   r-   r   r-   r-   r.   r     r   r   Literal[-1, 1]_AsyncIOWrapper[BufferedRandom]c                   r   r)   r-   r   r-   r-   r.   r     r   r   _AsyncIOWrapper[BufferedWriter]c                   r   r)   r-   r   r-   r-   r.   r     r   r   _AsyncIOWrapper[BufferedReader]c                   r   r)   r-   r   r-   r-   r.   r   #  r   _AsyncIOWrapper[BinaryIO]c                   r   r)   r-   r   r-   r-   r.   r   .  r   _AsyncIOWrapper[IO[Any]]c                   r   r)   r-   r   r-   r-   r.   r   9  r   r   r:   c                   s8   t | jjg|R i |}tj|I dH }t|S )zfOpen the file pointed to by the path, like the :func:`trio.open_file`
        function does.

        N)r   r=   r   rX   rY   rZ   Z	wrap_file)r7   r8   r:   rS   r&   r-   r-   r.   r   D  s   
bytesc                 C     d S r)   r-   r   r-   r-   r.   r   R      zPath.__bytes__rH   c                 C  r   r)   r-   r7   rH   r-   r-   r.   r   S  r   zPath.__truediv__c                 C  r   r)   r-   r   r-   r-   r.   r   T  r   zPath.__rtruediv__Path | pathlib.PurePathboolc                 C  r   r)   r-   r   r-   r-   r.   r   U  r   zPath.__lt__c                 C  r   r)   r-   r   r-   r-   r.   r   V  r   zPath.__le__c                 C  r   r)   r-   r   r-   r-   r.   r   W  r   zPath.__gt__c                 C  r   r)   r-   r   r-   r-   r.   r   X  r   zPath.__ge__tuple[str, ...]c                 C  r   r)   r-   r   r-   r-   r.   parts]     z
Path.partsc                 C  r   r)   r-   r   r-   r-   r.   drive_  r   z
Path.drivec                 C  r   r)   r-   r   r-   r-   r.   roota  r   z	Path.rootc                 C  r   r)   r-   r   r-   r-   r.   anchorc  r   zPath.anchorc                 C  r   r)   r-   r   r-   r-   r.   rn   e  r   z	Path.namec                 C  r   r)   r-   r   r-   r-   r.   suffixg  r   zPath.suffixc                 C  r   r)   r-   r   r-   r-   r.   suffixesi  r   zPath.suffixesc                 C  r   r)   r-   r   r-   r-   r.   stemk  r   z	Path.stemSequence[pathlib.Path]c                 C  r   r)   r-   r   r-   r-   r.   parentsm  r   zPath.parentsc                 C  r   r)   r-   r   r-   r-   r.   parento  r   zPath.parentc                 C  r   r)   r-   r   r-   r-   r.   as_posixs  r   zPath.as_posixc                 C  r   r)   r-   r   r-   r-   r.   as_urit  r   zPath.as_uric                 C  r   r)   r-   r   r-   r-   r.   is_absoluteu  r   zPath.is_absolutec                 C  r   r)   r-   r   r-   r-   r.   is_reservedv  r   zPath.is_reservedpath_patternc                 C  r   r)   r-   )r7   r   r-   r-   r.   matchw  r   z
Path.matchc                 G  r   r)   r-   r   r-   r-   r.   relative_tox  r   zPath.relative_torn   c                 C  r   r)   r-   )r7   rn   r-   r-   r.   	with_namey  r   zPath.with_namer   c                 C  r   r)   r-   )r7   r   r-   r-   r.   with_suffixz  r   zPath.with_suffixc                 G  r   r)   r-   r   r-   r-   r.   joinpath{  r   zPath.joinpath)   	   c                 G  r   r)   r-   r   r-   r-   r.   is_relative_to~  r   zPath.is_relative_tor   c                 C  r   r)   r-   )r7   r   r-   r-   r.   	with_stem  r   zPath.with_stemc                   r   r)   r-   r   r-   r-   r.   cwd     zPath.cwd)r   
   T)follow_symlinksr   os.stat_resultc                  r   r)   r-   )r7   r   r-   r-   r.   stat      z	Path.statc                  r   r)   r-   )r7   r   r   r-   r-   r.   chmod  r   z
Path.chmodc                   r   r)   r-   r   r-   r-   r.   r     r   c                   r   r)   r-   r7   r   r-   r-   r.   r     r   c                   r   r)   r-   r   r-   r-   r.   exists  r   zPath.existspatternrP   c                   r   r)   r-   r7   r   r-   r-   r.   r     r   z	Path.globc                   r   r)   r-   r   r-   r-   r.   is_dir  r   zPath.is_dirc                   r   r)   r-   r   r-   r-   r.   is_file  r   zPath.is_filec                   r   r)   r-   r   r-   r-   r.   
is_symlink  r   zPath.is_symlinkc                   r   r)   r-   r   r-   r-   r.   	is_socket  r   zPath.is_socketc                   r   r)   r-   r   r-   r-   r.   is_fifo  r   zPath.is_fifoc                   r   r)   r-   r   r-   r-   r.   is_block_device  r   zPath.is_block_devicec                   r   r)   r-   r   r-   r-   r.   is_char_device  r   zPath.is_char_devicec                   r   r)   r-   r   r-   r-   r.   r     r   zPath.iterdirc                   r   r)   r-   r   r-   r-   r.   lchmod  r   zPath.lchmodc                   r   r)   r-   r   r-   r-   r.   lstat  r   z
Path.lstat  Fr   exist_okc                   r   r)   r-   )r7   r   r   r   r-   r-   r.   mkdir  r   z
Path.mkdirwin32c                   r   r)   r-   r   r-   r-   r.   owner  r   z
Path.ownerc                   r   r)   r-   r   r-   r-   r.   group  r   z
Path.groupc                   r   r)   r-   r   r-   r-   r.   is_mount  r   zPath.is_mountc                   r   r)   r-   r   r-   r-   r.   readlink  r   zPath.readlinktargetc                   r   r)   r-   r7   r   r-   r-   r.   rename  r   zPath.renamec                   r   r)   r-   r   r-   r-   r.   replace  r   zPath.replacestrictc                   r   r)   r-   )r7   r   r-   r-   r.   resolve  r   zPath.resolvec                   r   r)   r-   r   r-   r-   r.   r     r   z
Path.rglobc                   r   r)   r-   r   r-   r-   r.   rmdir  r   z
Path.rmdirtarget_is_directoryc                   r   r)   r-   )r7   r   r   r-   r-   r.   
symlink_to  r   zPath.symlink_tostr | pathlib.Pathc                   r   r)   r-   r   r-   r-   r.   hardlink_to  r   zPath.hardlink_to  c                   r   r)   r-   )r7   r   r   r-   r-   r.   touch  r   z
Path.touch
missing_okc                   r   r)   r-   )r7   r  r-   r-   r.   unlink  r   zPath.unlinkc                   r   r)   r-   r   r-   r-   r.   home  r   z	Path.homec                   r   r)   r-   r   r-   r-   r.   absolute  r   zPath.absolutec                   r   r)   r-   r   r-   r-   r.   
expanduser  r   zPath.expanduserc                   r   r)   r-   r   r-   r-   r.   
read_bytes  r   zPath.read_bytesc                   r   r)   r-   )r7   r   r   r-   r-   r.   	read_text  r   zPath.read_text
other_pathbytes | int | StrPathc                   r   r)   r-   )r7   r  r-   r-   r.   samefile  r   zPath.samefiledatac                   r   r)   r-   )r7   r  r-   r-   r.   write_bytes  r   zPath.write_bytesc                   r   r)   r-   )r7   r  r   r   r   r-   r-   r.   
write_text  s   zPath.write_textc                   r   r)   r-   )r7   r  r   r   r-   r-   r.   r    s   r      StrPath | bytesc                   r   r)   r-   r   r-   r-   r.   link_to  r   zPath.link_toc                   r   r)   r-   r   r-   r-   r.   is_junction  r   zPath.is_junctionwalkpathsegmentsc                   r   r)   r-   )r7   r  r-   r-   r.   with_segments  r   zPath.with_segments)r8   r%   r'   rs   )r'   rk   )r'   r3   )r   r   NNN)r   r   r   r   r   r   r   r   r   r   r'   r   )NNN)r   r   r   r   r   rs   r   rs   r   rs   r'   r   )r   NNN)r   r   r   r   r   rs   r   rs   r   rs   r'   r   )r   r   r   r   r   rs   r   rs   r   rs   r'   r   )r   r   r   r   r   rs   r   rs   r   rs   r'   r   )r   r   r   r   r   rs   r   rs   r   rs   r'   r   )r   r3   r   r   r   r   r   r   r   r   r'   r   )r8   r   r:   r   r'   r   )r'   r   )rH   r%   r'   r,   )rH   r   r'   r   )r'   r   )r'   r   )r'   r,   )r'   r   )r   r3   r'   r   )rn   r3   r'   r,   )r   r3   r'   r,   )rH   r%   r'   r   )r   r3   r'   r,   )r   r   r'   r   )r   r   r   r   r'   rs   )r'   r   )r   r   r'   rs   )r   r3   r'   rP   )r'   rP   )r   FF)r   r   r   r   r   r   r'   rs   )r   r%   r'   r,   )F)r   r   r'   r,   )r'   rs   )r   r%   r   r   r'   rs   )r   r   r'   rs   )r   T)r   r   r   r   r'   rs   )r  r   r'   rs   )NN)r   r   r   r   r'   r3   )r  r	  r'   r   )r  r   r'   r   )
r  r3   r   r   r   r   r   r   r'   r   )r  r3   r   r   r   r   r'   r   )r   r  r'   rs   )r  r%   r'   r,   )_r   r   r   __doc__r   r+   r,   r_   PurePathrj   rM   rl   ru   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rn   r   r   r   r   r   r   r   r   r   r   r   r   r   r   sysversion_infor   r   rf   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   platformr   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-   r-   rz   r.   r,      s:  
 

























	tr,   )	metaclassa  
    Like :meth:`~pathlib.Path.iterdir`, but async.

    This is an async method that returns a synchronous iterator, so you
    use it like::

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

    Note that it actually loads the whole directory list into memory
    immediately, during the initial call. (See `issue #501
    <https://github.com/python-trio/trio/issues/501>`__ for discussion.)

r  z
    Like Python 3.8-3.11's :meth:`~pathlib.Path.link_to`, but async.

    :deprecated: This method was deprecated in Python 3.10 and entirely     removed in 3.12. Use :meth:`hardlink_to` instead which has     a more meaningful parameter order.
)r&   r$   r'   r(   )r0   r1   r2   r3   r4   r5   r'   r6   )r0   r1   r4   rF   r'   rG   )r0   r1   rN   r3   r'   rO   )r0   r1   rN   r3   r'   rb   )r0   r1   rN   r3   r'   rf   )F
__future__r   rB   r   r+   r  r@   collections.abcr   r   r   r   	functoolsr   ior   r	   r
   r   r   typingr   r   r   r   r   r   r   r   r   rX   Ztrio._file_ior   Z_AsyncIOWrapperZ
trio._utilr   r   r   Z	_typeshedr   r   r   r   r   typing_extensionsr   r    r!   r"   r#   r$   r3   r%   r   r/   rE   rM   ra   re   rh   ri   r1   r,   r   r  r  r  r  PathLikeregisterr-   r-   r-   r.   <module>   sF    ,





D  
