
    &e                         U d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ  G d de          Zd	e	d
efdZd	e	d
efdZdaee         ed<   d
efdZdS )z!Runtime-related utility functions    )AnyOptional)config)MarkdownFormattedException)
ForwardMsg)populate_hash_if_neededc                   8     e Zd ZdZdef fdZdedefdZ xZS )MessageSizeErrorzNException raised when a websocket message is larger than the configured limit.failed_msg_strc                     |                      |          }t          t          |                               |           d S )N)_get_messagesuperr
   __init__)selfr   msg	__class__s      >lib/python3.11/site-packages/streamlit/runtime/runtime_util.pyr   zMessageSizeError.__init__   s;    //%%..s33333    returnc                     d                     t          |          dz  t                      dz                                d          S )Na@  
**Data of size {message_size_mb:.1f} MB exceeds the message size limit of {message_size_limit_mb} 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/library/advanced-features/configuration#set-configuration-options).

_Note that increasing the limit may lead to long loading times and large memory consumption
of the client's browser and the Streamlit server._
    .A)message_size_mbmessage_size_limit_mb
)formatlenget_max_message_size_bytesstrip)r   r   s     r   r   zMessageSizeError._get_message    sM    	 V #N 3 3c 9'A'C'Cc'I    U4[[#	
r   )	__name__
__module____qualname____doc__r   r   strr   __classcell__)r   s   @r   r
   r
      sl        XX4s 4 4 4 4 4 4
3 
3 
 
 
 
 
 
 
 
r   r
   r   r   c                     |                      d          dv rdS |                                 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_msgr-   7   sF    
~~f!;;;u<<>>S!23P!Q!QRRRRr   c                 (   t          |            |                                 }t          |          t                      k    rOddlmc m} |                    | j        j	        j        t          |                     |                                 }|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_strr2   s      r   serialize_forward_msgr7   ?   s     C   ##%%G
7||02222888888888 	390:<LW<U<UVVV''))Nr   N_max_message_size_bytesc                  f    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.
    Nzserver.maxMessageSizer   )r8   r   r,   r+    r   r   r   r   X   s.     &"("34K"L"LsSVxx"W""r   )r"   typingr   r   	streamlitr   streamlit.errorsr   streamlit.proto.ForwardMsg_pb2r   #streamlit.runtime.forward_msg_cacher   r
   boolr-   bytesr7   r8   r+   __annotations__r   r:   r   r   <module>rC      s!   ( ' '                       7 7 7 7 7 7 5 5 5 5 5 5 G G G G G G
 
 
 
 
1 
 
 
<S* S S S S Sz e    , *. # - - -
#C 
# 
# 
# 
# 
# 
#r   