
    g                        d dl mZ d dlZd dlmZ d dlmZmZmZ d dl	m
Z
 d dlmZ erd dlmZ d dlmZ  G d	 d
e      Z G d de      Z G d de      Z G d dej*                        Z G d dee      Zy)    )annotationsN)abstractmethod)TYPE_CHECKING
NamedTupleProtocol)util)CacheStatsProvider)Sequence)FileURLsc                  :    e Zd ZU dZded<   ded<   ded<   ded<   y)	UploadedFileRecz7Metadata and raw bytes for an uploaded file. Immutable.strfile_idnametypebytesdataN__name__
__module____qualname____doc____annotations__     \/var/www/openai/venv/lib/python3.12/site-packages/streamlit/runtime/uploaded_file_manager.pyr   r      s    AL
I
I
Kr   r   c                  0    e Zd ZU dZded<   ded<   ded<   y)UploadFileUrlInfoz9Information we provide for single file in get_upload_urlsr   r   
upload_url
delete_urlNr   r   r   r   r   r   '   s    CLOOr   r   c                      e Zd ZU dZded<   y)DeletedFilea  Represents a deleted file in deserialized values for st.file_uploader and
    st.camera_input

    Return this from st.file_uploader and st.camera_input deserialize (so they can
    be used in session_state), when widget value contains file record that is missing
    from the storage.
    DeleteFile instances filtered out before return final value to the user in script,
    or before sending to frontend.r   r   Nr   r   r   r   r"   r"   /   s    & Lr   r"   c                  4     e Zd ZdZd fdZddZddZ xZS )UploadedFilezA mutable uploaded file.

    This class extends BytesIO, which has copy-on-write semantics when
    initialized with `bytes`.
    c                    t         |   |j                         |j                  | _        |j                  | _        |j
                  | _        t        |j                        | _        || _        y N)	super__init__r   r   r   r   lensize
_file_urls)selfrecord	file_urls	__class__s      r   r(   zUploadedFile.__init__C   sN    
 	%~~KK	KK	$	#r   c                `    t        |t              st        S | j                  |j                  k(  S r&   )
isinstancer$   NotImplementedr   )r,   others     r   __eq__zUploadedFile.__eq__O   s%    %.!!||u}},,r   c                ,    t        j                  |       S r&   )r   repr_)r,   s    r   __repr__zUploadedFile.__repr__T   s    zz$r   )r-   r   r.   FileURLsProto)r3   objectreturnbool)r:   r   )r   r   r   r   r(   r4   r7   __classcell__)r/   s   @r   r$   r$   <   s    
$-
 r   r$   c                  T    e Zd ZdZe	 	 	 	 	 	 dd       Zedd       Z	 	 	 	 	 	 ddZy)	UploadedFileManagera  UploadedFileManager protocol, that should be implemented by the concrete
    uploaded file managers.

    It is responsible for:
        - retrieving files by session_id and file_id for st.file_uploader and
            st.camera_input
        - cleaning up uploaded files associated with session on session end

    It should be created during Runtime initialization.

    Optionally UploadedFileManager could be responsible for issuing URLs which will be
    used by frontend to upload files to.
    c                    t         )a  Return a  list of UploadedFileRec for a given sequence of file_ids.

        Parameters
        ----------
        session_id
            The ID of the session that owns the files.
        file_ids
            The sequence of ids associated with files to retrieve.

        Returns
        -------
        List[UploadedFileRec]
            A list of URL UploadedFileRec instances, each instance contains information
            about uploaded file.
        NotImplementedError)r,   
session_idfile_idss      r   	get_fileszUploadedFileManager.get_filesg   
    & "!r   c                    t         )z1Remove all files associated with a given session.r@   )r,   rB   s     r   remove_session_filesz(UploadedFileManager.remove_session_files|   s
     "!r   c                    t         )a!  Return a list of UploadFileUrlInfo for a given sequence of file_names.
        Optional to implement, issuing of URLs could be done by other service.

        Parameters
        ----------
        session_id
            The ID of the session that request URLs.
        file_names
            The sequence of file names for which URLs are requested

        Returns
        -------
        List[UploadFileUrlInfo]
            A list of UploadFileUrlInfo instances, each instance contains information
            about uploaded file URLs.
        r@   )r,   rB   
file_namess      r   get_upload_urlsz#UploadedFileManager.get_upload_urls   rE   r   N)rB   r   rC   Sequence[str]r:   zlist[UploadedFileRec])rB   r   r:   None)rB   r   rI   rK   r:   zlist[UploadFileUrlInfo])r   r   r   r   r   rD   rG   rJ   r   r   r   r>   r>   X   sd     "")6"	" "( " """+8"	 "r   r>   )
__future__r   ioabcr   typingr   r   r   	streamlitr   streamlit.runtime.statsr	   collections.abcr
   streamlit.proto.Common_pb2r   r8   r   r   r"   BytesIOr$   r>   r   r   r   <module>rV      sh    # 	  6 6  6(Dj 
 
* 
 2::  8<",h <"r   