
    g                        d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
mZ d dlmZmZmZ erd dlmZ  G d	 d
e      Zy)    )annotationsN)defaultdict)TYPE_CHECKING)util)	CacheStatgroup_stats)UploadedFileManagerUploadedFileRecUploadFileUrlInfo)Sequencec                  r    e Zd ZdZddZ	 	 	 	 	 	 ddZddZddZ	 	 	 	 	 	 ddZd Z		 	 	 	 	 	 ddZ
dd	Zy
)MemoryUploadedFileManagerzHolds files uploaded by users of the running Streamlit app.
    This class can be used safely from multiple threads simultaneously.
    c                :    t        t              | _        || _        y N)r   dictfile_storageendpoint)selfupload_endpoints     c/var/www/openai/venv/lib/python3.12/site-packages/streamlit/runtime/memory_uploaded_file_manager.py__init__z"MemoryUploadedFileManager.__init__&   s    CNtCT'    c                    | j                   |   }g }|D ](  }|j                  |d      }||j                  |       * |S )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.
        N)r   getappend)r   
session_idfile_idssession_storage	file_recsfile_idfile_recs          r   	get_filesz#MemoryUploadedFileManager.get_files*   sQ    $ ++J7	G&**7D9H#  *  
 r   c                <    | j                   j                  |d       y)z1Remove all files associated with a given session.Nr   pop)r   r   s     r   remove_session_filesz.MemoryUploadedFileManager.remove_session_filesF   s    j$/r   c                ,    t        j                  |       S r   )r   repr_)r   s    r   __repr__z"MemoryUploadedFileManager.__repr__J   s    zz$r   c                <    || j                   |   |j                  <   y)z
        Safe to call from any thread.

        Parameters
        ----------
        session_id
            The ID of the session that owns the file.
        file
            The file to add.
        N)r   r    )r   r   files      r   add_filez"MemoryUploadedFileManager.add_fileM   s      7;*%dll3r   c                F    | j                   |   }|j                  |d       y)z?Remove file with given file_id associated with a given session.Nr$   )r   r   r    r   s       r   remove_filez%MemoryUploadedFileManager.remove_file_   s"    ++J7GT*r   c                    g }|D ]`  }t        t        j                               }|j                  t	        || j
                   d| d| | j
                   d| d|              b |S )zFReturn a list of UploadFileUrlInfo for a given sequence of file_names./)r    
upload_url
delete_url)struuiduuid4r   r   r   )r   r   
file_namesresult_r    s         r   get_upload_urlsz)MemoryUploadedFileManager.get_upload_urlsd   sq     A$**,'GMM!#"&--*QwiH"&--*QwiH  r   c           
        g }| j                   j                         }|j                         D ]!  }|j                  |j                                # |D cg c]#  }t	        ddt        |j                              % }}t        |      S c c}w )zPReturn the manager's CacheStats.

        Safe to call from any thread.
        r	    )category_name
cache_namebyte_length)r   copyvaluesextendr   lendatar   )r   	all_filesfile_storage_copyr   r+   statss         r   	get_statsz#MemoryUploadedFileManager.get_statst   s     ,.	 !--2240779O_3356  : ""
 " 3		N
 " 	 "
 5!!"
s   (B
N)r   r3   )r   r3   r   Sequence[str]returnzlist[UploadedFileRec])r   r3   rI   None)rI   r3   )r   r3   r+   r
   rI   rJ   )r   r3   r6   rH   rI   zlist[UploadFileUrlInfo])rI   zlist[CacheStat])__name__
__module____qualname____doc__r   r"   r&   r)   r,   r.   r9   rG    r   r   r   r   !   s{    ()6	80 ;; ; 
	;$+
+8	  "r   r   )
__future__r   r4   collectionsr   typingr   	streamlitr   streamlit.runtime.statsr   r   'streamlit.runtime.uploaded_file_managerr	   r
   r   collections.abcr   r   rO   r   r   <module>rW      s:    #  #    :  (i" 3 i"r   