o
    h                     @  s   d dl m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)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 )FileStreamAttributer
   filer   pathintfilenoN)__name__
__module____qualname__r   r   __annotations__r   r    r   r   f/var/www/html/construction_image-detection-poc/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#   r.   r   r*   r   r   r-   +   s    c                     s
    j  S r!   )r#   r   r   r*   r   r   r-   2   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+   propertyr1   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 )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   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_path@   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   receiveK   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$   rC   rD   r   r   r   rE   X   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   rF   h   s   
zFileReadStream.tellN)r   r4   r&   r3   )r:   )r;   r   r&   r<   )rC   r   rD   r   r&   r   )r&   r   )
r   r   r   __doc__classmethodr9   rB   r   rE   rF   r   r   r   r   r3   7   s    
r3   c                   @  s,   e Zd ZdZe	dddd	Zd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   r4   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wbNr6   )r8   r   rJ   moder   r   r   r   r9   ~   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   rA   r   r   r   send   s   zFileWriteStream.sendN)F)r   r4   rJ   rK   r&   rI   )rO   r<   r&   r'   )r   r   r   rG   rH   r9   rQ   r   r   r   r   rI   u   s    rI   N)
__future__r   collections.abcr   r   ior   r   osr   pathlibr   typingr	   r
   r    r   r   r   r   r   r   abcr   r   r   r    r3   rI   r   r   r   r   <module>   s     	>