U
    &%e                     @  s   d dl 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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)SEEK_SETUnsupportedOperation)PathLike)Path)AnyBinaryIOCallableMapping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   Q/var/www/html/Darija-Ai-API/env/lib/python3.8/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                   sj   t j fddi}t jdr0 fdd|t j< z j  W n tk
rR   Y nX  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#   r/   r   r+   r   r   r-   *   r.   c                     s
    j  S r!   )r#   r   r   r+   r   r   r-   1   r.   )r   r   hasattrr#   r   r   r   )r$   
attributesr   r+   r   extra_attributes#   s     
z _BaseFileStream.extra_attributesN)r   r   r   r%   r,   propertyr2   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 )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
    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_path?   s    zFileReadStream.from_path   r   bytes)	max_bytesr(   c              
     sl   zt | jj|I d H }W n@ tk
r4   td Y n( tk
rZ } z
t|W 5 d }~X Y nX |rd|S td S r!   )	r   r)   r#   read
ValueErrorr   OSErrorr   r   )r$   r=   dataexcr   r   r   receiveJ   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$   rD   rE   r   r   r   rF   W   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   rG   g   s    
zFileReadStream.tellN)r;   )
r   r   r   __doc__classmethodr:   rC   r   rF   rG   r   r   r   r   r4   6   s   
r4   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 )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
    Fr5   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wbNr7   )r9   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k
r4   td Y n( tk
rZ } z
t|W 5 d }~X Y nX d S r!   )r   r)   r#   writer?   r   r@   r   )r$   rP   rB   r   r   r   send   s    
zFileWriteStream.sendN)F)r   r   r   rH   rI   r:   rR   r   r   r   r   rJ   t   s
    rJ   N)
__future__r   ior   r   osr   pathlibr   typingr   r   r	   r
   r    r   r   r   r   r   r   abcr   r   r   r    r4   rJ   r   r   r   r   <module>   s    	>