o
     d                     @   s   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
mZ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 )    )SEEK_SETUnsupportedOperation)PathLike)Path)AnyBinaryIOCallableDictMappingUnioncast   )BrokenResourceErrorClosedResourceErrorEndOfStreamTypedAttributeSet	to_threadtyped_attribute)ByteReceiveStreamByteSendStreamc                   @   s8   e Zd ZU e Zeed< e Zeed< e Z	e
ed< dS )FileStreamAttributefilepathfilenoN)__name__
__module____qualname__r   r   r   __annotations__r   r   r   int r   r   =/usr/local/lib/python3.10/dist-packages/anyio/streams/file.pyr      s   
 r   c                   @   sF   e Zd ZdefddZd
ddZedeee	g ef f fdd	Z
dS )_BaseFileStreamr   c                 C   s
   || _ d S N_file)selfr   r   r   r    __init__   s   
z_BaseFileStream.__init__returnNc                    s   t | jjI d H  d S r"   )r   run_syncr$   closer%   r   r   r    aclose   s   z_BaseFileStream.aclosec                    sj   t j fddi}t jdr fdd|t j< z j  W n
 ty)   Y |S w  fdd|t j< |S )Nc                      s    j S r"   r#   r   r*   r   r    <lambda>$   s    z2_BaseFileStream.extra_attributes.<locals>.<lambda>namec                      s   t  jjS r"   )r   r$   r-   r   r*   r   r    r,   (   s    c                      s
    j  S r"   )r$   r   r   r*   r   r    r,   /   s   
 )r   r   hasattrr$   r   r   r   )r%   
attributesr   r*   r    extra_attributes!   s   z _BaseFileStream.extra_attributes)r'   N)r   r   r   r   r&   r+   propertyr
   r   r   r0   r   r   r   r    r!      s
    
$r!   c                   @   sj   e Zd ZdZedeedf dd fddZddede	fd	d
Z
efdededefddZdefddZdS )FileReadStreamz
    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
    r   PathLike[str]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_path=   s   zFileReadStream.from_path   	max_bytesc              
      sZ   zt | jj|I d H }W n ty   td  ty& } zt|d }~ww |r+|S tr"   )	r   r(   r$   read
ValueErrorr   OSErrorr   r   )r%   r:   dataexcr   r   r    receiveH   s   zFileReadStream.receivepositionwhencec                    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%   rA   rB   r   r   r    rC   U   s   zFileReadStream.seekc                    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    rD   e   s   
zFileReadStream.tellN)r9   )r   r   r   __doc__classmethodr   strr8   r   bytesr@   r   rC   rD   r   r   r   r    r2   4   s    
r2   c                   @   sH   e Zd ZdZe	ddeedf dedd fddZd	e	dd
fddZ
d
S )FileWriteStreamz
    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
    Fr   r3   appendr'   c                    s4   |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wbNr5   )r7   r   rJ   moder   r   r   r    r8   {   s   zFileWriteStream.from_pathitemNc              
      sP   zt | jj|I d H  W d S  ty   td  ty' } zt|d }~ww r"   )r   r(   r$   writer<   r   r=   r   )r%   rN   r?   r   r   r    send   s   zFileWriteStream.send)F)r   r   r   rE   rF   r   rG   boolr8   rH   rP   r   r   r   r    rI   r   s    
rI   N)ior   r   osr   pathlibr   typingr   r   r   r	   r
   r   r    r   r   r   r   r   r   abcr   r   r   r!   r2   rI   r   r   r   r    <module>   s    $ 	>