o
    h                     @  s   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	 d	e	ZG d
d de
ZdddZdddZdaded< dddZdS )z"Runtime-related utility functions.    )annotations)TYPE_CHECKINGAny)config)MarkdownFormattedExceptionStreamlitAPIException)populate_hash_if_needed)
ForwardMsgc                      s,   e Zd ZdZd
 fddZddd	Z  ZS )MessageSizeErrorzNException raised when a websocket message is larger than the configured limit.failed_msg_strr   c                   s   |  |}t | d S )N)_get_messagesuper__init__)selfr   msg	__class__ R/var/www/vscode/kcb/lib/python3.10/site-packages/streamlit/runtime/runtime_util.pyr       s   
zMessageSizeError.__init__returnstrc                 C  s(   dt |d ddt d  d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   r   r   r   r   $   s   

zMessageSizeError._get_message)r   r   )r   r   r   r   )__name__
__module____qualname____doc__r   r   __classcell__r   r   r   r   r
      s    r
   c                   @  s   e Zd ZdZdddZdS )BadDurationStringErrorz5Raised when a bad duration argument string is passed.durationr   c                 C  s   t | d|  d S )NzcTTL string doesn't look right. It should be formatted as`'1d2h34m'` or `2 days`, for example. Got: )r   r   )r   r"   r   r   r   r   7   s   zBadDurationStringError.__init__N)r"   r   )r   r   r   r   r   r   r   r   r   r!   4   s    r!   r   r	   r   boolc                 C  s(   |  ddv r	dS |  ttdkS )z0True if the given message qualifies for caching.type>   ref_hash
initializeFzglobal.minCachedMessageSize)
WhichOneofByteSizeintr   
get_option)r   r   r   r   is_cacheable_msg?   s   r+   bytesc                 C  sR   t |  |  }t|t kr'ddlm  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_strr0   r   r   r   serialize_forward_msgG   s   r5   Nz
int | None_max_message_size_bytesr)   c                   C  s   t du rtdtd 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   )r6   r   r*   r)   r   r   r   r   r   `   s   r   )r   r	   r   r#   )r   r	   r   r,   )r   r)   )r   
__future__r   typingr   r   	streamlitr   streamlit.errorsr   r   #streamlit.runtime.forward_msg_cacher   streamlit.proto.ForwardMsg_pb2r	   r
   r!   r+   r5   r6   __annotations__r   r   r   r   r   <module>   s   

