
    g                        U d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	m
Z
 ddlmZ erddlmZ  G d d	e	      Z G d
 de
      ZddZddZdaded<   ddZy)z!Runtime-related utility functions    )annotations)TYPE_CHECKINGAny)config)MarkdownFormattedExceptionStreamlitAPIException)populate_hash_if_needed)
ForwardMsgc                  ,     e Zd ZdZd fdZddZ xZS )MessageSizeErrorzNException raised when a websocket message is larger than the configured limit.c                F    | j                  |      }t        | 	  |       y )N)_get_messagesuper__init__)selffailed_msg_strmsg	__class__s      S/var/www/openai/venv/lib/python3.12/site-packages/streamlit/runtime/runtime_util.pyr   zMessageSizeError.__init__    s     /    c                b    dt        |      dz  ddt               dz   dj                  d      S )Nz
**Data of size     .Az.1fz& MB exceeds the message size limit of a   MB.**

This is often caused by a large chart or dataframe. Please decrease the amount of data sent
to the browser, or increase the limit by setting the config option `server.maxMessageSize`.
[Click here to learn more about config options](https://docs.streamlit.io/develop/api-reference/configuration/config.toml).

_Note that increasing the limit may lead to long loading times and large memory consumption
of the client's browser and the Streamlit server._

)lenget_max_message_size_bytesstrip)r   r   s     r   r   zMessageSizeError._get_message$   sF    N#c)#..TUoUqtwUwTx y	 %+	r   )r   r   )r   r   returnstr)__name__
__module____qualname____doc__r   r   __classcell__)r   s   @r   r   r      s    Xr   r   c                      e Zd ZdZddZy)BadDurationStringErrorz5Raised when a bad duration argument string is passed.c                6    t        j                  | d|        y )NzcTTL string doesn't look right. It should be formatted as`'1d2h34m'` or `2 days`, for example. Got: )r   r   )r   durations     r   r   zBadDurationStringError.__init__7   s#    "++::BE	
r   N)r'   r   )r   r    r!   r"   r    r   r   r%   r%   4   s
    ?
r   r%   c                    | j                  d      dv ry| j                         t        t        j                  d            k\  S )z0True if the given message qualifies for caching.type>   ref_hash
initializeFzglobal.minCachedMessageSize)
WhichOneofByteSizeintr   
get_option)r   s    r   is_cacheable_msgr1   ?   s9    
~~f!;;<<>S!2!23P!QRRRr   c                   t        |        | j                         }t        |      t               kD  rRddlmc m} |j                  | j                  j                  j                  t        |             | j                         }|S )zSerialize a ForwardMsg to send to a client.

    If the message is too large, it will be converted to an exception message
    instead.
    r   N)r	   SerializeToStringr   r   streamlit.elements.exceptionelements	exceptionmarshalldeltanew_elementr   )r   msg_strr6   s      r   serialize_forward_msgr;   G   sk     C ##%G
7|02288 	39900::<LW<UV'')Nr   Nz
int | None_max_message_size_bytesc                 \    t         !t        j                  d      t        d      z  a t         S )zReturns the max websocket message size in bytes.

    This will lazyload the value from the config and store it in the global symbol table.
    zserver.maxMessageSizer   )r<   r   r0   r/   r(   r   r   r   r   `   s,     &"("3"34K"LsSVx"W""r   )r   r
   r   bool)r   r
   r   bytes)r   r/   )r"   
__future__r   typingr   r   	streamlitr   streamlit.errorsr   r   #streamlit.runtime.forward_msg_cacher	   streamlit.proto.ForwardMsg_pb2r
   r   r%   r1   r;   r<   __annotations__r   r(   r   r   <module>rG      sV    ( " %  N G91 .
2 
S, '+  *
#r   