o
    QDi                     @  s^   d dl mZ d dlZddlmZmZ ddlmZ ddlm	Z	 G dd de	Z
G d	d
 d
ZdS )    )annotationsN   )errorstypes)FrictionlessException)Loaderc                   @  s"   e Zd ZdZdd Zd	ddZdS )
StreamLoaderzStream loader implementation.c                 C  s   | j j}tj|jsd| }ttj|dt	|dr:zt
|jd}W n ty9   d| }ttj|dw t|}|S )Nz"only local streams are supported: noteencodingrbz'cannot open a stream in the byte mode: )resourcedataospathisfilenamer   r   SchemeErrorhasattropen	ExceptionReusableByteStream)selfbyte_streamr
    r   [/var/www/Datamplify/venv/lib/python3.10/site-packages/frictionless/schemes/stream/loader.pyread_byte_stream_create   s   


z$StreamLoader.read_byte_stream_creater   types.IByteStreamc                 C  s   || j _d S N)r   r   r   r   r   r   r   write_byte_stream_save      z#StreamLoader.write_byte_stream_saveNr   r   )__name__
__module____qualname____doc__r   r    r   r   r   r   r   
   s    r   c                   @  s,   e Zd ZdddZdddZddddZdS )r   r   r   c                 C  s
   || _ d S r   ) _ReusableByteStream__byte_streamr   r   r   r   __init__'   s   
zReusableByteStream.__init__r   strc                 C  s   t | j|S r   )getattrr'   )r   r   r   r   r   __getattr__*   r!   zReusableByteStream.__getattr__sizeintc                 C  sL   | j jr z
t| j jd| _ W n ty   d}ttj|dw | j |S )Nr   z2cannot re-open a byte stream: {self.__byte_stream}r	   )	r'   closedr   r   r   r   r   r   read)r   r-   r
   r   r   r   r0   -   s   zReusableByteStream.readNr"   )r   r)   )r,   )r-   r.   )r#   r$   r%   r(   r+   r0   r   r   r   r   r   &   s    

r   )
__future__r   r    r   r   	exceptionr   systemr   r   r   r   r   r   r   <module>   s    