a
    ”˜ëjv  ã                   @  sÒ   d dl mZ dZd dlmZmZ d dlmZmZ d dl	m
Z
 d dlmZ d dlmZmZmZ dd	lmZmZmZmZmZmZ dd
lmZmZ G dd„ deƒZG dd„ dƒZG dd„ deeƒZG dd„ deeƒZdS )é    )Úannotations)ÚFileReadStreamÚFileStreamAttributeÚFileWriteStream)ÚCallableÚMapping)ÚSEEK_SETÚUnsupportedOperation)ÚPathLike)ÚPath)ÚAnyÚBinaryIOÚcasté   )ÚBrokenResourceErrorÚClosedResourceErrorÚEndOfStreamÚTypedAttributeSetÚ	to_threadÚtyped_attribute)ÚByteReceiveStreamÚByteSendStreamc                   @  s8   e Zd ZU eƒ Zded< eƒ Zded< eƒ Zded< dS )r   r   Úfiler   ÚpathÚintÚfilenoN)Ú__name__Ú
__module__Ú__qualname__r   r   Ú__annotations__r   r   © r    r    úQ/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/anyio/streams/file.pyr      s   
r   c                   @  s:   e Zd Zddœdd„Zddœdd„Zed	dœd
d„ƒZdS )Ú_BaseFileStreamr   )r   c                 C  s
   || _ d S ©N©Ú_file)Úselfr   r    r    r!   Ú__init__$   s    z_BaseFileStream.__init__ÚNone©Úreturnc                 Ã  s   t  | jj¡I d H  d S r#   )r   Úrun_syncr%   Úclose©r&   r    r    r!   Úaclose'   s    z_BaseFileStream.aclosezMapping[Any, Callable[[], Any]]c                   sh   t j‡ fdd„i}tˆ jdƒr0‡ fdd„|t j< zˆ j ¡  W n tyP   Y n0 ‡ fdd„|t j< |S )Nc                     s   ˆ j S r#   r$   r    r-   r    r!   Ú<lambda>-   ó    z2_BaseFileStream.extra_attributes.<locals>.<lambda>Únamec                     s   t ˆ jjƒS r#   )r   r%   r1   r    r-   r    r!   r/   1   r0   c                     s
   ˆ j  ¡ S r#   )r%   r   r    r-   r    r!   r/   8   r0   )r   r   Úhasattrr%   r   r   r	   )r&   Ú
attributesr    r-   r!   Úextra_attributes*   s    ÿz _BaseFileStream.extra_attributesN)r   r   r   r'   r.   Úpropertyr4   r    r    r    r!   r"   #   s   r"   c                   @  sZ   e Zd ZdZedd dœdd„ƒZdddd	œd
d„Zefddddœdd„Zddœdd„Z	dS )r   z¦
    A byte stream that reads from a file in the file system.

    :param file: a file that has been opened for reading in binary mode

    .. versionadded:: 3.0
    ústr | PathLike[str])r   r*   c                 Ã  s&   t  t|ƒjd¡I dH }| tt|ƒƒS )z{
        Create a file read stream by opening the given file.

        :param path: path of the file to read from

        ÚrbN©r   r+   r   Úopenr   r   )Úclsr   r   r    r    r!   Ú	from_pathF   s    zFileReadStream.from_pathé   r   Úbytes)Ú	max_bytesr*   c              
   Ã  sl   zt  | jj|¡I d H }W n@ ty2   td ‚Y n* tyZ } zt|‚W Y d }~n
d }~0 0 |rd|S t‚d S r#   )	r   r+   r%   ÚreadÚ
ValueErrorr   ÚOSErrorr   r   )r&   r>   ÚdataÚexcr    r    r!   ÚreceiveQ   s    
zFileReadStream.receive)ÚpositionÚwhencer*   c                 Ã  s   t  | jj||¡I dH S )au  
        Seek the file to the given position.

        .. seealso:: :meth:`io.IOBase.seek`

        .. note:: Not all file descriptors are seekable.

        :param position: position to seek the file to
        :param whence: controls how ``position`` is interpreted
        :return: the new absolute position
        :raises OSError: if the file is not seekable

        N)r   r+   r%   Úseek)r&   rE   rF   r    r    r!   rG   ^   s    zFileReadStream.seekr)   c                 Ã  s   t  | jj¡I dH S )zÕ
        Return the current stream position.

        .. note:: Not all file descriptors are seekable.

        :return: the current absolute position
        :raises OSError: if the file is not seekable

        N)r   r+   r%   Útellr-   r    r    r!   rH   n   s    
zFileReadStream.tellN)r<   )
r   r   r   Ú__doc__Úclassmethodr;   rD   r   rG   rH   r    r    r    r!   r   =   s   
r   c                   @  s8   e Zd ZdZedddd dœdd„ƒZdd	d
œdd„ZdS )r   z¥
    A byte stream that writes to a file in the file system.

    :param file: a file that has been opened for writing in binary mode

    .. versionadded:: 3.0
    Fr6   Úbool)r   Úappendr*   c                 Ã  s2   |rdnd}t  t|ƒj|¡I dH }| tt|ƒƒS )a  
        Create a file write stream by opening the given file for writing.

        :param path: path of the file to write to
        :param append: if ``True``, open the file for appending; if ``False``, any
            existing file at the given path will be truncated

        ÚabÚwbNr8   )r:   r   rL   Úmoder   r    r    r!   r;   „   s    zFileWriteStream.from_pathr=   r(   )Úitemr*   c              
   Ã  s`   zt  | jj|¡I d H  W n@ ty2   td ‚Y n* tyZ } zt|‚W Y d }~n
d }~0 0 d S r#   )r   r+   r%   Úwriter@   r   rA   r   )r&   rP   rC   r    r    r!   Úsend”   s    
zFileWriteStream.sendN)F)r   r   r   rI   rJ   r;   rR   r    r    r    r!   r   {   s
    ÿr   N)Ú
__future__r   Ú__all__Úcollections.abcr   r   Úior   r	   Úosr
   Úpathlibr   Útypingr   r   r   Ú r   r   r   r   r   r   Úabcr   r   r   r"   r   r   r    r    r    r!   Ú<module>   s    	>