o
    沪g|,                     @  sl   d Z ddlmZ ddlZddlZddlZddlmZmZ ddl	m
Z
 ddlmZ G dd dZdddZdS )z6Class to store a key-value pair for the config system.    )annotationsN)AnyCallable)to_snake_caserepr_c                
   @  s|   e Zd ZdZdZdZddddddddedf
d,ddZd-ddZd.ddZ	e
d/d!d"Zd0d1d&d'Zd2d(d)Ze
d*d+ ZdS )3ConfigOptiona:  Stores a Streamlit configuration option.

    A configuration option, like 'browser.serverPort', which indicates which port
    to use when connecting to the proxy. There are two ways to create a
    ConfigOption:

    Simple ConfigOptions are created as follows:

        ConfigOption('browser.serverPort',
            description = 'Connect to the proxy at this port.',
            default_val = 8501)

    More complex config options resolve their values at runtime as follows:

        @ConfigOption('browser.serverPort')
        def _proxy_port():
            """Connect to the proxy at this port.

            Defaults to 8501.
            """
            return 8501

    NOTE: For complex config options, the function is called each time the
    option.value is evaluated!

    Attributes
    ----------
    key : str
        The fully qualified section.name
    value : any
        The value for this option. If this is a complex config option then
        the callback is called EACH TIME value is evaluated.
    section : str
        The section of this option. Example: 'global'.
    name : str
        See __init__.
    description : str
        See __init__.
    where_defined : str
        Indicates which file set this config option.
        ConfigOption.DEFAULT_DEFINITION means this file.
    is_default: bool
        True if the config value is equal to its default value.
    visibility : {"visible", "hidden"}
        See __init__.
    scriptable : bool
        See __init__.
    deprecated: bool
        See __init__.
    deprecation_text : str or None
        See __init__.
    expiration_date : str or None
        See __init__.
    replaced_by : str or None
        See __init__.
    sensitive : bool
        See __init__.
    env_var: str
        The name of the environment variable that can be used to set the option.
    z	<default>z<streamlit>NvisibleFkeystrdescription
str | Nonedefault_val
Any | None
visibility
scriptablebool
deprecateddeprecation_textexpiration_datereplaced_bytype_type	sensitivec                 C  s   || _ d}t|| j }|sJ d| j  d|d|d| _| _|| _|| _|| _|| _	|| _
|	| _d| _d| _tj| _|
| _|| _t|ttf| _| jr]d| _
|du r]d| j }| j
ru|sfJ d	|slJ d
|| _t|| _| | dS )a.  Create a ConfigOption with the given name.

        Parameters
        ----------
        key : str
            Should be of the form "section.optionName"
            Examples: server.name, deprecation.v1_0_featureName
        description : str
            Like a comment for the config option.
        default_val : any
            The value for this config option.
        visibility : {"visible", "hidden"}
            Whether this option should be shown to users.
        scriptable : bool
            Whether this config option can be set within a user script.
        deprecated: bool
            Whether this config option is deprecated.
        deprecation_text : str or None
            Required if deprecated == True. Set this to a string explaining
            what to use instead.
        expiration_date : str or None
            Required if deprecated == True. set this to the date at which it
            will no longer be accepted. Format: 'YYYY-MM-DD'.
        replaced_by : str or None
            If this is option has been deprecated in favor or another option,
            set this to the path to the new option. Example:
            'server.runOnSave'. If this is set, the 'deprecated' option
            will automatically be set to True, and deprecation_text will have a
            meaningful default (unless you override it).
        type_ : one of str, int, float or bool
            Useful to cast the config params sent by cmd option parameter.
        sensitive: bool
            Sensitive configuration options cannot be set by CLI parameter.
        z?(?P<section>\_?[a-z][a-zA-Z0-9]*)\.(?P<name>[a-z][a-zA-Z0-9]*)$zKey "z" has invalid format.sectionnameTNzReplaced by %s.z0expiration_date is required for deprecated itemsz1deprecation_text is required for deprecated items)r
   rematchgroupr   r   r   r   r   r   r   r   
is_default_get_val_funcr   DEFAULT_DEFINITIONwhere_definedr   r   
isinstancelisttuplemultipler   textwrapdedentr   	set_value)selfr
   r   r   r   r   r   r   r   r   r   r   
key_formatr    r,   S/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/streamlit/config_option.py__init__b   s8   1
zConfigOption.__init__returnc                 C  s   t | S Nr   r*   r,   r,   r-   __repr__   s   zConfigOption.__repr__get_val_funcCallable[[], Any]c                 C  s    |j sJ d|j | _|| _| S )a  Assign a function to compute the value for this option.

        This method is called when ConfigOption is used as a decorator.

        Parameters
        ----------
        get_val_func : function
            A function which will be called to get the value of this parameter.
            We will use its docString as the description.

        Returns
        -------
        ConfigOption
            Returns self, which makes testing easier. See config_test.py.

        zAComplex config options require doc strings for their description.)__doc__r   r    )r*   r3   r,   r,   r-   __call__   s   zConfigOption.__call__r   c                 C  s   | j du rdS |   S )z$Get the value of this config option.N)r    r1   r,   r,   r-   value   s   
zConfigOption.valuer7   r"   Nonec                   s    fdd| _ |du rtj| _n|| _ | jk| _| jrl| jtjkrn|  rGddlm	} |t
}|td| j d| j d| j d	 dS ddlm	} |t
}|td
| j d| j d| j d| j d		 dS dS dS )zSet the value of this option.

        Parameters
        ----------
        value
            The new value for this parameter.
        where_defined : str
            New value to remember where this parameter was set.

        c                     s    S r0   r,   r,   r7   r,   r-   <lambda>   s    z(ConfigOption.set_value.<locals>.<lambda>Nr   )
get_loggeru   
                    ════════════════════════════════════════════════
                    z. IS NO LONGER SUPPORTED.

                    z$

                    Please update u   .
                    ════════════════════════════════════════════════
                    u   s
                    ════════════════════════════════════════════════
                    z$ IS DEPRECATED.
                    z>

                    This option will be removed on or after z%.

                    Please update )r    r   r!   r"   r   r   r   
is_expiredstreamlit.loggerr;   __name__errorr'   r(   r
   r   warningr   )r*   r7   r"   r;   LOGGERr,   r9   r-   r)      sH   
zConfigOption.set_valuec                 C  s&   | j sdS t| j}tj }||kS )z/Returns true if expiration_date is in the past.F)r   _parse_yyyymmdd_strr   datetimenow)r*   r   rD   r,   r,   r-   r<   #  s
   

zConfigOption.is_expiredc                 C  s    | j dd}dt|  S )z^
        Get the name of the environment variable that can be used to set the option.
        ._
STREAMLIT_)r
   replacer   upper)r*   r   r,   r,   r-   env_var,  s   zConfigOption.env_var)r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r/   r   )r3   r4   r/   r   )r/   r   r0   )r7   r   r"   r   r/   r8   )r/   r   )r>   
__module____qualname__r5   r!   STREAMLIT_DEFINITIONr   r.   r2   r6   propertyr7   r)   r<   rJ   r,   r,   r,   r-   r      s.    ?
d

;	r   date_strr   r/   datetime.datetimec                 C  s*   dd |  ddD \}}}t|||S )Nc                 s  s    | ]}t |V  qd S r0   )int).0tokenr,   r,   r-   	<genexpr>6  s    z&_parse_yyyymmdd_str.<locals>.<genexpr>-   )splitrC   )rO   yearmonthdayr,   r,   r-   rB   5  s   rB   )rO   r   r/   rP   )r5   
__future__r   rC   r   r'   typingr   r   streamlit.string_utilr   streamlit.utilr   r   rB   r,   r,   r,   r-   <module>   s     