o
    +iv                     @  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    E/var/www/html/venv/lib/python3.10/site-packages/anyio/streams/file.pyr      s   
 r   c                   @  s.   e Zd ZdddZdddZedd
dZdS )_BaseFileStreamr   r   c                 C  s
   || _ d S N_file)selfr   r    r    r!   __init__$   s   
z_BaseFileStream.__init__returnNonec                   s   t | jjI d H  d S r#   )r   run_syncr%   closer&   r    r    r!   aclose'   s   z_BaseFileStream.acloseMapping[Any, Callable[[], Any]]c                   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%   r0   r    r,   r    r!   r/   1   s    c                     s
    j  S r#   )r%   r   r    r,   r    r!   r/   8   s   
 )r   r   hasattrr%   r   r   r	   )r&   
attributesr    r,   r!   extra_attributes*   s   z _BaseFileStream.extra_attributesN)r   r   )r(   r)   )r(   r.   )r   r   r   r'   r-   propertyr3   r    r    r    r!   r"   #   s
    

r"   c                   @  sB   e Zd ZdZedddZddddZefdddZ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
    r   str | 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_pathF   s   zFileReadStream.from_path   	max_bytesr   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!   receiveQ   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&   rD   rE   r    r    r!   rF   ^   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!   rG   n   s   
zFileReadStream.tellN)r   r5   r(   r   )r;   )r<   r   r(   r=   )rD   r   rE   r   r(   r   )r(   r   )
r   r   r   __doc__classmethodr:   rC   r   rF   rG   r    r    r    r!   r   =   s    
r   c                   @  s,   e Zd ZdZe	dddd	Z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
    Fr   r5   appendboolr(   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wbNr7   )r9   r   rJ   moder   r    r    r!   r:      s   zFileWriteStream.from_pathitemr=   r)   c              
     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&   rO   rB   r    r    r!   send   s   zFileWriteStream.sendN)F)r   r5   rJ   rK   r(   r   )rO   r=   r(   r)   )r   r   r   rH   rI   r:   rQ   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     	>