
    /_i                        U d Z ddlmZ ddlmZ ddlmZmZmZm	Z	 ddl
mZ ddlmZmZ erddlmZ  ee      Zded	<    G d
 de      Z G d de      ZddZdaded<   ddZy)z"Runtime-related utility functions.    )annotations)	getLogger)TYPE_CHECKINGAnyFinalcast)config)MarkdownFormattedExceptionStreamlitAPIException)
ForwardMsgr   _LOGGERc                  ,     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      ]/var/www/html/land_sniper/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)#. /# $ %
 %+	r   )r   r   returnNone)r   r   r    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__:   s#    "++::BE	
r   N)r+   r"   r    r!   )r#   r$   r%   r&   r    r   r   r)   r)   7   s
    ?
r   r)   c                B   | j                         }t        |      t               kD  rxddlm} t        |      }t        j                  d|       |j                  | j                  j                  j                  |       d| j                  _        | 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   )	exceptionzDWebsocket message size limit exceeded. Showing error to the user: %sF)SerializeToStringr   r   streamlit.elementsr.   r   r   warningmarshalldeltanew_elementmetadata	cacheable)r   msg_strr.   msg_size_errors       r   serialize_forward_msgr9   B   s     ##%G
7|022 	1)'2R	
 	39900::NK!&'')Nr   Nz
int | None_max_message_size_bytesc                 p    t         !t        j                  d      t        d      z  a t	        d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   int)r:   r	   
get_optionr<   r   r,   r   r   r   r   b   s4     &"("3"34K"LsSVx"W.//r   )r   r   r    bytes)r    r<   )r&   
__future__r   loggingr   typingr   r   r   r   	streamlitr	   streamlit.errorsr
   r   streamlit.proto.ForwardMsg_pb2r   r#   r   __annotations__r   r)   r9   r:   r   r,   r   r   <module>rF      sb    ) "  2 2  N98$ $1 0
2 
: '+  *
0r   