o
    :ήczG                     @   s  d dl Z d dlZd dlZd dlmZ d dlmZ d dl mZ d dlm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZ ejd	krZd d
lmZ nd d
lmZ e
rod dl m!Z!m"Z"m#Z#m$Z$ ne% Z# Z! Z"Z$G dd deee Z&e						d(dee'de(f de!de(dee' dee' dee' de)deee'e(ge(f  de&e* fddZ+e							d)dee'de(f de"de(dee' dee' dee' de)deee'e(ge(f  de&e' fddZ+							d*dee'de(f de'de(dee' dee' dee' de)deee'e(ge(f  de&e fddZ+de	e de&e fd d!Z,ed"d#G d$d% d%ed& Z-G d'd& d&Z.e/e. dS )+    N)	dataclass)partial)PathLike)IOTYPE_CHECKINGAnyAnyStrAsyncIteratorCallableGenericIterableIteratorListOptionalSequenceTupleUnioncastoverload   )	to_thread)AsyncResource)      )Final)OpenBinaryModeOpenTextModeReadableBufferWriteableBufferc                   @   s  e Zd ZdZdee ddfddZdedefdd	Z	e
dee fd
dZdee fddZd5ddZd6dedefddZd6dddedefddZdefddZdee fddZdddedefddZdddedefdd Zedddedefd!d"Zedd#dedefd$d"Zdeeef defd%d"Zeddd&ee ddfd'd(Zedd#d&ee ddfd)d(Zd&eee ee f ddfd*d(Zd7dee defd+d,Z e!j"fd-ed.ee defd/d0Z#defd1d2Z$d5d3d4Z%dS )8	AsyncFilea  
    An asynchronous file object.

    This class wraps a standard file object and provides async friendly versions of the following
    blocking methods (where available on the original file object):

    * read
    * read1
    * readline
    * readlines
    * readinto
    * readinto1
    * write
    * writelines
    * truncate
    * seek
    * tell
    * flush

    All other methods are directly passed through.

    This class supports the asynchronous context manager protocol which closes the underlying file
    at the end of the context block.

    This class also supports asynchronous iteration::

        async with await open_file(...) as f:
            async for line in f:
                print(line)
    fpreturnNc                 C   s
   || _ d S N_fp)selfr     r&   :/tmp/pip-target-vg8gfxp4/lib/python/anyio/_core/_fileio.py__init__H      
zAsyncFile.__init__namec                 C   s   t | j|S r"   )getattrr$   r%   r*   r&   r&   r'   __getattr__K      zAsyncFile.__getattr__c                 C   s   | j S )zThe wrapped file object.r#   r%   r&   r&   r'   wrappedN   s   zAsyncFile.wrappedc                 C  s$   	 |   I d H }|r|V  nd S qr"   )readline)r%   liner&   r&   r'   	__aiter__S   s   zAsyncFile.__aiter__c                       t | jjI d H S r"   )r   run_syncr$   closer/   r&   r&   r'   aclose[      zAsyncFile.aclosesizec                       t | jj|I d H S r"   )r   r5   r$   readr%   r:   r&   r&   r'   r<   ^      zAsyncFile.readr%   zAsyncFile[bytes]c                    r;   r"   )r   r5   r$   read1r=   r&   r&   r'   r?   a   r>   zAsyncFile.read1c                    r4   r"   )r   r5   r$   r1   r/   r&   r&   r'   r1   d   r8   zAsyncFile.readlinec                    r4   r"   )r   r5   r$   	readlinesr/   r&   r&   r'   r@   g   r8   zAsyncFile.readlinesbc                    r;   r"   )r   r5   r$   readintor%   rA   r&   r&   r'   rB   j   r>   zAsyncFile.readintoc                    r;   r"   )r   r5   r$   	readinto1rC   r&   r&   r'   rD   m   r>   zAsyncFile.readinto1c                       d S r"   r&   rC   r&   r&   r'   writep      zAsyncFile.writezAsyncFile[str]c                    rE   r"   r&   rC   r&   r&   r'   rF   t   rG   c                    r;   r"   )r   r5   r$   rF   rC   r&   r&   r'   rF   x   r>   linesc                    rE   r"   r&   r%   rH   r&   r&   r'   
writelines{   s   zAsyncFile.writelinesc                    rE   r"   r&   rI   r&   r&   r'   rJ      rG   c                    r;   r"   )r   r5   r$   rJ   rI   r&   r&   r'   rJ      s   c                    r;   r"   )r   r5   r$   truncater=   r&   r&   r'   rK      r>   zAsyncFile.truncateoffsetwhencec                       t | jj||I d H S r"   )r   r5   r$   seek)r%   rL   rM   r&   r&   r'   rO         zAsyncFile.seekc                    r4   r"   )r   r5   r$   tellr/   r&   r&   r'   rQ      r8   zAsyncFile.tellc                    r4   r"   )r   r5   r$   flushr/   r&   r&   r'   rR      r8   zAsyncFile.flushr!   N)r9   r"   )&__name__
__module____qualname____doc__r   r   r(   strobjectr-   propertyr0   r	   r3   r7   intr<   bytesr?   r1   r   r@   r   rB   rD   r   r   rF   r   r   rJ   r   rK   osSEEK_SETrO   rQ   rR   r&   r&   r&   r'   r   (   sL    

 r   .filePathLike[str]mode	bufferingencodingerrorsnewlineclosefdopenerr!   c                    rE   r"   r&   r_   ra   rb   rc   rd   re   rf   rg   r&   r&   r'   	open_file      ri   c                    rE   r"   r&   rh   r&   r&   r'   ri      rj   rr9   Tc           	         s*   t t| |||||||	I dH }t|S )z
    Open a file asynchronously.

    The arguments are exactly the same as for the builtin :func:`open`.

    :return: an asynchronous file object

    N)r   r5   openr   )	r_   ra   rb   rc   rd   re   rf   rg   r    r&   r&   r'   ri      s
   
c                 C   s   t | S )z
    Wrap an existing file as an asynchronous file.

    :param file: an existing file-like object
    :return: an asynchronous file object

    )r   )r_   r&   r&   r'   	wrap_file   s   rm   F)eqc                   @   s$   e Zd ZU ed ed< dddZdS )	_PathIteratorr`   iteratorr!   Pathc                    s8   t jt| jd ddI d H }|d u rtd ttd|S )NTcancellabler`   )r   r5   nextrp   StopAsyncIterationrq   r   )r%   nextvalr&   r&   r'   	__anext__   s
   z_PathIterator.__anext__Nr!   rq   )rT   rU   rV   r   __annotations__rw   r&   r&   r&   r'   ro      s   
 ro   rq   c                   @   s2  e Zd ZU dZdZeed< deedf ddfdd	Z	defd
dZ
defddZdefddZdefddZdefddZdedefddZdd defddZdd defddZdd defddZdd defddZdedd fdd Zdedd fd!d"Zedeed#f fd$d%Zedefd&d'Zedefd(d)Zedefd*d+Zede d  fd,d-Z!edd.d/Z"edefd0d1Z#edefd2d3Z$ede%e fd4d5Z&edefd6d7Z'dd8d9Z(defd:d;Z)defd<d=Z*d>edefd?d@Z+deedf defdAdBZ,dCdDdEedFeddfdGdHZ-e.ddIdJZ/defdKdLZ0ddMdNZ1dOede2d  fdPdQZ3defdRdSZ4dTeee5j6d f ddfdUdVZ7e.ddWdXZ8defdYdZZ9defd[d\Z:defd]d^Z;defd_d`Z<defdadbZ=defdcddZ>defdedfZ?defdgdhZ@defdidjZAdefdkdlZBde2d  fdmdnZCdeedf dd fdodpZDdEeddfdqdrZEdeFjGfdsdtZH	vddEedwedxeddfdydzZIeJ	#	#	#	#ddEeKd{ed|eLe d}eLe d~eLe deMe fddZNeJ	#	#	#	#	#ddEeOd{ed|eLe d}eLe d~eLe deMe fddZN					ddEed{ed|eLe d}eLe d~eLe deMe fddZNdefddZPdefddZQ	dd|eLe d}eLe defddZRdeedf dd fddZSdddZTdTeee5jUd f dd fddZVdTeee5jUd f dd fddZWddedd fddZXdOede2d  fddZYdddZZdeeeee5j6d f defddZ[dCdDdFedeFjGfddZ\	vddTeee5j6d f deddfddZ]ddEedxeddfddZ^ddeddfddZ_dedd fddZ`dedd fddZadedd fddZbdedefddZc			dded|eLe d}eLe d~eLe def
ddZddS )rq   a  
    An asynchronous version of :class:`pathlib.Path`.

    This class cannot be substituted for :class:`pathlib.Path` or :class:`pathlib.PurePath`, but
    it is compatible with the :class:`os.PathLike` interface.

    It implements the Python 3.10 version of :class:`pathlib.Path` interface, except for the
    deprecated :meth:`~pathlib.Path.link_to` method.

    Any methods that do disk I/O need to be awaited on. These methods are:

    * :meth:`~pathlib.Path.absolute`
    * :meth:`~pathlib.Path.chmod`
    * :meth:`~pathlib.Path.cwd`
    * :meth:`~pathlib.Path.exists`
    * :meth:`~pathlib.Path.expanduser`
    * :meth:`~pathlib.Path.group`
    * :meth:`~pathlib.Path.hardlink_to`
    * :meth:`~pathlib.Path.home`
    * :meth:`~pathlib.Path.is_block_device`
    * :meth:`~pathlib.Path.is_char_device`
    * :meth:`~pathlib.Path.is_dir`
    * :meth:`~pathlib.Path.is_fifo`
    * :meth:`~pathlib.Path.is_file`
    * :meth:`~pathlib.Path.is_mount`
    * :meth:`~pathlib.Path.lchmod`
    * :meth:`~pathlib.Path.lstat`
    * :meth:`~pathlib.Path.mkdir`
    * :meth:`~pathlib.Path.open`
    * :meth:`~pathlib.Path.owner`
    * :meth:`~pathlib.Path.read_bytes`
    * :meth:`~pathlib.Path.read_text`
    * :meth:`~pathlib.Path.readlink`
    * :meth:`~pathlib.Path.rename`
    * :meth:`~pathlib.Path.replace`
    * :meth:`~pathlib.Path.rmdir`
    * :meth:`~pathlib.Path.samefile`
    * :meth:`~pathlib.Path.stat`
    * :meth:`~pathlib.Path.touch`
    * :meth:`~pathlib.Path.unlink`
    * :meth:`~pathlib.Path.write_bytes`
    * :meth:`~pathlib.Path.write_text`

    Additionally, the following methods return an async iterator yielding :class:`~.Path` objects:

    * :meth:`~pathlib.Path.glob`
    * :meth:`~pathlib.Path.iterdir`
    * :meth:`~pathlib.Path.rglob`
    )_path__weakref__r{   argsr`   r!   Nc                 G   s   t j| | _d S r"   )pathlibrq   rz   r%   r|   r&   r&   r'   r(        zPath.__init__c                 C   
   | j  S r"   )rz   
__fspath__r/   r&   r&   r'   r     r)   zPath.__fspath__c                 C   r   r"   )rz   __str__r/   r&   r&   r'   r     r)   zPath.__str__c                 C   s   | j j d|  dS )N())	__class__rT   as_posixr/   r&   r&   r'   __repr__"     zPath.__repr__c                 C   r   r"   )rz   	__bytes__r/   r&   r&   r'   r   %  r)   zPath.__bytes__c                 C   r   r"   )rz   __hash__r/   r&   r&   r'   r   (  r)   zPath.__hash__otherc                 C       t |tr|jn|}| j|S r"   )
isinstancerq   rz   __eq__r%   r   targetr&   r&   r'   r   +     zPath.__eq__c                 C   r   r"   )r   rq   rz   __lt__r   r&   r&   r'   r   /  r   zPath.__lt__c                 C   r   r"   )r   rq   rz   __le__r   r&   r&   r'   r   3  r   zPath.__le__c                 C   r   r"   )r   rq   rz   __gt__r   r&   r&   r'   r   7  r   zPath.__gt__c                 C   r   r"   )r   rq   rz   __ge__r   r&   r&   r'   r   ;  r   zPath.__ge__c                 C   s   t | j| S r"   )rq   rz   r%   r   r&   r&   r'   __truediv__?  s   zPath.__truediv__c                 C   s   t ||  S r"   rq   r   r&   r&   r'   __rtruediv__B  r.   zPath.__rtruediv__.c                 C      | j jS r"   )rz   partsr/   r&   r&   r'   r   E     z
Path.partsc                 C   r   r"   )rz   driver/   r&   r&   r'   r   I  r   z
Path.drivec                 C   r   r"   )rz   rootr/   r&   r&   r'   r   M  r   z	Path.rootc                 C   r   r"   )rz   anchorr/   r&   r&   r'   r   Q  r   zPath.anchorc                 C   s   t dd | jjD S )Nc                 s   s    | ]}t |V  qd S r"   r   ).0pr&   r&   r'   	<genexpr>W  s    zPath.parents.<locals>.<genexpr>)tuplerz   parentsr/   r&   r&   r'   r   U  s   zPath.parentsc                 C   s   t | jjS r"   )rq   rz   parentr/   r&   r&   r'   r   Y  s   zPath.parentc                 C   r   r"   )rz   r*   r/   r&   r&   r'   r*   ]  r   z	Path.namec                 C   r   r"   )rz   suffixr/   r&   r&   r'   r   a  r   zPath.suffixc                 C   r   r"   )rz   suffixesr/   r&   r&   r'   r   e  r   zPath.suffixesc                 C   r   r"   )rz   stemr/   r&   r&   r'   r   i  r   z	Path.stemc                    s   t | jjI d H }t|S r"   )r   r5   rz   absoluterq   )r%   pathr&   r&   r'   r   m  s   zPath.absolutec                 C   r   r"   )rz   r   r/   r&   r&   r'   r   q  r)   zPath.as_posixc                 C   r   r"   )rz   as_urir/   r&   r&   r'   r   t  r)   zPath.as_uripath_patternc                 C   s   | j |S r"   )rz   match)r%   r   r&   r&   r'   r   w  r.   z
Path.matchc                 G   s&   z| j |  W dS  ty   Y dS w )NTF)relative_to
ValueErrorr   r&   r&   r'   is_relative_toz  s   
zPath.is_relative_toTfollow_symlinksra   r   c                   s&   t tj|d}t|| j|I d H S )Nr   )r   r]   chmodr   r5   rz   )r%   ra   r   funcr&   r&   r'   r     s   z
Path.chmodc                       t tjjI d H }| |S r"   )r   r5   r}   rq   cwd)clsr   r&   r&   r'   r        zPath.cwdc                       t j| jjddI d H S NTrr   )r   r5   rz   existsr/   r&   r&   r'   r     rP   zPath.existsc                    s   t tj| jjddI d H S r   )rq   r   r5   rz   
expanduserr/   r&   r&   r'   r        zPath.expanduserpatternc                 C      | j |}t|S r"   )rz   globro   r%   r   genr&   r&   r'   r        z	Path.globc                    r   r   )r   r5   rz   groupr/   r&   r&   r'   r     rP   z
Path.groupr   c                    s,   t |tr	|j}ttj|| I d H  d S r"   )r   rq   rz   r   r5   r]   linkr%   r   r&   r&   r'   hardlink_to  s   
zPath.hardlink_toc                    r   r"   )r   r5   r}   rq   home)r   	home_pathr&   r&   r'   r     r   z	Path.homec                 C   r   r"   )rz   is_absoluter/   r&   r&   r'   r     r)   zPath.is_absolutec                    r   r   )r   r5   rz   is_block_devicer/   r&   r&   r'   r     rP   zPath.is_block_devicec                    r   r   )r   r5   rz   is_char_devicer/   r&   r&   r'   r     rP   zPath.is_char_devicec                    r   r   )r   r5   rz   is_dirr/   r&   r&   r'   r     rP   zPath.is_dirc                    r   r   )r   r5   rz   is_fifor/   r&   r&   r'   r     rP   zPath.is_fifoc                    r   r   )r   r5   rz   is_filer/   r&   r&   r'   r     rP   zPath.is_filec                    s   t jtjj| jddI d H S r   )r   r5   r]   r   ismountrz   r/   r&   r&   r'   is_mount  r   zPath.is_mountc                 C   r   r"   )rz   is_reservedr/   r&   r&   r'   r     r)   zPath.is_reservedc                    r   r   )r   r5   rz   	is_socketr/   r&   r&   r'   r     rP   zPath.is_socketc                    r   r   )r   r5   rz   
is_symlinkr/   r&   r&   r'   r     rP   zPath.is_symlinkc                 C   s   | j  }t|S r"   )rz   iterdirro   )r%   r   r&   r&   r'   r     s   
zPath.iterdirc                 G      t | jj| S r"   )rq   rz   joinpathr~   r&   r&   r'   r     r   zPath.joinpathc                    s   t | jj|I d H  d S r"   )r   r5   rz   lchmod)r%   ra   r&   r&   r'   r     s   zPath.lchmodc                    r   r   )r   r5   rz   lstatr/   r&   r&   r'   r     rP   z
Path.lstat  Fr   exist_okc                    s    t | jj|||I d H  d S r"   )r   r5   rz   mkdir)r%   ra   r   r   r&   r&   r'   r     s   z
Path.mkdirrb   rc   rd   re   c                    rE   r"   r&   r%   ra   rb   rc   rd   re   r&   r&   r'   rl        	z	Path.openc                    rE   r"   r&   r   r&   r&   r'   rl     r   rk   r9   c                    s(   t | jj|||||I d H }t|S r"   )r   r5   rz   rl   r   )r%   ra   rb   rc   rd   re   r    r&   r&   r'   rl     s
   
c                    r   r   )r   r5   rz   ownerr/   r&   r&   r'   r     rP   z
Path.ownerc                    r4   r"   )r   r5   rz   
read_bytesr/   r&   r&   r'   r     r8   zPath.read_bytesc                    rN   r"   )r   r5   rz   	read_text)r%   rc   rd   r&   r&   r'   r     s   zPath.read_textc                 G   r   r"   )rq   rz   r   r   r&   r&   r'   r      r   zPath.relative_toc                    s&   t tj| jI d H }ttt|S r"   )r   r5   r]   readlinkrz   rq   r   rX   r   r&   r&   r'   r     s   zPath.readlinkc                    0   t |tr	|j}t| jj|I d H  t|S r"   )r   rq   rz   r   r5   renamer   r&   r&   r'   r     
   
zPath.renamec                    r   r"   )r   rq   rz   r   r5   replacer   r&   r&   r'   r     r   zPath.replacestrictc                    s*   t | jj|d}ttj|ddI d H S )N)r   Trr   )r   rz   resolverq   r   r5   )r%   r   r   r&   r&   r'   r     s   zPath.resolvec                 C   r   r"   )rz   rglobro   r   r&   r&   r'   r     r   z
Path.rglobc                    s   t | jjI d H  d S r"   )r   r5   rz   rmdirr/   r&   r&   r'   r     rP   z
Path.rmdir
other_pathc                    s,   t |tr	|j}tj| jj|ddI d H S r   )r   rq   rz   r   r5   samefile)r%   r   r&   r&   r'   r      s   

zPath.samefilec                   s(   t tj|d}tj|| jddI d H S )Nr   Trr   )r   r]   statr   r5   rz   )r%   r   r   r&   r&   r'   r   *  s   z	Path.stattarget_is_directoryc                    s.   t |tr	|j}t| jj||I d H  d S r"   )r   rq   rz   r   r5   
symlink_to)r%   r   r   r&   r&   r'   r   .  s   
zPath.symlink_to  c                    s   t | jj||I d H  d S r"   )r   r5   rz   touch)r%   ra   r   r&   r&   r'   r   8  r   z
Path.touch
missing_okc                    s8   zt | jjI d H  W d S  ty   |s Y d S w r"   )r   r5   rz   unlinkFileNotFoundError)r%   r   r&   r&   r'   r   ;  s   zPath.unlinkr*   c                 C      t | j|S r"   )rq   rz   	with_namer,   r&   r&   r'   r   B  r   zPath.with_namer   c                 C   s   t | j|| jj S r"   )rq   rz   r   r   )r%   r   r&   r&   r'   	with_stemE  r   zPath.with_stemr   c                 C   r   r"   )rq   rz   with_suffix)r%   r   r&   r&   r'   r   H  r   zPath.with_suffixdatac                    r;   r"   )r   r5   rz   write_bytes)r%   r   r&   r&   r'   r   K  r>   zPath.write_bytesc                    s,   dt f fdd}t|I d H S )Nr!   c                     sB   j jdd} |  W  d    S 1 sw   Y  d S )Nw)rc   rd   re   )rz   rl   rF   )r    r   rc   rd   re   r%   r&   r'   sync_write_textV  s   $z(Path.write_text.<locals>.sync_write_text)r[   r   r5   )r%   r   rc   rd   re   r   r&   r   r'   
write_textN  s   zPath.write_textrx   )r   FF)....).....)rk   r9   NNN)NN)FrS   )r   T)NNN)erT   rU   rV   rW   	__slots__r   ry   r   rX   r(   r   r   r   r\   r   r[   r   rY   boolr   r   r   r   r   r   r   rZ   r   r   r   r   r   r   r   r   r*   r   r   r   r   r   r   r   r   r   r   classmethodr   r   r   r	   r   r   r}   rq   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r]   stat_resultr   r   r   r   r   r   rl   r   r   r   r   r   r   PurePathr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r&   r&   r&   r'   rq      sl  
 2











)......).......)rk   r9   NNNTN)0r]   r}   sysdataclassesr   	functoolsr   r   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r    r   abcr   version_infor   typing_extensions	_typeshedr   r   r   r   rY   r   rX   r[   r   r\   ri   rm   ro   rq   registerr&   r&   r&   r'   <module>   s    H
o			
  