
    /_ix                       d dl mZ d dlZd dlZd dlZd dlZd dlZd dlm	Z	m
Z
 e	rd dlmZ d dlmZmZ d dlmZ d dlmZ d dlmZmZmZ d	Zdd
Z	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZddZddZd dZ	 	 	 	 d!dZ	 	 	 	 d"dZ 	 	 	 	 d#dZ!	 d$	 	 	 	 	 	 	 	 	 d%dZ"	 d&	 	 	 	 	 	 	 	 	 	 	 	 	 d'dZ#	 	 	 	 	 	 	 	 d(dZ$	 	 	 	 	 	 d)dZ%	 	 	 	 	 	 d*dZ&	 	 	 	 	 	 d+dZ'	 	 	 	 	 	 	 	 	 	 d,dZ(	 	 	 	 	 	 	 	 d-dZ)y).    )annotationsN)TYPE_CHECKINGAny)Iterator)cli_utilurl_util)ConfigOption)is_css_color_like)StreamlitInvalidThemeError StreamlitInvalidThemeOptionError!StreamlitInvalidThemeSectionErrori   c                 &    ddl m}   | t              S )zHGet logger for this module. Separate function to avoid circular imports.r   
get_logger)streamlit.loggerr   __name__r   s    T/var/www/html/land_sniper/venv/lib/python3.12/site-packages/streamlit/config_util.py_get_loggerr   )   s    +h    c                    | j                         D ]9  \  }}|j                  d      s|j                  }||   j                  }||k7  s9 y y)zpReturn True if and only if an option in the server section differs
    between old_options and new_options.
    serverTFitems
startswithvalue)old_optionsnew_optionsopt_nameopt_valold_valnew_vals         r   server_option_changedr"   0   s[     )..0 '""8,--h'--g r   c                ~   g j                  t        d             dfd}dfd}dfd}dfd}| D ]  }|dk(  r
|j                         D ci c]6  \  }}|j                  |k(  r"|j                  dk(  r|j                         s||8 }	}}t        |	      dk(  rjj                  d	        |d
| d       j                  d	       |	j                         D ]-  }
|
j                  j                  d      d   }t        |
j                  xs d	      }t        |      dz
  }t        |      D ]r  \  }}|j                         j                  d      }|r|d   j                         s|dd }|dk(  r|n|}|D ]  } ||j                                 ||k7  sk |d	       t |
j                   rud   dk7  r |d	        |t#        j$                  dd              |d	       t        |
j&                        D ]
  } ||         |d	        |d|
j(                   d       ddl}|j-                  d|
j.                  i      }|dd j                         }t        |      dkD  rd   dk7  r |d	        |d|        n	 |
j0                  t2        j4                  k7  }|r%d   dk7  r |d	        |d|
j0                          |j-                  ||
j6                  i      }t        |      dk(  rd| d}n|sd| } ||       0  t#        j8                  dj;                               yc c}}w )z8Print the given config sections/options to the terminal.zh
        # Below are all the sections and options you can have in
        ~/.streamlit/config.toml.
    c                X    j                  dt        j                  | d      z          y )N# T)boldappendr   style_for_clitextouts    r   append_descz show_config.<locals>.append_descR   s!    

4(00DAABr   c                T    j                  dt        j                  |       z          y )Nr%   r'   r*   s    r   append_commentz#show_config.<locals>.append_commentU   s    

4(00667r   c                T    j                  t        j                  | dd             y )NTgreen)r&   fgr'   r*   s    r   append_sectionz#show_config.<locals>.append_sectionX   s    

8))$TgFGr   c                R    j                  t        j                  | d             y )Nr1   r2   r'   r*   s    r   append_settingz#show_config.<locals>.append_setting[   s    

8))$7;<r   _testvisibler    [].   
N#zTHIS IS DEPRECATED.yellowr5   z(This option will be removed on or after default
   z	Default: r%   zThe value below was set in z =
)r+   strreturnNone)r(   _cleanr   section
visibility
is_expiredlenvalueskeysplit_clean_paragraphsdescription	enumeraterstripstriplstrip
deprecatedr   r)   deprecation_textexpiration_datetomldumpsdefault_valwhere_definedr	   DEFAULT_DEFINITIONr   print_to_clijoin)section_descriptionsconfig_optionsr-   r/   r3   r6   rH   kvsection_optionsoptionrM   description_paragraphslast_paragraph_idxi	paragraphlinesappend_funclinerX   toml_defaultoption_is_manually_settoml_settingr,   s                          @r   show_configro   B   sm    CJJ	
C8H= ( ]) g ',,.
1yyG#	(A!,,. qD
 
 1$

27)1~&

2%,,. H	)F**""3'+C%6v7I7I7OR%P"!$%;!<q!@ )*@ A '9!((*00
 q!1!!"IE ./!Vk " /D./ **"2&''*   r7c>"2&**+@XN r"-f.E.EF )D"4()r">v?U?U>VVWX ::y&2D2D&EFL',224L< 1$r7c>"2&<.9:  $$(G(GG # &r7d?"2&!<V=Q=Q<RST::sFLL&9:L< A%!#C5~+!#L>2<(QH	)+])~ $))C.)q
s   ;L9c                0    t        j                  dd|       S )zReplace sequences of multiple spaces with a single space, excluding newlines.

    Preserves leading and trailing spaces, and does not modify spaces in between lines.
    z + )resub)txts    r   rG   rG      s    
 66$S!!r   c           	         | j                  d      } | j                  d      }|D cg c])  }dj                  d |j                  d      D              + c}S c c}w )zHSplit the text into paragraphs, preserve newlines within the paragraphs.r?   z

c              3  2   K   | ]  }t        |        y w)N)rG   ).0rk   s     r   	<genexpr>z$_clean_paragraphs.<locals>.<genexpr>   s     A4&,As   )rS   rN   r^   )rt   
paragraphsrh   s      r   rO   rO      sY     ))D/C6"J $ 			A9??4+@AA  s   .Ac                l   t               }t        | t              r| st        d| d      t	        |       D ]  \  }}t        |t
              s*t        d| d| dt        |      j                   d|       |j                         }|st        d| d| d      t        |      rp|j                  d|||        yt        | t
              s't        d| d	t        |       j                   d|        | j                         }|st        d| d
      t        |      s|j                  d||       yy)a  Validate theme color configuration option values.

    Validates that the value is a string (or list of strings, in the case of
    chartCategoricalColors and chartSequentialColors) and is not empty.

    Handles both single color strings (like primaryColor, backgroundColor)
    and arrays of color strings (like chartCategoricalColors, chartSequentialColors).

    Parameters
    ----------
    value : Any
        The color value to validate. Can be a string or list of strings.
    option_name : str
        The name of the theme option being validated (e.g., "theme.primaryColor").

    Raises
    ------
    StreamlitInvalidThemeOptionError
        If the value is not a string/list of strings, is empty, or contains
        empty values in the case of arrays.

    Notes
    -----
    Logs warnings for potentially invalid colors, since more comprehensive
    validation happens on the frontend.
    zTheme option 'z' cannot be an empty arrayr:   z]' must be a string, got : z]' cannot be emptyz^Theme option '%s[%s]' may be an invalid color: %s. Expected formats: hex, rgb, and rgba colorsNz,' must be a string or array of strings, got z' cannot be emptyzZTheme option '%s' may be an invalid color: %s. Expected formats: hex, rgb, and rgba colors)r   
isinstancelistr   rQ   rD   typer   rS   r
   warning)r   option_nameloggerrg   color	color_str	value_strs          r   _check_color_valuer      s|   6 ]F %2 -GH  "%( 	HAueS)6$[M1#5NtTY{OcOcNddfglfmn  I6$[M1#5GH 
 %Y/B	, 	 eS!.[M)UVZ[`VaVjVjUkkmnsmtu
 	
 [[]I.[M):;
 	

 Y':		
 (r   c              #     K   | j                         D ]4  \  }}|j                  d      s|j                  %||j                  f 6 yw)z
    Iterate through theme config options, yielding (option_path, value) pairs.
    Returns: theme.primaryColor, #ff0000, ...

    Leveraged by _extract_current_theme_config() to retrieve main config.toml theme options.
    theme.Nr   )r`   r   r   s      r   _iterate_theme_config_optionsr   )  sK      ,113 *'x(W]]-FGMM))*s   (AAAc                N   i }t        |       D ]  \  }}|j                  d      }t        |      dk(  r|\  }}|dk7  s0|||<   6t        |      dk(  r|\  }}}||vri ||<   |||   |<   \t        |      dk(  sk|\  }}}}||vri ||<   |||   vri ||   |<   |||   |   |<    |S )z
    Extract current theme configuration from config options.
    Returns a dictionary with the current theme options in nested format.
    r<      base      )r   rN   rK   )	r`   current_theme_optionsr   	opt_valueparts_rd   rH   
subsections	            r   _extract_current_theme_configr   7  s     <^L K)s#u:?IAv09%f-Z1_!&Aw3313%g.5>!'*62Z1_-2*Aw
F3313%g.!6w!??=?%g.z:AJ!'*:6v>#K& ! r   c                P   t               }t               }| D ]  }|j                  d      s|j                  d      }|d   dk(  r%t        |      dk(  r|\  }}|j	                  |       S|d   dk(  s\|d   dk(  set        |      dk(  st|\  }}}|j	                  |        ||fS )	ah  Get valid theme configuration options for main theme and theme sections.

    Extracts valid theme options from the config options template to ensure they
    stay in sync with the actual theme options defined via _create_theme_options() calls.

    Parameters
    ----------
    config_options_template : dict[str, ConfigOption]
        Template of all available configuration options.

    Returns
    -------
    tuple[set[str], set[str]]
        A tuple (main_theme_options, section_theme_options) where:
        - main_theme_options: Valid theme options for the main theme (without "theme." prefix)
        - section_theme_options: Valid theme options for sections/subsections
          (sidebar, light, dark, light.sidebar, dark.sidebar)

    Notes
    -----
    All non-main theme sections have the same valid options, so we only need to
    extract them once.
    r   r<   r   themer   r>   sidebarr   )setr   rN   rK   add)config_options_templatemain_theme_optionssection_theme_options
option_keyr   r   r   s          r   _get_valid_theme_optionsr   V  s    6 E . 7
  *$$S)EQx7"s5zQ!&;"&&{3qW$qY)>3u:QR? %*!1k%))+67 444r   c                    |dk(  r| d|  }nd| d|  }dj                  d t        |      D              }t               j                  d||||       y)z=Helper function to log a warning for an invalid theme option.r   r<   r   r?   c              3  &   K   | ]	  }d |   yw)u     • N )rw   opts     r   rx   z0_invalid_theme_option_warning.<locals>.<genexpr>  s     "ScVC5>"Ss   zNTheme file %s contains invalid theme option: '%s'.

Valid '%s' options are:
%sN)r^   sortedr   r   )r   file_path_or_urlvalid_optionssection_namefull_option_namevalid_options_lists         r   _invalid_theme_option_warningr     sm     w*^1[M: $L>;-@"SVM=R"SSM	&r   c           	     l   | j                         D ]  \  }}t        |t              r;|r|dk7  rt        d| d| |      ||vri ||<   t	        || d| ||||   d       Q||vr!t        ||||       |j                  |d       v|||<   d| d| }d|j                         v st        ||        y)a  Recursively validate a theme section and its subsection/options.

    Parameters
    ----------
    section_configs : dict[str, Any]
        The section configs to validate.
    section_path : str
        Path like 'sidebar', 'light', 'light.sidebar'.
    file_path_or_url : str
        Theme file path for error messages.
    section_options : set[str]
        Valid options for this section.
    filtered_parent : dict[str, Any]
        Parent section to populate/filter out invalid options.
    allow_sidebar_subsection : bool, optional
        Allow sidebar subsection (only "light" and "dark" sections), by default False.

    Raises
    ------
    StreamlitInvalidThemeSectionError
        If an invalid subsection is found.
    r   r   r<   FNr   )	r   r|   dictr   !_validate_theme_section_recursiver   poplowerr   )	section_configssection_pathr   rc   filtered_parentallow_sidebar_subsectionr   option_valuer   s	            r   r   r     s   < &5%:%:%< $C!\lD)+{i/G7\N!K=9$  /1/1,-.+/ , /) 	 T2 ,8OK(!'~Q{mD*0022"<1ABI$Cr   c           	        t        |      \  }}h d}| j                  di       }t        j                  |       }|j                  di       }|j	                         D ]  \  }	}
t        |
t              r1|	|vrt        |	|      |	|vri ||	<   |	dv }t        |
|	||||	   |       G|	|vr t        |	||       |j                  |	d       kd|	 }d|j                         v st        |
|        |S )a  
    Validate that a theme file contains only valid theme sections and config options.

    If invalid sections are found in the theme file, a StreamlitInvalidThemeSectionError is raised.

    If invalid config options are found in the theme file, a warning is logged with the valid
    options for the given section.

    Returns
    -------
        A filtered copy of the theme content with invalid options removed.
    >   darklightr   r   >   r   r   Nr   r   )r   getcopydeepcopyr   r|   r   r   r   r   r   r   r   )theme_contentr   r   valid_main_optionsvalid_section_optionsvalid_sectionstheme_sectionfiltered_themefiltered_theme_sectionr   r   r   r   s                r   _validate_theme_file_contentr     sB   $ 1I1-- 2N!%%gr2M ]]=1N+//< &3%8%8%: (C!\lD).07$  "8868&{3 (36G'G$- %&{3(  22) " #&&{D9 "(}5*0022"<1ABQ(CT r   c                     dd}d fd}d fd}d fd}	 ddl }t        j                         }	 |rJt        j
                  j                   d      5 }|j                         j                  d	      ddd       nt        j                  j                         s2t        j                  j                  t        j                                 t        j                  j                         s |        t         d	
      5 }	|	j                         ddd       t!        j#                  d	            }
|
t$        kD  r |        j'                        }d|vr |        t)        | |      }|S # t        $ r  |        Y gw xY w# 1 sw Y   uxY w# 1 sw Y   xY w# t*        t,        t.        t0        f$ r  t        j2                  j4                  $ r}t+        d  d|       |d}~wt6        $ r}t+        d  d|       |d}~ww xY w)z
    Load and parse a theme TOML file from a local path or URL.

    Handles raising errors when a file cannot be found, read, parsed,
    or contains invalid theme options.

    Otherwise returns the parsed TOML content as a dictionary.
    c                     t        d      )Nz^The 'toml' package is required to load theme files. Please install it with 'pip install toml'.r   r   r   r   _raise_missing_tomlz-_load_theme_file.<locals>._raise_missing_toml=  s    (9
 	
r   c                      t        d        )NzTheme file not found: )FileNotFoundErrorr   s   r   _raise_file_not_foundz/_load_theme_file.<locals>._raise_file_not_foundC  s    "89I8J KLLr   c                 "    t        d  d      )NTheme file z must contain a [theme] section)r   r   s   r   _raise_missing_theme_sectionz6_load_theme_file.<locals>._raise_missing_theme_sectionF  s    /*++JK
 	
r   c            	     n    t        j                  d            } t        d d| ddt        dd      )Nutf-8r   z is too large (,z! bytes). Maximum allowed size is zT bytes (1MB). Theme files should contain only configuration options, not large data.)rK   encoder   _MAX_THEME_FILE_SIZE_BYTES)content_sizecontentr   s    r   _raise_file_too_largez/_load_theme_file.<locals>._raise_file_too_largeK  sP    7>>'23(*+?<:J K''A!&D EUV
 	
r   r   N   )timeoutr   )encodingr   z#Could not load theme file from URL r{   zError loading theme file rE   rF   )rX   ImportErrorr   is_urlurllibrequesturlopenreaddecodeospathisabsr^   getcwdexistsopenrK   r   r   loadsr   r   r   r   r   errorURLError	Exception)r   r   r   r   r   r   rX   is_valid_urlresponsefr   parsed_themer   er   s   `             @r   _load_theme_filer   1  s   
M



 ??#34L5 ''(8"'E :"--/009: :
 77==!12#%77<<		=M#N 77>>"23%'&9 #Q&&(# 7>>'2344!# zz'* ,&(* 6*,C
 U  : :# #. 	#()	  	<<   (12B1C2aSI
	  ('(8'9A3?
	sf   E3 #F"  F
8BF" FAF" 3FF
FF" FF" "6HG**H6HHc                   t        j                  |       }|j                         D ]W  \  }}||v r6t        ||   t              r#t        |t              rt        ||   |      ||<   @t        j                  |      ||<   Y |S )z
    Recursively merge two dictionaries, with override_dict values taking precedence.
    Handles arbitrary levels of nesting for theme configurations.
    )r   r   r   r|   r   _deep_merge_theme_dicts)	base_dictoverride_dictmergedrM   r   s        r   r   r     s{     ]]9%F#))+ /
U&=ZsT:z%QU?V1&+uEF3K --.F3K/ Mr   c                    t        | |      S )z
    Apply theme inheritance where theme config values from config.toml
    take precedence over the theme configs defined in theme.base toml file.

    Returns a dictionary with the merged theme configuration.
    )r   )
base_themeoverride_themes     r   _apply_theme_inheritancer     s     #:~>>r   c                    | j                         D ]D  \  }}|dk(  r|dk(  r|r| d| n|}t        |t              rt        ||||       ; ||||       F y)z
    Recursively set theme options from nested dictionary in process_theme_inheritance().
    This utility function traverses nested theme configuration sections/subsection
    and sets each option using the provided set_option_func.
    r   r   r<   N)r   r|   r   _set_theme_options_recursive)options_dictprefixset_option_funcsourcer   r   current_keys          r   r   r     sp     &2%7%7%9 ?!\& Vw%639+/{lD)(k?F
 Kv>?r   c                   | y| j                  d      }|r|j                  y|j                  dv rydfd}	 t        |      }|j                  di       j                  d      }|r|dvr |        | rt        |       ni }t	        |d|i      }i }	| | j                         D ]H  \  }
}|
j                  d      s|
dk7  s|j                  dv s-|j                  |j                  d	|	|
<   J | D 
cg c]  }
|
j                  d      r|
dk7  r|
 }}
|D ]  }
 ||
dd
        |j                  di       j                  d      }|r |d|d        n |ddd d       |j                  di       }t        |d|d        |	j                         D ]  \  }
} ||
|d   |d           yc c}
w # t        t        t        t        f$ r  t        $ r0}t               j                  d       t        d d|       |d}~ww xY w)aG  
    Process theme inheritance if theme.base points to a theme file.

    This function checks if theme.base is set to a file path or URL,
    loads the theme file, and applies inheritance logic where the
    current config.toml values override the theme.base file values.

    Sets the merged theme options to the config.
    Nz
theme.base)r   r   c                 "    t        d  d      )Nr   zy cannot reference another theme file in its base property. Only 'light' and 'dark' are allowed in referenced theme files.r   )
base_values   r   _raise_invalid_nested_basez=process_theme_inheritance.<locals>._raise_invalid_nested_base  s#    (* &M N
 	
r   r   r   r   )zenvironment variablez-command-line argument or environment variable)r   r[   zreset for theme inheritanceztheme file: r   z
 (default)r   r[   z"Error processing theme inheritancez)Failed to process theme inheritance from r{   r   )r   r   r   r   r   r   r   r[   r   r   r   r   r   r   r   	exception)r`   r   r   base_optionr  theme_file_content
theme_baser   merged_themehigh_precedence_theme_optionsr   
opt_configtheme_options_to_removetheme_file_baser   opt_datar   r  s                    @r   process_theme_inheritancer    s     $$\2K+++3""J &&
O-j:QR (++GR8<<VD
*,==&( >L).9QS 	
 0*? @

 )+%%(6(<(<(> $*''1 L0"00 ",!1!1)3)A)A?1(;$ !/'&&x0X5M '# '
 4 O$0MNO -00"=AA&IL/\*;VW gj\'L
 %(("5$7O|J<5P	

 #@"E"E"G 	THhHhw&7/9RS	T3': 	#()	  	  DE(7
|2aSI
	s=   BF9  F9 F9 "F9 7F4BF9 4F9 9"H+HH)rE   r   )r   dict[str, ConfigOption]r   r  rE   bool)r_   zdict[str, str]r`   r  rE   rF   )rt   rD   rE   rD   )rt   rD   rE   z	list[str])r   r   r   rD   rE   rF   )r`   r  rE   zIterator[tuple[str, Any]])r`   r  rE   dict[str, Any])r   r  rE   ztuple[set[str], set[str]])r   )
r   rD   r   rD   r   set[str]r   rD   rE   rF   )F)r   r  r   rD   r   rD   rc   r  r   r  r   r  rE   rF   )r   r  r   rD   r   r  rE   r  )r   rD   r   r  rE   r  )r   r  r   r  rE   r  )r   r  r   r  rE   r  )
r   r  r   rD   r   r   r   rD   rE   rF   )r`   zdict[str, ConfigOption] | Noner   r  r   r   rE   rF   )*
__future__r   r   r   rr   urllib.errorr   urllib.requesttypingr   r   collections.abcr   	streamlitr   r   streamlit.config_optionr	   !streamlit.elements.lib.color_utilr
   streamlit.errorsr   r   r   r   r   r"   ro   rG   rO   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   <module>r     sP   #  	 	   %( ( 0 ?  )  (7N	${*({*+{* 
{*|"P
f*+**!+!!>-54-5-5h  	  	
 
@ &+BC#BCBC BC 	BC
 $BC #BC 
BCJI!II 5I 	IX__4K__D.<(	?	?0>	?	?? ?*-?@C?MP?	?8q2q4q q 
	qr   