L ixddlmZddlZddlZddlZddlZddlZddlm Z m Z e rddl m Z ddl mZmZddlmZddlmZddlmZmZmZd Zdd Z dd Z dd Zdd ZddZd dZ d!dZ d"dZ d#dZ! d$ d%dZ" d& d'dZ# d(dZ$ d)dZ% d*dZ& d+dZ' d,dZ( d-dZ)y).) annotationsN) TYPE_CHECKINGAny)Iterator)cli_utilurl_util) ConfigOption)is_css_color_like)StreamlitInvalidThemeError StreamlitInvalidThemeOptionError!StreamlitInvalidThemeSectionErroric&ddlm}|tS)zHGet logger for this module. Separate function to avoid circular imports.r get_logger)streamlit.loggerr__name__rs [/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/config_util.py _get_loggerr)s+ h c|jD]9\}}|jds|j}||j}||k7s9yy)zpReturn True if and only if an option in the server section differs between old_options and new_options. serverTFitems startswithvalue) old_options new_optionsopt_nameopt_valold_valnew_vals rserver_option_changedr"0s[ )..0'""8, --h'-- g  rc~gjtddfd }dfd }dfd }dfd }|D]}|dk(r |jDcic]6\}}|j|k(r"|jdk(r|j s||8} }}t | dk(rjjd |d |d jd | jD]-} | jjd d } t| jxsd } t | dz } t| D]r\}}|jjd}|r|djs|dd}|dk(r|n|}|D]}||j|| k7sk|d t| j rud dk7r|d |t#j$dd|d t| j&D] }|| |d |d| j(d ddl}|j-d| j.i}|ddj}t |dkDrd dk7r|d |d|n | j0t2j4k7}|r%d dk7r|d |d| j0|j-| | j6i}t |dk(rd| d}n|sd|}||0t#j8dj;ycc}}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. cXjdtj|dzy)N# T)boldappendr style_for_clitextouts r append_descz show_config..append_descRs! 4(00DAABrcTjdtj|zy)Nr%r'r*s rappend_commentz#show_config..append_commentUs 4(00667rcTjtj|ddy)NTgreen)r&fgr'r*s rappend_sectionz#show_config..append_sectionXs 8))$TgFGrcRjtj|dy)Nr1r2r'r*s rappend_settingz#show_config..append_setting[s 8))$7;"2&**+@XNr"-f.E.EF)D"4()r">v?U?U>VVWX ::y&2D2D&EFL',224L< 1$r7c>"2&<.9:$$ (G(GG #&r7d?"2&!2 < (QH )+])~ $))C.)q s;L9c0tjdd|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 + )resub)txts rrGrGs 66$S !!rc |jd}|jd}|Dcgc])}djd|jdD+c}Scc}w)zHSplit the text into paragraphs, preserve newlines within the paragraphs.r?z c32K|]}t|yw)N)rG).0rks r z$_clean_paragraphs..sA4&,As)rSrNr^)rt paragraphsrhs rrOrOsY ))D/C6"J$   A9??4+@AA  s.Ac lt}t|tr|std|dt |D]\}}t|t s*td|d|dt |jd||j}|std|d|dt|rp|jd|||yt|t s'td|d t |jd||j}|std|d t|s|jd ||yy) aValidate 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. zTheme 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 isinstancelistr rQrDtyperrSr warning)r option_nameloggerrgcolor color_str value_strs r_check_color_valuers|6]F%2  -GH "%( HAueS)6$[M1#5NtTY{OcOcNddfglfmn I6$[M1#5GH %Y/B  ,  eS !.[M)UVZ[`VaVjVjUkkmnsmt u  [[]I .[M): ;  Y ' :     (rc#K|jD]4\}}|jds|j%||jf6yw)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`rrs r_iterate_theme_config_optionsr)sK,113*'   x (W]]-FGMM) )*s(A  A A cNi}t|D]\}}|jd}t|dk(r|\}}|dk7s0|||<6t|dk(r|\}}}||vri||<||||<\t|dk(sk|\}}}}||vri||<|||vri|||<|||||<|S)z Extract current theme configuration from config options. Returns a dictionary with the current theme options in nested format. r<base)rrNrK) r`current_theme_optionsr opt_valueparts_rdrH subsections r_extract_current_theme_configr7s<^LK)s# u:?IAv09%f- Z1_!& Aw3313%g.5> !' *6 2 Z1_-2 *Aw F3313%g.!6w!??=?%g.z:AJ !' *: 6v >#K& ! rcPt}t}|D]}|jds|jd}|ddk(r%t|dk(r|\}}|j |S|ddk(s\|ddk(set|dk(st|\}}}|j |||fS) ahGet 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. rr<rthemerr>sidebarr)setrrNrKadd)config_options_templatemain_theme_optionssection_theme_options option_keyrrrs r_get_valid_theme_optionsrVs6E. 7   *$$S)EQx7"s5zQ!&;"&&{3qW$qY)>3u:QR?%*!1k%))+6 7 4 44rc|dk(r|d|}nd|d|}djdt|D}tjd||||y)z=Helper function to log a warning for an invalid theme option.rr<rr?c3&K|] }d| yw)u • N)rwopts rrxz0_invalid_theme_option_warning..s"ScVC5>"SszNTheme file %s contains invalid theme option: '%s'. Valid '%s' options are: %sN)r^sortedrr)rfile_path_or_url valid_options section_namefull_option_namevalid_options_lists r_invalid_theme_option_warningrsmw*^1[M:$L>;-@"SVM=R"SSM & rc l|jD]\}}t|tr;|r|dk7rtd|d||||vri||<t ||d|||||dQ||vr!t |||||j |dv|||<d|d|}d|jvst||y)aRecursively 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. rrr<FNr) rr|dictr !_validate_theme_section_recursiverpoplowerr) section_configs section_pathrrcfiltered_parentallow_sidebar_subsectionr option_valuers rrrs<&5%:%:%<$C! \ lD )+{i/G7\N!K=9$ /1/1 , -.+/  ,   / )       T 2,8OK (!' ~Q{mD *0022"<1ABI$Crc t|\}}hd}|jdi}tj|}|jdi}|j D]\} } t | t r1| |vr t| || |vri|| <| dv} t| | |||| | G| |vr t| |||j| dkd| } d| jvst| | |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. >darklightrr>rrNrr) rgetcopydeepcopyrr|rr rrrrr) theme_contentrrvalid_main_optionsvalid_section_optionsvalid_sections theme_sectionfiltered_themefiltered_theme_sectionrrrrs r_validate_theme_file_contentrsB$1I1--2N!%%gr2M]]=1N+//<&3%8%8%:(C! \ lD ).07$ "8868&{3(36G'G $ - %&{3(   2 2 ) "  # & &{D 9"( }5 *0022"<1ABQ(CT rc dd}dfd }dfd }dfd } ddl}tj} |rJtj j d5}|jjd dddntjjs2tjjtjtjjs|td 5} | jdddt!j#d } | t$kDr|j'} d | vr|t)| |} | S#t$r |YgwxYw#1swYuxYw#1swYxYw#t*t,t.t0f$rtj2j4$r} t+d d | | d} ~ wt6$r} t+dd | | d} ~ wwxYw)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. ctd)Nz^The 'toml' package is required to load theme files. Please install it with 'pip install toml'.r rrr_raise_missing_tomlz-_load_theme_file.._raise_missing_toml=s( 9  rc td)NzTheme file not found: )FileNotFoundErrorrsr_raise_file_not_foundz/_load_theme_file.._raise_file_not_foundCs"89I8J KLLrc"tdd)N Theme file z must contain a [theme] section)r rsr_raise_missing_theme_sectionz6_load_theme_file.._raise_missing_theme_sectionFs/*++J K  rc ntjd}tdd|ddtdd)Nutf-8rz is too large (,z! bytes). Maximum allowed size is zT bytes (1MB). Theme files should contain only configuration options, not large data.)rKencoder _MAX_THEME_FILE_SIZE_BYTES) content_sizecontentrs r_raise_file_too_largez/_load_theme_file.._raise_file_too_largeKsP7>>'23 (*+?<:JK''A!&DEU V  rrN)timeoutr)encodingrz#Could not load theme file from URL r{zError loading theme file rErF)rX ImportErrorris_urlurllibrequesturlopenreaddecodeospathisabsr^getcwdexistsopenrKrrloadsrr r r rerrorURLError Exception)rrrrrrrX is_valid_urlresponsefr parsed_themerers` @r_load_theme_filer1s M   ??#34L5 ''(8"'E :"--/009 : : 77==!12#%77<< =M#N 77>>"23%'&9 #Q&&( #7>>'23 4 4 ! #zz'*  , & ( *6 *,C U  : : # #. #()    << (12B1C2aS I   ('(8'9A3 ?  sfE3#F" F 8B F"FAF"3FF FF"FF""6H G** H 6HH ctj|}|jD]W\}}||vr6t||tr#t|trt |||||<@tj|||<Y|S)z Recursively merge two dictionaries, with override_dict values taking precedence. Handles arbitrary levels of nesting for theme configurations. )rrrr|r_deep_merge_theme_dicts) base_dict override_dictmergedrMrs rrrs{]]9 %F#))+/ U &=Zs T:z%QU?V1&+uEF3K--.F3K / Mrct||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_themeoverride_themes r_apply_theme_inheritancers #:~ >>rc|jD]D\}}|dk(r|dk(r|r|d|n|}t|trt||||;||||Fy)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. rrr<N)rr|r_set_theme_options_recursive) options_dictprefixset_option_funcsourcerr current_keys rrrsp&2%7%7%9?! \ & Vw%6 39+/{ lD ) (k?F  Kv >?rc|y|jd}|r |jy|jdvrydfd } t|}|jdijd}|r |dvr||r t|ni}t |d|i}i} ||j D]H\} } | j ds| dk7s| jdvs-| j| jd | | <J|D cgc]} | j dr| dk7r| } } | D] } || dd |jdijd} | r|d| d n|dd d d |jdi}t|d|d | j D]\} }|| |d|dycc} w#ttttf$rt$r0}tjdtdd||d}~wwxYw)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)rrc"tdd)Nrzy cannot reference another theme file in its base property. Only 'light' and 'dark' are allowed in referenced theme files.r) base_valuesr_raise_invalid_nested_basez=process_theme_inheritance.._raise_invalid_nested_bases#(*&M N  rrrr)zenvironment variablez-command-line argument or environment variable)rr[zreset for theme inheritancez theme file: rz (default)rr[z"Error processing theme inheritancez)Failed to process theme inheritance from r{r)rrrrrrrr[rr r r rrr exception)r`rr base_optionrtheme_file_content theme_baser merged_themehigh_precedence_theme_optionsr opt_configtheme_options_to_removetheme_file_baseropt_datarrs @rprocess_theme_inheritancer s $$\2K +++3""J&& O-j:QR(++GR8<L ). 9QS  0 *? @ )+%  %(6(<(<(> $*''1 L0"00",!1!1)3)A)A?1(; $!/'&&x0X5M' #' 4 O$0MN O-00"=AA&I  L/\*;V W gj\'L  %(("5 $ 7O|J<5P #@"E"E"G T Hh Hhw&7/9R S T3': #()      DE(7 |2aS I  s=BF9F9F9"F97F4BF94F99"H +HH )rEr)rdict[str, ConfigOption]rrrEbool)r_zdict[str, str]r`rrErF)rtrDrErD)rtrDrEz list[str])rrrrDrErF)r`rrEzIterator[tuple[str, Any]])r`rrEdict[str, Any])rrrEztuple[set[str], set[str]])r) rrDrrDrset[str]rrDrErF)F)rrrrDrrDrcrrrrrrErF)rrrrDrrrEr)rrDrrrEr)rrrrrEr)rrrrrEr) rrrrDrrrrDrErF)r`zdict[str, ConfigOption] | NonerrrrrErF)* __future__rrrrr urllib.errorrurllib.requesttypingrrcollections.abcr streamlitrrstreamlit.config_optionr !streamlit.elements.lib.color_utilr streamlit.errorsr r r rrr"rorGrOrrrrrrrrrrrr rrrrsP# %((0?) (7N ${*({*+{* {*|"P f *+ * *!+!!>-54-5-5h    @&+ BC#BCBCBC BC $ BC # BC BCJI!II5I IX__4K__D.<( ? ?0> ? ?? ?*-?@C?MP? ?8q2q4qq qr