
    %ed,                         d Z ddlZddlZddlZddlmZmZmZ ddlm	Z	 ddl
mZ ddlmZ  G d d          Zd	ed
ej        fdZdS )z6Class to store a key-value pair for the config system.    N)AnyCallableOptional)util)to_snake_case)DeprecationErrorc                   ,   e Zd ZdZdZdZddddddddedf
dedee         d	ee         d
ede	de	dee         dee         dee         de
de	fdZdefdZdeg ef         dd fdZedefd            Zddedee         ddfdZde	fdZed             ZdS )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descriptiondefault_val
visibility
scriptable
deprecateddeprecation_textexpiration_datereplaced_bytype_	sensitivec                 j   || _         d}t          j        || j                   }|sJ d| j          d            |                    d          |                    d          c| _        | _        || _        || _        || _        || _	        || _
        |	| _        d| _        d| _        t          j        | _        |
| _        || _        | j        rd| _
        |
d| j        z  }| j
        r8|s
J d	            |s
J d
            || _        t)          j        |          | _        |                     |           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_definedtyper   r   textwrapdedentr   	set_value)selfr   r   r   r   r   r   r   r   r   r   r   
key_formatr   s                 7lib/python3.11/site-packages/streamlit/config_option.py__init__zConfigOption.__init__a   sY   b  	$ TX..===dh======"'++i"8"8%++f:M:Mdi&$$&$&:>)<	" 	H"DO'#4t7G#G ? 	F"VV$VVVV#XX%XXXX#2D $,O4D$E$ED!{#####    returnc                 *    t          j        |           S N)r   repr_r%   s    r'   __repr__zConfigOption.__repr__   s    z$r)   get_val_funcc                 N    |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%   r0   s     r'   __call__zConfigOption.__call__   sE    $  	O 	ON	O 	O 	O (/)r)   c                 <    | j         dS |                                  S )z$Get the value of this config option.N)r   r.   s    r'   valuezConfigOption.value   s$     %4!!###r)   r5   r    c                    fd| _         |t          j        | _        n|| _        | j        k    | _        | j        r| j        t          j        k    r| j        | j        | j        | j	        d}| 
                                r$t          t          j        d          |z            ddlm}  |t                     }|                    t          j        d          |z             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 r,    )r5   s   r'   <lambda>z(ConfigOption.set_value.<locals>.<lambda>   s    U r)   N)r   fileexplanationdateu  
                    ════════════════════════════════════════════════
                    %(key)s IS NO LONGER SUPPORTED.

                    %(explanation)s

                    Please update %(file)s.
                    ════════════════════════════════════════════════
                    r   )
get_loggeru"  
                    ════════════════════════════════════════════════
                    %(key)s IS DEPRECATED.
                    %(explanation)s

                    This option will be removed on or after %(date)s.

                    Please update %(file)s.
                    ════════════════════════════════════════════════
                    )r   r
   r   r    r   r   r   r   r   r   
is_expiredr   r"   r#   streamlit.loggerr=   __name__warning)r%   r5   r    detailsr=   LOGGERs    `    r'   r$   zConfigOption.set_value   s2    +]]] !-!@D!.D4#33? +	t1\5TTT x*#4,	 G    "&O
 
     877777#H--O	      ;+	 +	TTr)   c                     | 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   rG   s      r'   r>   zConfigOption.is_expired&  s@     	5-d.BCC##%%_$$r)   c                     | 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   s     r'   env_varzConfigOption.env_var/  s=    
 xS))9M$//5577999r)   r,   )r@   
__module____qualname__r2   r   STREAMLIT_DEFINITIONstrr   r   boolr!   r(   r/   r   r3   propertyr5   r$   r>   rN   r8   r)   r'   r
   r
      s       ; ;~ % )
 &*%)#  *.)-%)`$ `$`$ c]`$ c]	`$
 `$ `$ `$ #3-`$ "#`$ c]`$ `$ `$ `$ `$ `$D #        Xb#g%6 >    0 $s $ $ $ X$? ?s ?8C= ?D ? ? ? ?B%D % % % % : : X: : :r)   r
   date_strr*   c                 v    d |                      dd          D             \  }}}t          j        |||          S )Nc                 ,    g | ]}t          |          S r8   )int).0tokens     r'   
<listcomp>z'_parse_yyyymmdd_str.<locals>.<listcomp>9  s    GGGuE

GGGr)   -   )splitrF   )rU   yearmonthdays       r'   rE   rE   8  s?    GGsA0F0FGGGD%T5#...r)   )r2   rF   r   r"   typingr   r   r   	streamlitr   streamlit.case_convertersr   streamlit.errorsr   r
   rR   rE   r8   r)   r'   <module>rf      s    = <  				  * * * * * * * * * *       3 3 3 3 3 3 - - - - - -Z: Z: Z: Z: Z: Z: Z: Z:z/# /(*; / / / / / /r)   